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]

Re: [PATCH] PR c++/27574 (PING)


Jason Merrill a écrit :
Seems like this won't solve the problem of wanting to discard the information for unreachable functions.

Please find attached a reworked patch that merges the two previous approaches.
Basically, I flag abstracts functions which clones are live. Then, at function body clearing time, I just prevent the DECL_INITIAL() from being nuked as well.


So the bodies of non live functions are always dropped incurring no text size increase, but we should get the debug info for the abstract functions that are needed.

It passes regtest on trunk for x86_64.

Thanks,

Dodji.
gcc/ChangeLog:
2008-11-04  Dodji Seketeli  <dodji@redhat.com>

	PR debug/27574
	* cgraph.h: New abstract_and_needed member to struct cgraph_node.
	* cgraphunit.c (cgraph_analyze_functions): Flag abstract functions
	- which clones are reachable - as "abstract and needed".
	* cgraph.c (cgraph_release_function_body):  If a node is "abstract and needed",
	do not release its DECL_INITIAL() content because that will be needed to emit
	debug info.

gcc/testsuite/ChangeLog:
2008-11-04  Dodji Seketeli  <dodji@redhat.com>

	PR debug/27574
	* g++.dg/debug/dwarf2/local-var-in-contructor.C: New test.

diff --git a/gcc/cgraph.c b/gcc/cgraph.c
index 73dbfb3..43659cb 100644
--- a/gcc/cgraph.c
+++ b/gcc/cgraph.c
@@ -936,7 +936,11 @@ cgraph_release_function_body (struct cgraph_node *node)
       DECL_STRUCT_FUNCTION (node->decl) = NULL;
     }
   DECL_SAVED_TREE (node->decl) = NULL;
-  DECL_INITIAL (node->decl) = error_mark_node;
+  /* If the node is abstract and needed, then do not clear DECL_INITIAL
+     of its associated function function declaration because it's
+     needed to emit debug info later.  */
+  if (!node->abstract_and_needed)
+    DECL_INITIAL (node->decl) = error_mark_node;
 }
 
 /* Remove the node from cgraph.  */
diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index a6018dc..7825804 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -166,6 +166,9 @@ struct cgraph_node GTY((chain_next ("%h.next"), chain_prev ("%h.previous")))
   /* Set when function must be output - it is externally visible
      or its address is taken.  */
   unsigned needed : 1;
+  /* Set when decl is an abstract function pointed to by the
+     ABSTRACT_DECL_ORIGIN of a reachable function.  */
+  unsigned abstract_and_needed : 1;
   /* Set when function is reachable by call from other function
      that is either reachable or needed.  */
   unsigned reachable : 1;
diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index 7c84573..cd58c2a 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -896,6 +896,15 @@ cgraph_analyze_functions (void)
 	if (!edge->callee->reachable)
 	  cgraph_mark_reachable_node (edge->callee);
 
+      /* If decl is a clone of an abstract function, mark that abstract
+	 function so that we don't release its body. The DECL_INITIAL() of that
+         abstract function declaration will be later needed to output debug info.  */
+      if (DECL_ABSTRACT_ORIGIN (decl))
+	{
+	  struct cgraph_node *origin_node = cgraph_node (DECL_ABSTRACT_ORIGIN (decl));
+	  origin_node->abstract_and_needed = true;
+	}
+
       /* We finalize local static variables during constructing callgraph
          edges.  Process their attributes too.  */
       process_function_and_variable_attributes (first_processed,
diff --git a/gcc/final.c b/gcc/final.c
index e2d9e5a..d007907 100644
--- a/gcc/final.c
+++ b/gcc/final.c
@@ -4187,6 +4187,10 @@ rest_of_handle_final (void)
   timevar_push (TV_SYMOUT);
   (*debug_hooks->function_decl) (current_function_decl);
   timevar_pop (TV_SYMOUT);
+
+  /* Release the blocks that are linked to DECL_INITIAL() to free the memory.  */
+  DECL_INITIAL (current_function_decl) = error_mark_node;
+
   if (DECL_STATIC_CONSTRUCTOR (current_function_decl)
       && targetm.have_ctors_dtors)
     targetm.asm_out.constructor (XEXP (DECL_RTL (current_function_decl), 0),
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/local-var-in-contructor.C b/gcc/testsuite/g++.dg/debug/dwarf2/local-var-in-contructor.C
new file mode 100644
index 0000000..d61d27f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/local-var-in-contructor.C
@@ -0,0 +1,30 @@
+// Contributed by Dodji Seketeli <dodji@redhat.com>
+// Origin PR27574
+// { dg-do compile }
+// { dg-options "-O0 -g" }
+// { dg-final { scan-assembler "problem" } }
+
+void f (int *)
+{
+}
+
+class A
+{
+public:
+ A(int i);
+};
+
+A::A(int i)
+{
+ int *problem = new int(i);
+ f (problem);
+}
+
+int
+main (void)
+{
+  A a (0);
+
+  return 0;
+}
+

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