[7/7] Remove is_nonnegative and as_nonnegative

Message ID 20250311-attribute-unsigned-initial-v1-7-833f35aa0f29@adacore.com
State New
Headers
Series Handle unsigned DW_FORM_data* constants more nicely |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Tom Tromey March 11, 2025, 5 p.m. UTC
  This removes attribute::is_nonnegative and attribute::as_nonnegative
in favor of a call to unsigned_constant.
---
 gdb/dwarf2/attribute.h | 22 ----------------------
 gdb/dwarf2/read.c      | 37 ++++++++++++++++++++-----------------
 2 files changed, 20 insertions(+), 39 deletions(-)
  

Patch

diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
index 824e92bf9cf991817e4ba0f48aebc211c2106036..4dce04d65bb989cb673220c314721f4b2a6117af 100644
--- a/gdb/dwarf2/attribute.h
+++ b/gdb/dwarf2/attribute.h
@@ -91,28 +91,6 @@  struct attribute
     return u.unsnd;
   }
 
-  /* Return true if the value is nonnegative.  Requires that that
-     reprocessing not be needed.  */
-  bool is_nonnegative () const
-  {
-    if (form_is_unsigned ())
-      return true;
-    if (form_is_strictly_signed ())
-      return as_signed () >= 0;
-    return false;
-  }
-
-  /* Return the nonnegative value.  Requires that that reprocessing not be
-     needed.  */
-  ULONGEST as_nonnegative () const
-  {
-    if (form_is_unsigned ())
-      return as_unsigned ();
-    if (form_is_strictly_signed ())
-      return (ULONGEST)as_signed ();
-    gdb_assert (false);
-  }
-
   /* Return non-zero if ATTR's value is a section offset --- classes
      lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
      You may use the as_unsigned method to retrieve such offsets.
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index ea684f98347274032797554c30cd7d6fcc20d6b7..467aa141124d9952e4f2c5531bfb6fdbb5b3344f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -17094,27 +17094,30 @@  new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
       attr = dwarf2_attr (die,
 			  inlined_func ? DW_AT_call_file : DW_AT_decl_file,
 			  &file_cu);
-      if (attr != nullptr && attr->is_nonnegative ())
+      if (attr != nullptr)
 	{
-	  file_name_index file_index
-	    = (file_name_index) attr->as_nonnegative ();
-	  struct file_entry *fe;
-
-	  if (file_cu->line_header == nullptr)
+	  std::optional<ULONGEST> index_cst = attr->unsigned_constant ();
+	  if (index_cst.has_value ())
 	    {
-	      file_and_directory fnd (nullptr, nullptr);
-	      handle_DW_AT_stmt_list (file_cu->dies, file_cu, fnd, {}, false);
-	    }
+	      file_name_index file_index = (file_name_index) *index_cst;
+	      struct file_entry *fe;
 
-	  if (file_cu->line_header != nullptr)
-	    fe = file_cu->line_header->file_name_at (file_index);
-	  else
-	    fe = NULL;
+	      if (file_cu->line_header == nullptr)
+		{
+		  file_and_directory fnd (nullptr, nullptr);
+		  handle_DW_AT_stmt_list (file_cu->dies, file_cu, fnd, {}, false);
+		}
 
-	  if (fe == NULL)
-	    complaint (_("file index out of range"));
-	  else
-	    sym->set_symtab (fe->symtab);
+	      if (file_cu->line_header != nullptr)
+		fe = file_cu->line_header->file_name_at (file_index);
+	      else
+		fe = NULL;
+
+	      if (fe == NULL)
+		complaint (_("file index out of range"));
+	      else
+		sym->set_symtab (fe->symtab);
+	    }
 	}
 
       switch (die->tag)