]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use LONGEST rather than int for array slices
authorTom Tromey <tromey@adacore.com>
Wed, 27 Aug 2025 19:08:13 +0000 (13:08 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 11 Sep 2025 17:59:58 +0000 (11:59 -0600)
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.

gdb/ada-lang.c
gdb/eval.c
gdb/valops.c
gdb/value.h

index f935365d667748fbfb553ed2d1fc55ed3dc76c6d..af7bc1ec0c0915846547a4326380d75e7c091f45 100644 (file)
@@ -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<LONGEST> 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.  */
index 498c0bffd1e2d7971090fdc0498b2338dcbc7d73..cefc8573b320b61170a31ce8f0cf74903dc75411 100644 (file)
@@ -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);
 }
 
index 85d69fb11f27e283a8a400ae0205df022c8499d2..fa87546770a603555001236219c583b89ed2324a 100644 (file)
@@ -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;
index 374934d20f6e8bc8583bbf94640afede4c3d85d3..b9d2809beadc74447ff694b612eb10070af4634d 100644 (file)
@@ -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