This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Your patch to PR 30700


Jan,

Your patch http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123922 is
causing an ICE when compiling this snippet with -g

namespace NS {
  int x = 0;
  int &ref = x;
}

using NS::ref;

The problem is that we are emitting debug info for 'x' during parsing,
so cgraph_global_info_ready is still false.  Since 'x' has already been
processed in this case, we will have a varpool entry for it.

Since it's too early, the 'needed' indicator may be too pessimistic, but
it didn't seem to me that we have much of a choice.  So, I thought that
if the varpool entry for the decl is already finalized, we can use it.

The other option would be to try and push this analysis much later after
parsing, but that seems fairly intrusive.  I'm currently testing the
attached patch.  Honza, does this make sense at all?

Thanks.
2007-07-26  Diego Novillo  <dnovillo@google.com>

	PR 31899
	* dwarf2out.c (reference_to_unused): Handle VAR_DECLs even if
	not all the cgraph has been built.  Assert that the
	corresponding varpool node has been finalized.

testsuite/ChangeLog

	* g++.dg/debug/31899.C: New test.

Index: testsuite/g++.dg/debug/31899.C
===================================================================
--- testsuite/g++.dg/debug/31899.C	(revision 0)
+++ testsuite/g++.dg/debug/31899.C	(revision 0)
@@ -0,0 +1,8 @@
+// { dg-do compile }
+// { dg-options "-g"
+namespace NS {
+  int x = 0;
+  int &ref = x;
+}
+
+using NS::ref;
Index: dwarf2out.c
===================================================================
--- dwarf2out.c	(revision 126951)
+++ dwarf2out.c	(working copy)
@@ -10300,12 +10300,15 @@ reference_to_unused (tree * tp, int * wa
     return *tp;
   else if (!flag_unit_at_a_time)
     return NULL_TREE;
-  else if (!cgraph_global_info_ready
-	   && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
+  else if (!cgraph_global_info_ready && TREE_CODE (*tp) == FUNCTION_DECL)
     gcc_unreachable ();
   else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL)
     {
       struct varpool_node *node = varpool_node (*tp);
+
+      if (!cgraph_global_info_ready)
+	gcc_assert (node->finalized);
+
       if (!node->needed)
 	return *tp;
     }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]