From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH][gdb/exp] Fix assert when adding ptr to imaginary unit
Date: Thu, 28 Jan 2021 14:06:56 +0100 [thread overview]
Message-ID: <20210128130655.GA8529@delia> (raw)
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 <tdevries@suse.de>
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 <tdevries@suse.de>
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)
next reply other threads:[~2021-01-28 13:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-28 13:06 Tom de Vries [this message]
2021-01-28 14:08 ` Tom Tromey
2021-01-29 7:04 ` Tom de Vries
2021-01-29 7:10 ` Tom de Vries
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=20210128130655.GA8529@delia \
--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