From: Tom Tromey Date: Wed, 27 Aug 2025 19:08:13 +0000 (-0600) Subject: Use LONGEST rather than int for array slices X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6c82831fe65d1c94f776df3c2cbe6309768ed730;p=thirdparty%2Fbinutils-gdb.git Use LONGEST rather than int for array slices This patch started by removing the remaining calls to longest_to_int from ada-lang.c, then chasing down the callees to make sure they were also using LONGEST. This ended up with a small change to value_slice as well. --- diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index f935365d667..af7bc1ec0c0 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -3119,7 +3119,7 @@ ada_value_ptr_subscript (struct value *arr, int arity, struct value **ind) this array is LOW, as per Ada rules. */ static struct value * ada_value_slice_from_ptr (struct value *array_ptr, struct type *type, - int low, int high) + LONGEST low, LONGEST high) { struct type *type0 = ada_check_typedef (type); struct type *base_index_type = type0->index_type ()->target_type (); @@ -3130,7 +3130,7 @@ ada_value_slice_from_ptr (struct value *array_ptr, struct type *type, (alloc, type0->target_type (), index_type, type0->dyn_prop (DYN_PROP_BYTE_STRIDE), type0->field (0).bitsize ()); - int base_low = ada_discrete_type_low_bound (type0->index_type ()); + LONGEST base_low = ada_discrete_type_low_bound (type0->index_type ()); std::optional base_low_pos, low_pos; CORE_ADDR base; @@ -3154,7 +3154,7 @@ ada_value_slice_from_ptr (struct value *array_ptr, struct type *type, static struct value * -ada_value_slice (struct value *array, int low, int high) +ada_value_slice (struct value *array, LONGEST low, LONGEST high) { struct type *type = ada_check_typedef (array->type ()); struct type *base_index_type = type->index_type ()->target_type (); @@ -3427,7 +3427,7 @@ ada_array_length (struct value *arr, int n) less than LOW, then LOW-1 is used. */ static struct value * -empty_array (struct type *arr_type, int low, int high) +empty_array (struct type *arr_type, LONGEST low, LONGEST high) { struct type *arr_type0 = ada_check_typedef (arr_type); type_allocator alloc (arr_type0->index_type ()->target_type ()); @@ -10303,8 +10303,7 @@ ada_ternop_slice_operation::evaluate (struct type *expect_type, to_fixed_array_type (type0->target_type (), NULL, 1); return ada_value_slice_from_ptr (array, arr_type0, - longest_to_int (low_bound), - longest_to_int (high_bound)); + low_bound, high_bound); } } else if (noside == EVAL_AVOID_SIDE_EFFECTS) @@ -10312,8 +10311,7 @@ ada_ternop_slice_operation::evaluate (struct type *expect_type, else if (high_bound < low_bound) return empty_array (array->type (), low_bound, high_bound); else - return ada_value_slice (array, longest_to_int (low_bound), - longest_to_int (high_bound)); + return ada_value_slice (array, low_bound, high_bound); } /* Implement BINOP_IN_BOUNDS. */ diff --git a/gdb/eval.c b/gdb/eval.c index 498c0bffd1e..cefc8573b32 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1180,8 +1180,8 @@ ternop_slice_operation::evaluate (struct type *expect_type, struct value *upper = std::get<2> (m_storage)->evaluate (nullptr, exp, noside); - int lowbound = value_as_long (low); - int upperbound = value_as_long (upper); + LONGEST lowbound = value_as_long (low); + LONGEST upperbound = value_as_long (upper); return value_slice (array, lowbound, upperbound - lowbound + 1); } diff --git a/gdb/valops.c b/gdb/valops.c index 85d69fb11f2..fa87546770a 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -4020,7 +4020,7 @@ value_of_this_silent (const struct language_defn *lang) bound as the original ARRAY. */ struct value * -value_slice (struct value *array, int lowbound, int length) +value_slice (struct value *array, LONGEST lowbound, LONGEST length) { struct type *slice_range_type, *slice_type, *range_type; LONGEST lowerbound, upperbound; diff --git a/gdb/value.h b/gdb/value.h index 374934d20f6..b9d2809bead 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -1589,7 +1589,7 @@ extern struct value *make_cv_value (int, int, struct value *); extern struct value *varying_to_slice (struct value *); -extern struct value *value_slice (struct value *, int, int); +extern struct value *value_slice (struct value *, LONGEST, LONGEST); /* Create a complex number. The type is the complex type; the values are cast to the underlying scalar type before the complex number is