]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use correct sign in get_mpz
authorTom Tromey <tromey@adacore.com>
Wed, 19 Mar 2025 20:04:43 +0000 (14:04 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 24 Apr 2025 19:25:08 +0000 (13:25 -0600)
This changes dwarf2/read.c:get_mpz to use the correct sign-extension
function.  Normally a rational constant uses signed values, but a
purely unsigned form also seems fine here.  This adds a new
attribute::form_is_strictly_unsigned, which is more precise than
form_is_unsigned (which accepts a lot of forms that aren't really for
ordinary constants).

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32680

gdb/dwarf2/attribute.h
gdb/dwarf2/read.c

index 460cbcf264a72b26ba1ea9e4618f46fa8f1ff82b..31ff018a80ccdb9af4332c089b7b257f96f6c149 100644 (file)
@@ -175,6 +175,15 @@ struct attribute
      false.  */
   bool form_is_strictly_signed () const;
 
+  /* Check if the attribute's form is an unsigned constant form.  This
+     only returns true for forms that are strictly unsigned -- that
+     is, for a context-dependent form like DW_FORM_data1, this returns
+     false.  */
+  bool form_is_strictly_unsigned () const
+  {
+    return form == DW_FORM_udata;
+  }
+
   /* Check if the attribute's form is a form that requires
      "reprocessing".  */
   bool form_requires_reprocessing () const;
index aae74e91769fa5383824263f42e82b7cfaad285b..c5e62dd52eeccb7eecfa5d146ecc35db36d56cbf 100644 (file)
@@ -13216,10 +13216,10 @@ get_mpz (struct dwarf2_cu *cu, gdb_mpz *value, struct attribute *attr)
                   ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE,
                   true);
     }
-  else if (attr->form_is_unsigned ())
+  else if (attr->form_is_strictly_unsigned ())
     *value = gdb_mpz (attr->as_unsigned ());
   else
-    *value = gdb_mpz (attr->constant_value (1));
+    *value = gdb_mpz (attr->signed_constant ().value_or (1));
 }
 
 /* Assuming DIE is a rational DW_TAG_constant, read the DIE's