* [PATCH] Remove some dead code from evaluate_subexp_standard
@ 2020-11-28 22:43 Tom Tromey
2020-11-29 19:55 ` Andrew Burgess
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2020-11-28 22:43 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
I noticed that in the OP_ARRAY case in evaluate_subexp_standard,
"index_pc" is read but never set. This dead code then guards the only
call to init_array_element, so this can be removed as well.
gdb/ChangeLog
2020-11-28 Tom Tromey <tom@tromey.com>
* eval.c (init_array_element): Remove.
(evaluate_subexp_standard) <OP_ARRAY>: Remove "index_pc".
---
gdb/ChangeLog | 5 ++++
gdb/eval.c | 64 ++++++---------------------------------------------
2 files changed, 12 insertions(+), 57 deletions(-)
diff --git a/gdb/eval.c b/gdb/eval.c
index 407d4b4ac59..d02813eec52 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -57,10 +57,6 @@ static struct value *evaluate_struct_tuple (struct value *,
struct expression *, int *,
enum noside, int);
-static LONGEST init_array_element (struct value *, struct value *,
- struct expression *, int *, enum noside,
- LONGEST, LONGEST);
-
struct value *
evaluate_subexp (struct type *expect_type, struct expression *exp,
int *pos, enum noside noside)
@@ -337,39 +333,6 @@ evaluate_struct_tuple (struct value *struct_val,
return struct_val;
}
-/* Recursive helper function for setting elements of array tuples.
- The target is ARRAY (which has bounds LOW_BOUND to HIGH_BOUND); the
- element value is ELEMENT; EXP, POS and NOSIDE are as usual.
- Evaluates index expressions and sets the specified element(s) of
- ARRAY to ELEMENT. Returns last index value. */
-
-static LONGEST
-init_array_element (struct value *array, struct value *element,
- struct expression *exp, int *pos,
- enum noside noside, LONGEST low_bound, LONGEST high_bound)
-{
- LONGEST index;
- int element_size = TYPE_LENGTH (value_type (element));
-
- if (exp->elts[*pos].opcode == BINOP_COMMA)
- {
- (*pos)++;
- init_array_element (array, element, exp, pos, noside,
- low_bound, high_bound);
- return init_array_element (array, element,
- exp, pos, noside, low_bound, high_bound);
- }
- else
- {
- index = value_as_long (evaluate_subexp (nullptr, exp, pos, noside));
- if (index < low_bound || index > high_bound)
- error (_("tuple index out of range"));
- memcpy (value_contents_raw (array) + (index - low_bound) * element_size,
- value_contents (element), element_size);
- }
- return index;
-}
-
/* Promote value ARG1 as appropriate before performing a unary operation
on this argument.
If the result is not appropriate for any particular language then it
@@ -1433,30 +1396,17 @@ evaluate_subexp_standard (struct type *expect_type,
for (tem = nargs; --nargs >= 0;)
{
struct value *element;
- int index_pc = 0;
element = evaluate_subexp (element_type, exp, pos, noside);
if (value_type (element) != element_type)
element = value_cast (element_type, element);
- if (index_pc)
- {
- int continue_pc = *pos;
-
- *pos = index_pc;
- index = init_array_element (array, element, exp, pos, noside,
- low_bound, high_bound);
- *pos = continue_pc;
- }
- else
- {
- if (index > high_bound)
- /* To avoid memory corruption. */
- error (_("Too many array elements"));
- memcpy (value_contents_raw (array)
- + (index - low_bound) * element_size,
- value_contents (element),
- element_size);
- }
+ if (index > high_bound)
+ /* To avoid memory corruption. */
+ error (_("Too many array elements"));
+ memcpy (value_contents_raw (array)
+ + (index - low_bound) * element_size,
+ value_contents (element),
+ element_size);
index++;
}
return array;
--
2.17.2
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] Remove some dead code from evaluate_subexp_standard
2020-11-28 22:43 [PATCH] Remove some dead code from evaluate_subexp_standard Tom Tromey
@ 2020-11-29 19:55 ` Andrew Burgess
2020-11-30 8:20 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2020-11-29 19:55 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
* Tom Tromey <tom@tromey.com> [2020-11-28 15:43:23 -0700]:
> I noticed that in the OP_ARRAY case in evaluate_subexp_standard,
> "index_pc" is read but never set. This dead code then guards the only
> call to init_array_element, so this can be removed as well.
For the record index_pc was made redundant in commit:
commit ae8fddda32d161ea0d8606fdd71349230d5b0ad6
Date: Tue Apr 15 11:28:15 2014 +0800
Remove operator BINOP_RANGE
This change looks good to me, we've clearly not needed this
functionality for the last 6 years!
Thanks,
Andrew
>
> gdb/ChangeLog
> 2020-11-28 Tom Tromey <tom@tromey.com>
>
> * eval.c (init_array_element): Remove.
> (evaluate_subexp_standard) <OP_ARRAY>: Remove "index_pc".
> ---
> gdb/ChangeLog | 5 ++++
> gdb/eval.c | 64 ++++++---------------------------------------------
> 2 files changed, 12 insertions(+), 57 deletions(-)
>
> diff --git a/gdb/eval.c b/gdb/eval.c
> index 407d4b4ac59..d02813eec52 100644
> --- a/gdb/eval.c
> +++ b/gdb/eval.c
> @@ -57,10 +57,6 @@ static struct value *evaluate_struct_tuple (struct value *,
> struct expression *, int *,
> enum noside, int);
>
> -static LONGEST init_array_element (struct value *, struct value *,
> - struct expression *, int *, enum noside,
> - LONGEST, LONGEST);
> -
> struct value *
> evaluate_subexp (struct type *expect_type, struct expression *exp,
> int *pos, enum noside noside)
> @@ -337,39 +333,6 @@ evaluate_struct_tuple (struct value *struct_val,
> return struct_val;
> }
>
> -/* Recursive helper function for setting elements of array tuples.
> - The target is ARRAY (which has bounds LOW_BOUND to HIGH_BOUND); the
> - element value is ELEMENT; EXP, POS and NOSIDE are as usual.
> - Evaluates index expressions and sets the specified element(s) of
> - ARRAY to ELEMENT. Returns last index value. */
> -
> -static LONGEST
> -init_array_element (struct value *array, struct value *element,
> - struct expression *exp, int *pos,
> - enum noside noside, LONGEST low_bound, LONGEST high_bound)
> -{
> - LONGEST index;
> - int element_size = TYPE_LENGTH (value_type (element));
> -
> - if (exp->elts[*pos].opcode == BINOP_COMMA)
> - {
> - (*pos)++;
> - init_array_element (array, element, exp, pos, noside,
> - low_bound, high_bound);
> - return init_array_element (array, element,
> - exp, pos, noside, low_bound, high_bound);
> - }
> - else
> - {
> - index = value_as_long (evaluate_subexp (nullptr, exp, pos, noside));
> - if (index < low_bound || index > high_bound)
> - error (_("tuple index out of range"));
> - memcpy (value_contents_raw (array) + (index - low_bound) * element_size,
> - value_contents (element), element_size);
> - }
> - return index;
> -}
> -
> /* Promote value ARG1 as appropriate before performing a unary operation
> on this argument.
> If the result is not appropriate for any particular language then it
> @@ -1433,30 +1396,17 @@ evaluate_subexp_standard (struct type *expect_type,
> for (tem = nargs; --nargs >= 0;)
> {
> struct value *element;
> - int index_pc = 0;
>
> element = evaluate_subexp (element_type, exp, pos, noside);
> if (value_type (element) != element_type)
> element = value_cast (element_type, element);
> - if (index_pc)
> - {
> - int continue_pc = *pos;
> -
> - *pos = index_pc;
> - index = init_array_element (array, element, exp, pos, noside,
> - low_bound, high_bound);
> - *pos = continue_pc;
> - }
> - else
> - {
> - if (index > high_bound)
> - /* To avoid memory corruption. */
> - error (_("Too many array elements"));
> - memcpy (value_contents_raw (array)
> - + (index - low_bound) * element_size,
> - value_contents (element),
> - element_size);
> - }
> + if (index > high_bound)
> + /* To avoid memory corruption. */
> + error (_("Too many array elements"));
> + memcpy (value_contents_raw (array)
> + + (index - low_bound) * element_size,
> + value_contents (element),
> + element_size);
> index++;
> }
> return array;
> --
> 2.17.2
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] Remove some dead code from evaluate_subexp_standard
2020-11-29 19:55 ` Andrew Burgess
@ 2020-11-30 8:20 ` Tom Tromey
0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2020-11-30 8:20 UTC (permalink / raw)
To: Andrew Burgess; +Cc: Tom Tromey, gdb-patches
Andrew> For the record index_pc was made redundant in commit:
Andrew> commit ae8fddda32d161ea0d8606fdd71349230d5b0ad6
Andrew> Date: Tue Apr 15 11:28:15 2014 +0800
Andrew> Remove operator BINOP_RANGE
Thanks for doing the archaeology.
I looked briefly but didn't see it.
Andrew> This change looks good to me, we've clearly not needed this
Andrew> functionality for the last 6 years!
Thanks, I'm going to check it in.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-30 8:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-28 22:43 [PATCH] Remove some dead code from evaluate_subexp_standard Tom Tromey
2020-11-29 19:55 ` Andrew Burgess
2020-11-30 8:20 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox