Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH][gdb/exp] Fix assert when adding ptr to imaginary unit
Date: Fri, 29 Jan 2021 08:10:02 +0100	[thread overview]
Message-ID: <cc227b95-2567-e2b0-e434-f2ae0398f023@suse.de> (raw)
In-Reply-To: <396c65a8-3054-44ab-db5c-bbef7d698b66@suse.de>

[-- Attachment #1: Type: text/plain, Size: 1878 bytes --]

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 <tdevries@suse.de> writes:
>>
>> Tom> 2021-01-28  Tom de Vries  <tdevries@suse.de>
>>
>> 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

[-- Attachment #2: 0005-gdb-exp-Enable-complex-decimal-float.patch --]
[-- Type: text/x-patch, Size: 2096 bytes --]

[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);
 }
 

  reply	other threads:[~2021-01-29  7:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-28 13:06 Tom de Vries
2021-01-28 14:08 ` Tom Tromey
2021-01-29  7:04   ` Tom de Vries
2021-01-29  7:10     ` Tom de Vries [this message]
2021-02-05 10:05       ` Tom de Vries
2021-02-05  9:57     ` Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cc227b95-2567-e2b0-e434-f2ae0398f023@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox