diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0f50ac3d6b79..dac49f65bcbe 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2006-03-26 Geoffrey Keating + + * dwarf2out.c (add_location_or_const_value_attribute): Call + tree_add_const_value_attribute if nothing else works. + (reference_to_unused): New. + (rtl_for_decl_init): Use reference_to_unused to decide whether + to output an initializer. + 2006-03-27 Alan Modra PR target/26459 diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 6255c40208f4..5b1894c5be00 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -9929,6 +9929,23 @@ add_const_value_attribute (dw_die_ref die, rtx rtl) } +/* Determine whether the evaluation of EXPR references any variables + or functions which aren't otherwise used (and therefore may not be + output). */ +static tree +reference_to_unused (tree * tp, int * walk_subtrees, + void * data ATTRIBUTE_UNUSED) +{ + if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp)) + *walk_subtrees = 0; + + if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp) + && ! TREE_ASM_WRITTEN (*tp)) + return *tp; + else + return NULL_TREE; +} + /* Generate an RTL constant from a decl initializer INIT with decl type TYPE, for use in a later add_const_value_attribute call. */ @@ -9955,15 +9972,16 @@ rtl_for_decl_init (tree init, tree type) rtl = gen_rtx_CONST_STRING (VOIDmode, ggc_strdup (TREE_STRING_POINTER (init))); } + /* Although DWARF could easily handle other kinds of aggregates, we + have no way to represent such values as RTL constants, so skip + those. */ + else if (AGGREGATE_TYPE_P (type)) + ; /* If the initializer is something that we know will expand into an - immediate RTL constant, expand it now. Expanding anything else - tends to produce unresolved symbols; see debug/5770 and c++/6381. */ - /* Aggregate, vector, and complex types may contain constructors that may - result in code being generated when expand_expr is called, so we can't - handle them here. Integer and float are useful and safe types to handle - here. */ - else if ((INTEGRAL_TYPE_P (type) || SCALAR_FLOAT_TYPE_P (type)) - && initializer_constant_valid_p (init, type) == null_pointer_node) + immediate RTL constant, expand it now. We must be careful not to + reference variables which won't be output. */ + else if (initializer_constant_valid_p (init, type) + && ! walk_tree (&init, reference_to_unused, NULL, NULL)) { rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER); @@ -10327,6 +10345,9 @@ add_location_or_const_value_attribute (dw_die_ref die, tree decl, add_AT_location_description (die, attr, descr); return; } + /* None of that worked, so it must not really have a location; + try adding a constant value attribute from the DECL_INITIAL. */ + tree_add_const_value_attribute (die, decl); } /* If we don't have a copy of this variable in memory for some reason (such