[v3,6/7] Remove "highbound" parameter from value_array

Message ID 20230829-cleanup-array-op-v3-6-0d0256c6a6ed@adacore.com
State New
Headers
Series Small cleanups in array_operation::evaluate |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Patch failed to apply

Commit Message

Tom Tromey Aug. 29, 2023, 6:10 p.m. UTC
  value_array requires the passed-in bounds to match the length of the
array_view it is given.  This patch removes the redundant "highbound"
parameter.

Reviewed-by: John Baldwin <jhb@FreeBSD.org>
---
 gdb/eval.c      |  2 +-
 gdb/rust-lang.c |  2 +-
 gdb/valops.c    | 25 +++++++++----------------
 gdb/value.h     |  2 +-
 4 files changed, 12 insertions(+), 19 deletions(-)
  

Patch

diff --git a/gdb/eval.c b/gdb/eval.c
index 8dd1b530d06..7c955a4e9eb 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -2515,7 +2515,7 @@  array_operation::evaluate (struct type *expect_type,
 	 objects.  */
       argvec[tem] = in_args[tem]->evaluate_with_coercion (exp, noside);
     }
-  return value_array (tem2, tem3, argvec);
+  return value_array (tem2, argvec);
 }
 
 value *
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index f6e7d25f587..0e2ca090ba8 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1344,7 +1344,7 @@  eval_op_rust_array (struct type *expect_type, struct expression *exp,
 
       for (i = 0; i < copies; ++i)
 	eltvec[i] = elt;
-      return value_array (0, copies - 1, eltvec);
+      return value_array (0, eltvec);
     }
   else
     {
diff --git a/gdb/valops.c b/gdb/valops.c
index 1133049c54a..6404091d451 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1684,18 +1684,16 @@  value_ind (struct value *arg1)
 /* Create a value for an array by allocating space in GDB, copying the
    data into that space, and then setting up an array value.
 
-   The array bounds are set from LOWBOUND and HIGHBOUND, and the array
-   is populated from the values passed in ELEMVEC.
+   The array bounds are set from LOWBOUND and the size of ELEMVEC, and
+   the array is populated from the values passed in ELEMVEC.
 
    The element type of the array is inherited from the type of the
    first element, and all elements must have the same size (though we
    don't currently enforce any restriction on their types).  */
 
 struct value *
-value_array (int lowbound, int highbound,
-	     gdb::array_view<struct value *> elemvec)
+value_array (int lowbound, gdb::array_view<struct value *> elemvec)
 {
-  int nelem;
   int idx;
   ULONGEST typelength;
   struct value *val;
@@ -1704,28 +1702,23 @@  value_array (int lowbound, int highbound,
   /* Validate that the bounds are reasonable and that each of the
      elements have the same size.  */
 
-  nelem = highbound - lowbound + 1;
-  if (nelem <= 0)
-    {
-      error (_("bad array bounds (%d, %d)"), lowbound, highbound);
-    }
   typelength = type_length_units (elemvec[0]->enclosing_type ());
-  for (idx = 1; idx < nelem; idx++)
+  for (struct value *other : elemvec.slice (1))
     {
-      if (type_length_units (elemvec[idx]->enclosing_type ())
-	  != typelength)
+      if (type_length_units (other->enclosing_type ()) != typelength)
 	{
 	  error (_("array elements must all be the same size"));
 	}
     }
 
   arraytype = lookup_array_range_type (elemvec[0]->enclosing_type (),
-				       lowbound, highbound);
+				       lowbound,
+				       lowbound + elemvec.size () - 1);
 
   if (!current_language->c_style_arrays_p ())
     {
       val = value::allocate (arraytype);
-      for (idx = 0; idx < nelem; idx++)
+      for (idx = 0; idx < elemvec.size (); idx++)
 	elemvec[idx]->contents_copy (val, idx * typelength, 0, typelength);
       return val;
     }
@@ -1734,7 +1727,7 @@  value_array (int lowbound, int highbound,
      copying in each element.  */
 
   val = value::allocate (arraytype);
-  for (idx = 0; idx < nelem; idx++)
+  for (idx = 0; idx < elemvec.size (); idx++)
     elemvec[idx]->contents_copy (val, idx * typelength, 0, typelength);
   return val;
 }
diff --git a/gdb/value.h b/gdb/value.h
index ccf52199146..c28b731cc42 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1225,7 +1225,7 @@  inline struct value *value_string (const char *ptr, ssize_t count,
   return value_string ((const gdb_byte *) ptr, count, char_type);
 }
 
-extern struct value *value_array (int lowbound, int highbound,
+extern struct value *value_array (int lowbound,
 				  gdb::array_view<struct value *> elemvec);
 
 extern struct value *value_concat (struct value *arg1, struct value *arg2);