This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
improve DW_AT_const_value output
- From: gkeating at apple dot com (Geoffrey Keating)
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 26 Mar 2006 22:09:08 -0800 (PST)
- Subject: improve DW_AT_const_value output
This patch permits more frequent DW_AT_const_value output.
If you change setup_one_parameter in tree-inline.c to set DECL_INITIAL
in the variable it creates, this gets you proper output of
DW_AT_const_value for parameters optimised out. Unfortunately it
seems you also get a build failure in libstdc++ when something tries
to gimplify the DECL_INITIAL (of an unused variable, yet!). I think
this patch will help in general, even without that change.
Bootstrapped & tested on powerpc-darwin.
--
- Geoffrey Keating <geoffk@apple.com>
===File ~/patches/gcc-dwarf-consts-1.patch==================
2006-03-26 Geoffrey Keating <geoffk@apple.com>
* 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.
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c (revision 112374)
+++ gcc/dwarf2out.c (working copy)
@@ -9929,6 +9929,23 @@
}
+/* 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 = 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_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
============================================================