On Tue, Sep 19, 2017 at 04:09:20PM +0200, Richard Biener wrote:
> > The problem is that add_const_value_attribute has lots of smarts to handle
> > various kinds of constants, which the
> > if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
> > && initializer_constant_valid_p (init, type))
> > block doesn't implement, it relies on all the smarts to be done earlier.
> > One option is to duplicate that all on trees, another option is
> > to use the rtl_for_decl_init + add_const_value_attribute way
> > even for early_dwarf for constants, something like:
> >
> > - if (! early_dwarf)
> > + if (! early_dwarf || CONSTANT_CLASS_P (init))
> > {
> > rtl = rtl_for_decl_init (init, type);
> > if (rtl)
> > return add_const_value_attribute (die, rtl);
> > }
> > if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
> > && initializer_constant_valid_p (init, type))
>
> If we are sure that rtl_for_decl_init will never create symbol references
> for CONSTANT_CLASS_P (init) that's fine, but yes, in the end it would be
> nice to not have overlapping rtl/tree handling and have all constants
> handled in the tree path...
Will try now following plus testcase, the rest of constants I believe end up
being DW_FORM_block encoded and so is pretty much what we emit even for the
initializer_constant_valid_p tree fallback case.
--- gcc/dwarf2out.c.jj 2017-09-15 18:11:03.000000000 +0200
+++ gcc/dwarf2out.c 2017-09-19 16:03:27.678337475 +0200
@@ -19440,6 +19440,19 @@ tree_add_const_value_attribute (dw_die_r
init = t;
gcc_assert (!DECL_P (init));
+ if (TREE_CODE (init) == INTEGER_CST)
+ {
+ if (tree_fits_uhwi_p (init))
+ {
+ add_AT_unsigned (die, DW_AT_const_value, tree_to_uhwi (init));
+ return true;
+ }
+ if (tree_fits_shwi_p (init))
+ {
+ add_AT_int (die, DW_AT_const_value, tree_to_shwi (init));
+ return true;
+ }
+ }
if (! early_dwarf)
{
rtl = rtl_for_decl_init (init, type);
Jakub