This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH for debug/23336 - enums types missing from debug info
- From: Daniel Jacobowitz <drow at false dot org>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 22 Jul 2006 23:25:58 -0400
- Subject: PATCH for debug/23336 - enums types missing from debug info
This patch extends Aldy's fix, which caused (foo *) casts to emit the foo
type in debug information, to make enumerator usage emit the containing
enumeral type.
We already set TREE_USED on the enumerator; I could have checked for any
used member of an enum before skipping it in dwarf2out and that would also
have fixed the PR. But it would bloat debug information. As I noted in
c++/26965, this is a general problem with the compiler right now: TREE_USED
is often set for types during parsing, but we don't know until late whether
we're going to emit them. I know we used to have a problem where this:
enum foo {
bar = 1,
zed = bar
};
would always cause enum foo to be emitted, because it was self-referential.
I don't see any way to fix this sort of thing without keeping explicit debug
type dependencies associated with objects at the level we can usefully
garbage collect: functions, initializers for statics, types. Obviously this
is much more information than the single TREE_USED bit, and I don't know if
it's enough more to be fatally flawed.
Anyway, in the mean time, let's at least fix enums!
I would appreciate a C++ maintainer looking at this; I'm not sure if I put
it in the right place. It's remarkably annoying that there's a second copy
of this entire layer of the C++ frontend for template instantiation.
Bootstrapped and tested on x86_64-pc-linux-gnu. OK?
--
Daniel Jacobowitz
CodeSourcery
2006-07-22 Daniel Jacobowitz <dan@codesourcery.com>
PR debug/23336
* c-typeck.c (build_external_type): Mark used enum types.
* dwarf2out.c (dwarf2out_abstract_function): Save and restore
cfun also.
(gen_subprogram_die): Whitespace fix.
2006-07-22 Daniel Jacobowitz <dan@codesourcery.com>
PR debug/23336
* pt.c (tsubst_copy_and_build): Mark used enum types.
* semantics.c (finish_id_expression): Likewise.
2006-07-22 Daniel Jacobowitz <dan@codesourcery.com>
PR debug/23336
* lib/gcc-dg.exp (gcc-dg-debug-runtest): Suppress new tests
at -g1.
* gcc.dg/debug/enum-1.c, g++.dg/debug/enum-1.C,
g++.dg/debug/enum-2.C: New.
Index: testsuite/lib/gcc-dg.exp
===================================================================
--- testsuite/lib/gcc-dg.exp (revision 115676)
+++ testsuite/lib/gcc-dg.exp (working copy)
@@ -292,7 +292,12 @@ proc gcc-dg-debug-runtest { target_compi
foreach flags $DEBUG_TORTURE_OPTIONS {
set doit 1
- if { [string match {*/debug-[126].c} "$nshort"] \
+
+ # These tests check for information which may be deliberately
+ # suppressed at -g1.
+ if { ([string match {*/debug-[126].c} "$nshort"] \
+ || [string match {*/enum-1.c} "$nshort"] \
+ || [string match {*/enum-[12].C} "$nshort"]) \
&& [string match "*1" [lindex "$flags" 0] ] } {
set doit 0
}
Index: cp/pt.c
===================================================================
--- cp/pt.c (revision 115676)
+++ cp/pt.c (working copy)
@@ -9182,7 +9182,10 @@ tsubst_copy_and_build (tree t,
/* As in finish_id_expression, we resolve enumeration constants
to their underlying values. */
if (TREE_CODE (t) == CONST_DECL)
- return DECL_INITIAL (t);
+ {
+ used_types_insert (TREE_TYPE (t));
+ return DECL_INITIAL (t);
+ }
return t;
default:
Index: cp/semantics.c
===================================================================
--- cp/semantics.c (revision 115676)
+++ cp/semantics.c (working copy)
@@ -2589,7 +2589,10 @@ finish_id_expression (tree id_expression
{
*idk = CP_ID_KIND_NONE;
if (!processing_template_decl)
- return DECL_INITIAL (decl);
+ {
+ used_types_insert (TREE_TYPE (decl));
+ return DECL_INITIAL (decl);
+ }
return decl;
}
else
Index: c-typeck.c
===================================================================
--- c-typeck.c (revision 115676)
+++ c-typeck.c (working copy)
@@ -2067,6 +2067,7 @@ build_external_ref (tree id, int fun, lo
if (TREE_CODE (ref) == CONST_DECL)
{
+ used_types_insert (TREE_TYPE (ref));
ref = DECL_INITIAL (ref);
TREE_CONSTANT (ref) = 1;
TREE_INVARIANT (ref) = 1;
--- /dev/null 2006-07-20 04:40:48.651748895 -0400
+++ testsuite/gcc.dg/debug/enum-1.c 2006-07-22 14:47:18.000000000 -0400
@@ -0,0 +1,16 @@
+/* Verify that used enums are output. */
+/* { dg-do compile } */
+/* { dg-final { scan-assembler "JTI_MAX" } } */
+
+int var;
+
+enum java_tree_index
+{
+ JTI_MAX
+};
+
+void function (void)
+{
+ var = JTI_MAX;
+}
+
--- /dev/null 2006-07-20 04:40:48.651748895 -0400
+++ testsuite/g++.dg/debug/enum-1.C 2006-07-22 14:49:53.000000000 -0400
@@ -0,0 +1,16 @@
+/* Verify that used enums are output. */
+/* { dg-do compile } */
+/* { dg-final { scan-assembler "JTI_MAX" } } */
+
+int var;
+
+enum java_tree_index
+{
+ JTI_MAX
+};
+
+void function (void)
+{
+ var = JTI_MAX;
+}
+
--- /dev/null 2006-07-20 04:40:48.651748895 -0400
+++ testsuite/g++.dg/debug/enum-2.C 2006-07-22 15:07:34.000000000 -0400
@@ -0,0 +1,22 @@
+/* Verify that used enums are output. */
+/* { dg-do compile } */
+/* { dg-final { scan-assembler "JTI_MAX" } } */
+
+int var;
+
+enum java_tree_index
+{
+ JTI_MAX
+};
+
+template<int X>
+void tmpl (void)
+{
+ var = JTI_MAX + X;
+}
+
+void
+function (void)
+{
+ tmpl<2>();
+}
Index: dwarf2out.c
===================================================================
--- dwarf2out.c (revision 115676)
+++ dwarf2out.c (working copy)
@@ -11457,6 +11457,7 @@ dwarf2out_abstract_function (tree decl)
{
dw_die_ref old_die;
tree save_fn;
+ struct function *save_cfun;
tree context;
int was_abstract = DECL_ABSTRACT (decl);
@@ -11480,7 +11481,9 @@ dwarf2out_abstract_function (tree decl)
/* Pretend we've just finished compiling this function. */
save_fn = current_function_decl;
+ save_cfun = cfun;
current_function_decl = decl;
+ cfun = DECL_STRUCT_FUNCTION (decl);
set_decl_abstract_flags (decl, 1);
dwarf2out_decl (decl);
@@ -11488,6 +11491,7 @@ dwarf2out_abstract_function (tree decl)
set_decl_abstract_flags (decl, 0);
current_function_decl = save_fn;
+ cfun = save_cfun;
}
/* Helper function of premark_used_types() which gets called through
@@ -11531,7 +11535,7 @@ gen_subprogram_die (tree decl, dw_die_re
int declaration = (current_function_decl != decl
|| class_or_namespace_scope_p (context_die));
- premark_used_types();
+ premark_used_types ();
/* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
started to generate the abstract instance of an inline, decided to output