Allow pointer arithmetic with integer references
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-04-01 Hannes Domani <ssbssa@yahoo.de> PR gdb/24789 * eval.c (is_integral_or_integral_reference): New function. (evaluate_subexp_standard): Allow integer references in pointer arithmetic. gdb/testsuite/ChangeLog: 2020-04-01 Hannes Domani <ssbssa@yahoo.de> PR gdb/24789 * gdb.cp/misc.cc: Add integer reference variable. * gdb.cp/misc.exp: Add test.
This commit is contained in:
parent
77bf7b5317
commit
60e22c1eac
@ -1,3 +1,10 @@
|
|||||||
|
2020-04-01 Hannes Domani <ssbssa@yahoo.de>
|
||||||
|
|
||||||
|
PR gdb/24789
|
||||||
|
* eval.c (is_integral_or_integral_reference): New function.
|
||||||
|
(evaluate_subexp_standard): Allow integer references in
|
||||||
|
pointer arithmetic.
|
||||||
|
|
||||||
2020-04-01 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
|
2020-04-01 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
|
||||||
|
|
||||||
* remote.c (remote_target::remote_parse_stop_reply): Remove the
|
* remote.c (remote_target::remote_parse_stop_reply): Remove the
|
||||||
|
20
gdb/eval.c
20
gdb/eval.c
@ -1248,6 +1248,20 @@ skip_undetermined_arglist (int nargs, struct expression *exp, int *pos,
|
|||||||
evaluate_subexp (NULL_TYPE, exp, pos, noside);
|
evaluate_subexp (NULL_TYPE, exp, pos, noside);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return true if type is integral or reference to integral */
|
||||||
|
|
||||||
|
static bool
|
||||||
|
is_integral_or_integral_reference (struct type *type)
|
||||||
|
{
|
||||||
|
if (is_integral_type (type))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
type = check_typedef (type);
|
||||||
|
return (type != nullptr
|
||||||
|
&& TYPE_IS_REFERENCE (type)
|
||||||
|
&& is_integral_type (TYPE_TARGET_TYPE (type)));
|
||||||
|
}
|
||||||
|
|
||||||
struct value *
|
struct value *
|
||||||
evaluate_subexp_standard (struct type *expect_type,
|
evaluate_subexp_standard (struct type *expect_type,
|
||||||
struct expression *exp, int *pos,
|
struct expression *exp, int *pos,
|
||||||
@ -2208,10 +2222,10 @@ evaluate_subexp_standard (struct type *expect_type,
|
|||||||
if (binop_user_defined_p (op, arg1, arg2))
|
if (binop_user_defined_p (op, arg1, arg2))
|
||||||
return value_x_binop (arg1, arg2, op, OP_NULL, noside);
|
return value_x_binop (arg1, arg2, op, OP_NULL, noside);
|
||||||
else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
|
else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
|
||||||
&& is_integral_type (value_type (arg2)))
|
&& is_integral_or_integral_reference (value_type (arg2)))
|
||||||
return value_ptradd (arg1, value_as_long (arg2));
|
return value_ptradd (arg1, value_as_long (arg2));
|
||||||
else if (ptrmath_type_p (exp->language_defn, value_type (arg2))
|
else if (ptrmath_type_p (exp->language_defn, value_type (arg2))
|
||||||
&& is_integral_type (value_type (arg1)))
|
&& is_integral_or_integral_reference (value_type (arg1)))
|
||||||
return value_ptradd (arg2, value_as_long (arg1));
|
return value_ptradd (arg2, value_as_long (arg1));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2234,7 +2248,7 @@ evaluate_subexp_standard (struct type *expect_type,
|
|||||||
return value_from_longest (type, value_ptrdiff (arg1, arg2));
|
return value_from_longest (type, value_ptrdiff (arg1, arg2));
|
||||||
}
|
}
|
||||||
else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
|
else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
|
||||||
&& is_integral_type (value_type (arg2)))
|
&& is_integral_or_integral_reference (value_type (arg2)))
|
||||||
return value_ptradd (arg1, - value_as_long (arg2));
|
return value_ptradd (arg1, - value_as_long (arg2));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
2020-04-01 Hannes Domani <ssbssa@yahoo.de>
|
||||||
|
|
||||||
|
PR gdb/24789
|
||||||
|
* gdb.cp/misc.cc: Add integer reference variable.
|
||||||
|
* gdb.cp/misc.exp: Add test.
|
||||||
|
|
||||||
2020-04-01 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
|
2020-04-01 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
|
||||||
|
|
||||||
* gdb.server/stop-reply-no-thread.exp: Enhance the test
|
* gdb.server/stop-reply-no-thread.exp: Enhance the test
|
||||||
|
@ -24,6 +24,9 @@ bool v_bool_array[2];
|
|||||||
typedef struct fleep fleep;
|
typedef struct fleep fleep;
|
||||||
struct fleep { int a; } s;
|
struct fleep { int a; } s;
|
||||||
|
|
||||||
|
int number;
|
||||||
|
int &number_ref = number;
|
||||||
|
|
||||||
// ====================== simple class structures =======================
|
// ====================== simple class structures =======================
|
||||||
|
|
||||||
struct default_public_struct {
|
struct default_public_struct {
|
||||||
|
@ -110,3 +110,11 @@ gdb_test "print (int)false" "\\$\[0-9\]* = 0" "(int)false"
|
|||||||
|
|
||||||
gdb_test "print 'misc.cc'::v_bool" " = true" \
|
gdb_test "print 'misc.cc'::v_bool" " = true" \
|
||||||
"expression using block qualifier"
|
"expression using block qualifier"
|
||||||
|
|
||||||
|
# pointer arithmetic
|
||||||
|
gdb_test "print *(v_bool_array + number_ref)" "\\$\[0-9\]* = false" \
|
||||||
|
"pointer addition with integer reference"
|
||||||
|
gdb_test "print *(number_ref + v_bool_array)" "\\$\[0-9\]* = false" \
|
||||||
|
"pointer addition with integer reference"
|
||||||
|
gdb_test "print *(v_bool_array - number_ref)" "\\$\[0-9\]* = false" \
|
||||||
|
"pointer subtraction with integer reference"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user