public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 6/7] Remove "highbound" parameter from value_array
Date: Tue, 29 Aug 2023 09:34:44 -0600	[thread overview]
Message-ID: <20230829-cleanup-array-op-v2-6-3035458b0443@adacore.com> (raw)
In-Reply-To: <20230829-cleanup-array-op-v2-0-3035458b0443@adacore.com>

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.
---
 gdb/eval.c      |  2 +-
 gdb/rust-lang.c |  2 +-
 gdb/valops.c    | 22 ++++++++--------------
 gdb/value.h     |  2 +-
 4 files changed, 11 insertions(+), 17 deletions(-)

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..081c621594e 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,13 +1702,8 @@ 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 (idx = 1; idx < elemvec.size (); idx++)
     {
       if (type_length_units (elemvec[idx]->enclosing_type ())
 	  != typelength)
@@ -1720,12 +1713,13 @@ value_array (int lowbound, int highbound,
     }
 
   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 +1728,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);

-- 
2.40.1


  parent reply	other threads:[~2023-08-29 15:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-29 15:34 [PATCH v2 0/7] Small cleanups in array_operation::evaluate Tom Tromey
2023-08-29 15:34 ` [PATCH v2 1/7] Use gdb::array_view for value_array Tom Tromey
2023-08-29 15:34 ` [PATCH v2 2/7] Declare 'tem' in loop header in array_operation::evaluate Tom Tromey
2023-08-29 15:34 ` [PATCH v2 3/7] Hoist array bounds check " Tom Tromey
2023-08-29 15:34 ` [PATCH v2 4/7] Remove redundant variable from array_operation::evaluate Tom Tromey
2023-08-29 15:34 ` [PATCH v2 5/7] Remove another " Tom Tromey
2023-08-29 15:34 ` Tom Tromey [this message]
2023-08-29 17:53   ` [PATCH v2 6/7] Remove "highbound" parameter from value_array Simon Marchi
2023-08-29 18:01     ` Tom Tromey
2023-08-29 15:34 ` [PATCH v2 7/7] More renames in array_operation::evaluate Tom Tromey
2023-08-29 15:58 ` [PATCH v2 0/7] Small cleanups " John Baldwin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230829-cleanup-array-op-v2-6-3035458b0443@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).