This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Add DW_AT_const_value as unsigned or int depending on type and value used.
- From: Mark Wielaard <mjw at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Tom Tromey <tromey at redhat dot com>, Jason Merrill <jason at redhat dot com>, Cary Coutant <ccoutant at google dot com>
- Date: Mon, 14 Apr 2014 23:25:23 +0200
- Subject: Re: [PATCH] Add DW_AT_const_value as unsigned or int depending on type and value used.
- Authentication-results: sourceware.org; auth=none
- References: <1395573430-21207-1-git-send-email-mjw at redhat dot com>
On Sun, 2014-03-23 at 12:17 +0100, Mark Wielaard wrote:
> As the comment in the code already indicated DWARF2 does provide
> DW_FORM_sdata/DW_FORM_udata to represent signed/unsigned data.
> Enumeration constants wider than HOST_WIDE_INT are already handled
> separately. Those constant values that do fit a HOST_WIDE_INT can
> be encoded as signed or unsigned depending on type and value for
> more efficient encoding.
>
> * dwarf2out.c (gen_enumeration_type_die): Add DW_AT_const_value
> as unsigned or int depending on type and value used.
Since stage 1 opened up I would like to request approval again to push
this. Patch rebased to current master attached.
Thanks,
Mark
commit b81dcfbb049d4cce712ad185c62e503ea9f4658e
Author: Mark Wielaard <mjw@redhat.com>
Date: Fri Mar 7 22:27:15 2014 +0100
Add DW_AT_const_value as unsigned or int depending on type and value used.
As the comment in the code already indicated DWARF2 does provide
DW_FORM_sdata/DW_FORM_udata to represent signed/unsigned data.
Enumeration constants wider than HOST_WIDE_INT are already handled
separately. Those constant values that do fit a HOST_WIDE_INT can
be encoded as signed or unsigned depending on type and value for
more efficient encoding.
* dwarf2out.c (gen_enumeration_type_die): Add DW_AT_const_value
as unsigned or int depending on type and value used.
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b1706ce..355ba29 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-21 Mark Wielaard <mjw@redhat.com>
+
+ * dwarf2out.c (gen_enumeration_type_die): Add DW_AT_const_value
+ as unsigned or int depending on type and value used.
+
2014-03-20 Mark Wielaard <mjw@redhat.com>
* dwarf2out.c (add_bound_info): If HOST_WIDE_INT is big enough,
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 7eef56c..d4e4b17 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -17369,19 +17369,14 @@ gen_enumeration_type_die (tree type, dw_die_ref context_die)
if (simple_type_size_in_bits (TREE_TYPE (value))
<= HOST_BITS_PER_WIDE_INT || tree_fits_shwi_p (value))
- /* DWARF2 does not provide a way of indicating whether or
- not enumeration constants are signed or unsigned. GDB
- always assumes the values are signed, so we output all
- values as if they were signed. That means that
- enumeration constants with very large unsigned values
- will appear to have negative values in the debugger.
-
- TODO: the above comment is wrong, DWARF2 does provide
- DW_FORM_sdata/DW_FORM_udata to represent signed/unsigned data.
- This should be re-worked to use correct signed/unsigned
- int/double tags for all cases, instead of always treating as
- signed. */
- add_AT_int (enum_die, DW_AT_const_value, TREE_INT_CST_LOW (value));
+ {
+ HOST_WIDE_INT val = TREE_INT_CST_LOW (value);
+ if (TYPE_UNSIGNED (TREE_TYPE (value)) || val >= 0)
+ add_AT_unsigned (enum_die, DW_AT_const_value,
+ (unsigned HOST_WIDE_INT) val);
+ else
+ add_AT_int (enum_die, DW_AT_const_value, val);
+ }
else
/* Enumeration constants may be wider than HOST_WIDE_INT. Handle
that here. */