[11/13] Remove dead code from dwarf2_const_value_data

Message ID 20250320-attribute-madness-v1-11-79d42789f881@adacore.com
State New
Headers
Series More work on DW_FORM_* and sign handling |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
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 March 20, 2025, 7:27 p.m. UTC
  dwarf2_const_value_data checks the size of the data like so:

   if (bits < sizeof (*value) * 8)
...
  else if (bits == sizeof (*value) * 8)
...
   else
...

However, 'bits' can only be 8, 16, 32, or 64.  And, because 'value' is
a LONGEST, which is alwasy 64-bit, the final 'else' can never be
taken.

This patch removes the dead code.  And, because this was the only
reason for a non-void return value, the return type is changed as
well.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32680
---
 gdb/dwarf2/read.c | 51 ++++++++++++++++-----------------------------------
 1 file changed, 16 insertions(+), 35 deletions(-)
  

Patch

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 6bfdac82e08f32f9d9172ee8f16a27a0a1f0f6f9..bed3da1c2e456d78ef5a47d4b1cef2ad4c47a033 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -17327,13 +17327,10 @@  new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
    list was that this is unspecified.  We choose to always zero-extend
    because that is the interpretation long in use by GCC.  */
 
-static gdb_byte *
-dwarf2_const_value_data (const struct attribute *attr, struct obstack *obstack,
-			 struct dwarf2_cu *cu, LONGEST *value, int bits)
+static void
+dwarf2_const_value_data (const struct attribute *attr, LONGEST *value,
+			 int bits)
 {
-  struct objfile *objfile = cu->per_objfile->objfile;
-  enum bfd_endian byte_order = bfd_big_endian (objfile->obfd.get ()) ?
-				BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
   LONGEST l = attr->constant_value (0);
 
   if (bits < sizeof (*value) * 8)
@@ -17341,16 +17338,8 @@  dwarf2_const_value_data (const struct attribute *attr, struct obstack *obstack,
       l &= ((LONGEST) 1 << bits) - 1;
       *value = l;
     }
-  else if (bits == sizeof (*value) * 8)
-    *value = l;
   else
-    {
-      gdb_byte *bytes = (gdb_byte *) obstack_alloc (obstack, bits / 8);
-      store_unsigned_integer (bytes, bits / 8, byte_order, l);
-      return bytes;
-    }
-
-  return NULL;
+    *value = l;
 }
 
 /* Read a constant value from an attribute.  Either set *VALUE, or if
@@ -17435,16 +17424,16 @@  dwarf2_const_value_attr (const struct attribute *attr, struct type *type,
 	 converted to host endianness, so we just need to sign- or
 	 zero-extend it as appropriate.  */
     case DW_FORM_data1:
-      *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 8);
+      dwarf2_const_value_data (attr, value, 8);
       break;
     case DW_FORM_data2:
-      *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 16);
+      dwarf2_const_value_data (attr, value, 16);
       break;
     case DW_FORM_data4:
-      *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 32);
+      dwarf2_const_value_data (attr, value, 32);
       break;
     case DW_FORM_data8:
-      *bytes = dwarf2_const_value_data (attr, obstack, cu, value, 64);
+      dwarf2_const_value_data (attr, value, 64);
       break;
 
     case DW_FORM_sdata:
@@ -18651,31 +18640,23 @@  dwarf2_fetch_constant_bytes (sect_offset sect_off,
 	 zero-extend it as appropriate.  */
     case DW_FORM_data1:
       type = die_type (die, cu);
-      result = dwarf2_const_value_data (attr, obstack, cu, &value, 8);
-      if (result == NULL)
-	result = write_constant_as_bytes (obstack, byte_order,
-					  type, value, len);
+      dwarf2_const_value_data (attr, &value, 8);
+      result = write_constant_as_bytes (obstack, byte_order, type, value, len);
       break;
     case DW_FORM_data2:
       type = die_type (die, cu);
-      result = dwarf2_const_value_data (attr, obstack, cu, &value, 16);
-      if (result == NULL)
-	result = write_constant_as_bytes (obstack, byte_order,
-					  type, value, len);
+      dwarf2_const_value_data (attr, &value, 16);
+      result = write_constant_as_bytes (obstack, byte_order, type, value, len);
       break;
     case DW_FORM_data4:
       type = die_type (die, cu);
-      result = dwarf2_const_value_data (attr, obstack, cu, &value, 32);
-      if (result == NULL)
-	result = write_constant_as_bytes (obstack, byte_order,
-					  type, value, len);
+      dwarf2_const_value_data (attr, &value, 32);
+      result = write_constant_as_bytes (obstack, byte_order, type, value, len);
       break;
     case DW_FORM_data8:
       type = die_type (die, cu);
-      result = dwarf2_const_value_data (attr, obstack, cu, &value, 64);
-      if (result == NULL)
-	result = write_constant_as_bytes (obstack, byte_order,
-					  type, value, len);
+      dwarf2_const_value_data (attr, &value, 64);
+      result = write_constant_as_bytes (obstack, byte_order, type, value, len);
       break;
 
     case DW_FORM_sdata: