[10/13] Use attribute::signed_constant in attribute::as_boolean

Message ID 20250320-attribute-madness-v1-10-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 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Tom Tromey March 20, 2025, 7:27 p.m. UTC
  This changes attribute::as_boolean to use attribute::signed_constant.
This is maybe overkill but lets any reasonable constant form through.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32680
---
 gdb/dwarf2/attribute.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
index 25cf2b62cfd1c8f4981be2787fe4ade8c8c66b81..d3b3eed81bd500bf06dc8c83cab7ae1fa8c17974 100644
--- a/gdb/dwarf2/attribute.c
+++ b/gdb/dwarf2/attribute.c
@@ -323,5 +323,8 @@  attribute::as_boolean () const
     return true;
   else if (form == DW_FORM_flag)
     return u.unsnd != 0;
-  return constant_value (0) != 0;
+  /* Using signed_constant here will work even for the weird case
+     where a negative value is provided.  Probably doesn't matter but
+     also seems harmless.  */
+  return signed_constant ().value_or (0) != 0;
 }