From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id DQetEtC0E2AhFgAAWB0awg (envelope-from ) for ; Fri, 29 Jan 2021 02:10:08 -0500 Received: by simark.ca (Postfix, from userid 112) id 3CEDB1EF80; Fri, 29 Jan 2021 02:10:08 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=MAILING_LIST_MULTI,RDNS_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [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 D87441E945 for ; Fri, 29 Jan 2021 02:10:07 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5471A38930F3; Fri, 29 Jan 2021 07:10:07 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 514B6386F80B for ; Fri, 29 Jan 2021 07:10:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 514B6386F80B 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 65328AE55; Fri, 29 Jan 2021 07:10:03 +0000 (UTC) Subject: Re: [PATCH][gdb/exp] Fix assert when adding ptr to imaginary unit From: Tom de Vries To: Tom Tromey References: <20210128130655.GA8529@delia> <87im7hduh9.fsf@tromey.com> <396c65a8-3054-44ab-db5c-bbef7d698b66@suse.de> Message-ID: Date: Fri, 29 Jan 2021 08:10:02 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <396c65a8-3054-44ab-db5c-bbef7d698b66@suse.de> Content-Type: multipart/mixed; boundary="------------6A081A429CF0B6A977DF0942" Content-Language: en-US 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: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" This is a multi-part message in MIME format. --------------6A081A429CF0B6A977DF0942 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 1/29/21 8:04 AM, Tom de Vries wrote: > On 1/28/21 3:08 PM, Tom Tromey wrote: >>>>>>> "Tom" == Tom de Vries writes: >> >> Tom> 2021-01-28 Tom de Vries >> >> Tom> PR exp/27265 >> Tom> * valarith.c (scalar_binop): Don't call complex_binop unless >> Tom> arguments are either complex or can be casted to complex. >> >> Thanks for doing this. >> >> Tom> + if ((type1->code () == TYPE_CODE_COMPLEX >> Tom> + && (type2->code () == TYPE_CODE_COMPLEX >> Tom> + || type2->code () == TYPE_CODE_INT >> Tom> + || type2->code () == TYPE_CODE_FLT)) >> Tom> + || ((type2->code () == TYPE_CODE_COMPLEX >> Tom> + && (type1->code () == TYPE_CODE_COMPLEX >> Tom> + || type1->code () == TYPE_CODE_INT >> Tom> + || type1->code () == TYPE_CODE_FLT)))) >> Tom> return complex_binop (arg1, arg2, op); >> >> Maybe it should use is_floating_type || is_integral_type instead? >> is_scalar_type sounds like it should be right but does something really >> different instead. That function looks suspect to me. >> >> This approach would still rule out fixed point. I'm not sure if that's >> ok to do though. >> >> Also weirdly, is_fixed_point_type looks through TYPE_CODE_RANGE (seems >> reasonable) but is_integral_type does not (seems wrong). >> > > I managed to create an example using TYPE_CODE_BOOL that used to work > but was broken by this patch, added it to the tests in the patch. > > I've now gone a different route: instead of trying to narrow down when > complex_binop can be called, detect the error situation in complex_bin > and throw an error. > > That avoids speculation about what type is left after promotion. > Instead, we just check the type after promotion. > > WDYT? And FWIW, this WIP follow-up patch enables decimal float complex well enough to do "print (_Decimal32)0 + 5i". Thanks, - Tom --------------6A081A429CF0B6A977DF0942 Content-Type: text/x-patch; charset=UTF-8; name="0005-gdb-exp-Enable-complex-decimal-float.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0005-gdb-exp-Enable-complex-decimal-float.patch" [gdb/exp] Enable complex decimal float --- gdb/gdbtypes.c | 2 +- gdb/testsuite/gdb.base/complex-parts.exp | 3 ++- gdb/valprint.c | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index c736dff2ca8..b618016d427 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -3419,7 +3419,7 @@ bool can_create_complex_type (struct type *target_type) { return (target_type->code () == TYPE_CODE_INT - || target_type->code () == TYPE_CODE_FLT); + || is_floating_type (target_type)); } /* Allocate a TYPE_CODE_COMPLEX type structure. NAME is the type diff --git a/gdb/testsuite/gdb.base/complex-parts.exp b/gdb/testsuite/gdb.base/complex-parts.exp index 6385752a2f0..188fbfeab80 100644 --- a/gdb/testsuite/gdb.base/complex-parts.exp +++ b/gdb/testsuite/gdb.base/complex-parts.exp @@ -106,7 +106,8 @@ gdb_test "print (_Complex int) (23.75 + 8.88i)" " = 23 \\+ 8i" set re_reject_arg "Argument to complex arithmetic operation not supported\\." gdb_test "print (void *)0 + 5i" $re_reject_arg -gdb_test "print (_Decimal32)0 + 5i" $re_reject_arg + +gdb_test "print (_Decimal32)0 + 5i" "= 0 \\+ 5.000000i" # Set language to c++. Avoid warning by not having current frame. clean_restart diff --git a/gdb/valprint.c b/gdb/valprint.c index 340a329f9d0..36d66058ee7 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -830,11 +830,11 @@ generic_value_print_complex (struct value *val, struct ui_file *stream, fprintf_filtered (stream, "%s", decorations->complex_prefix); struct value *real_part = value_real_part (val); - value_print_scalar_formatted (real_part, options, 0, stream); + generic_value_print (real_part, stream, 0, options, decorations); fprintf_filtered (stream, "%s", decorations->complex_infix); struct value *imag_part = value_imaginary_part (val); - value_print_scalar_formatted (imag_part, options, 0, stream); + generic_value_print (imag_part, stream, 0, options, decorations); fprintf_filtered (stream, "%s", decorations->complex_suffix); } --------------6A081A429CF0B6A977DF0942--