public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][PR gdb/24789] Allow pointer arithmetic with integer references
       [not found] <20200331133547.547-1-ssbssa.ref@yahoo.de>
@ 2020-03-31 13:35 ` Hannes Domani
  2020-03-31 20:15   ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Hannes Domani @ 2020-03-31 13:35 UTC (permalink / raw)
  To: gdb-patches

Considering these variables:
int i = 3;
int &iref = i;

It's not possible to do any pointer arithmetic with iref:
(gdb) p &i+iref
Argument to arithmetic operation not a number or boolean.

So this adds checks for references to integers in pointer arithmetic.

gdb/ChangeLog:

2020-03-31  Hannes Domani  <ssbssa@yahoo.de>

	PR gdb/24789
	* eval.c (evaluate_subexp_standard): Allow integer references
	in pointer arithmetic.
---
 gdb/eval.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/gdb/eval.c b/gdb/eval.c
index 17af1b51df..aa629b7d02 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -2210,9 +2210,17 @@ evaluate_subexp_standard (struct type *expect_type,
       else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
 	       && is_integral_type (value_type (arg2)))
 	return value_ptradd (arg1, value_as_long (arg2));
+      else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
+	       && TYPE_IS_REFERENCE (type = check_typedef (value_type (arg2)))
+	       && is_integral_type (TYPE_TARGET_TYPE (type)))
+	return value_ptradd (arg1, value_as_long (arg2));
       else if (ptrmath_type_p (exp->language_defn, value_type (arg2))
 	       && is_integral_type (value_type (arg1)))
 	return value_ptradd (arg2, value_as_long (arg1));
+      else if (ptrmath_type_p (exp->language_defn, value_type (arg2))
+	       && TYPE_IS_REFERENCE (type = check_typedef (value_type (arg1)))
+	       && is_integral_type (TYPE_TARGET_TYPE (type)))
+	return value_ptradd (arg2, value_as_long (arg1));
       else
 	{
 	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
@@ -2236,6 +2244,10 @@ evaluate_subexp_standard (struct type *expect_type,
       else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
 	       && is_integral_type (value_type (arg2)))
 	return value_ptradd (arg1, - value_as_long (arg2));
+      else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
+	       && TYPE_IS_REFERENCE (type = check_typedef (value_type (arg2)))
+	       && is_integral_type (TYPE_TARGET_TYPE (type)))
+	return value_ptradd (arg1, - value_as_long (arg2));
       else
 	{
 	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
-- 
2.26.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH][PR gdb/24789] Allow pointer arithmetic with integer references
  2020-03-31 13:35 ` [PATCH][PR gdb/24789] Allow pointer arithmetic with integer references Hannes Domani
@ 2020-03-31 20:15   ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2020-03-31 20:15 UTC (permalink / raw)
  To: Hannes Domani via Gdb-patches

>>>>> "Hannes" == Hannes Domani via Gdb-patches <gdb-patches@sourceware.org> writes:

Thanks for the patch.

Hannes> So this adds checks for references to integers in pointer arithmetic.

This should have a test case.  It's fine to add it to some appropriate
pre-existing C++ test case.

Hannes> +	       && TYPE_IS_REFERENCE (type = check_typedef (value_type (arg2)))

Generally gdb doesn't use assignment in expressions; and in this case it
seems particularly bad to me.

Tom

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-31 20:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200331133547.547-1-ssbssa.ref@yahoo.de>
2020-03-31 13:35 ` [PATCH][PR gdb/24789] Allow pointer arithmetic with integer references Hannes Domani
2020-03-31 20:15   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).