From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id brUALfa2EmD/bwAAWB0awg (envelope-from ) for ; Thu, 28 Jan 2021 08:07:02 -0500 Received: by simark.ca (Postfix, from userid 112) id A91501EF80; Thu, 28 Jan 2021 08:07:02 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id D60441E939 for ; Thu, 28 Jan 2021 08:07:01 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4EE9C384402F; Thu, 28 Jan 2021 13:07:01 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 04E37384402F for ; Thu, 28 Jan 2021 13:06:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 04E37384402F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 258BFAE6D; Thu, 28 Jan 2021 13:06:58 +0000 (UTC) Date: Thu, 28 Jan 2021 14:06:56 +0100 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH][gdb/exp] Fix assert when adding ptr to imaginary unit Message-ID: <20210128130655.GA8529@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Tromey Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Hi, I'm running into this assertion failure: ... $ gdb -batch -ex "p (void *)0 - 5i" gdbtypes.c:3430: internal-error: \ type* init_complex_type(const char*, type*): Assertion \ `target_type->code () == TYPE_CODE_INT \ || target_type->code () == TYPE_CODE_FLT' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. ... This is a regression since commit c34e8714662 "Implement complex arithmetic". Before that commit we had: ... (gdb) p (void *)0 - 5i Argument to arithmetic operation not a number or boolean. ... Fix this in scalar_binop by further restricting what operands we allow to complex_binop. Tested on x86_64-linux. Any comments? Thanks, - Tom [gdb/exp] Fix assert when adding ptr to imaginary unit gdb/ChangeLog: 2021-01-28 Tom de Vries PR exp/27265 * valarith.c (scalar_binop): Don't call complex_binop unless arguments are either complex or can be casted to complex. gdb/testsuite/ChangeLog: 2021-01-28 Tom de Vries PR exp/27265 * gdb.base/complex-parts.exp: Add tests. --- gdb/testsuite/gdb.base/complex-parts.exp | 4 ++++ gdb/valarith.c | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/gdb.base/complex-parts.exp b/gdb/testsuite/gdb.base/complex-parts.exp index 3677c05aa1d..db193934214 100644 --- a/gdb/testsuite/gdb.base/complex-parts.exp +++ b/gdb/testsuite/gdb.base/complex-parts.exp @@ -103,3 +103,7 @@ gdb_test "print (_Complex int) 4" " = 4 \\+ 0i" gdb_test "print (_Complex float) 4.5" " = 4.5 \\+ 0i" gdb_test "ptype __complex__ short" " = _Complex short" gdb_test "print (_Complex int) (23.75 + 8.88i)" " = 23 \\+ 8i" + +set re_reject_arg "Argument to arithmetic operation not a number or boolean\\." +gdb_test "print (void *)0 + 5i" $re_reject_arg +gdb_test "print (_Decimal32)0 + 5i" $re_reject_arg diff --git a/gdb/valarith.c b/gdb/valarith.c index 81d48aae82a..9e9e4db1cd5 100644 --- a/gdb/valarith.c +++ b/gdb/valarith.c @@ -1171,8 +1171,14 @@ scalar_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) type1 = check_typedef (value_type (arg1)); type2 = check_typedef (value_type (arg2)); - if (type1->code () == TYPE_CODE_COMPLEX - || type2->code () == TYPE_CODE_COMPLEX) + if ((type1->code () == TYPE_CODE_COMPLEX + && (type2->code () == TYPE_CODE_COMPLEX + || type2->code () == TYPE_CODE_INT + || type2->code () == TYPE_CODE_FLT)) + || ((type2->code () == TYPE_CODE_COMPLEX + && (type1->code () == TYPE_CODE_COMPLEX + || type1->code () == TYPE_CODE_INT + || type1->code () == TYPE_CODE_FLT)))) return complex_binop (arg1, arg2, op); if ((!is_floating_value (arg1)