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: C++ PATCH for c++/41119, 41120


On 08/19/2009 01:25 PM, Jason Merrill wrote:
Synthesizing in the middle of a default argument was problematic because
we don't want to run the garbage collector in the middle of overload
resolution, because the overload candidates aren't marked for GC.
cp_parser_default_argument dealt with this by setting function_depth
around parsing of the default argument, but that didn't cover the case
of synthesizing for initializing a namespace-scope variable. But if
synthesis is the problem, we should set function_depth while
synthesizing, not around the larger scope.

Tested x86_64-pc-linux-gnu, applied to trunk.

2009-08-19  Jason Merrill  <jason@redhat.com>

	PR c++/41119
	PR c++/41120
	* decl2.c (mark_used): Increment function_depth during synthesis.
	* parser.c (cp_parser_default_argument): Not here.

diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index e4ed963..225cd9d 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -3948,7 +3948,16 @@ mark_used (tree decl)
       && !DECL_THUNK_P (decl)
       && ! DECL_INITIAL (decl))
     {
+      /* Synthesizing an implicitly defined member function will result in
+	 garbage collection.  We must treat this situation as if we were
+	 within the body of a function so as to avoid collecting live data
+	 on the stack (such as overload resolution candidates).
+
+         ??? Now that inlining is done unit-at-a-time, we ought to defer
+         synthesis like we do templates.  */
+      ++function_depth;
       synthesize_method (decl);
+      --function_depth;
       /* If we've already synthesized the method we don't need to
 	 do the instantiation test below.  */
     }
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index e64d0bf..a3e9f0e 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -14615,12 +14615,6 @@ cp_parser_default_argument (cp_parser *parser, bool template_parm_p)
      appear in a default argument.  */
   saved_local_variables_forbidden_p = parser->local_variables_forbidden_p;
   parser->local_variables_forbidden_p = true;
-  /* The default argument expression may cause implicitly
-     defined member functions to be synthesized, which will
-     result in garbage collection.  We must treat this
-     situation as if we were within the body of function so as
-     to avoid collecting live data on the stack.  */
-  ++function_depth;
   /* Parse the assignment-expression.  */
   if (template_parm_p)
     push_deferring_access_checks (dk_no_deferred);
@@ -14628,8 +14622,6 @@ cp_parser_default_argument (cp_parser *parser, bool template_parm_p)
     = cp_parser_assignment_expression (parser, /*cast_p=*/false, NULL);
   if (template_parm_p)
     pop_deferring_access_checks ();
-  /* Restore saved state.  */
-  --function_depth;
   parser->greater_than_is_operator_p = saved_greater_than_is_operator_p;
   parser->local_variables_forbidden_p = saved_local_variables_forbidden_p;
 
diff --git a/gcc/testsuite/g++.dg/other/gc4.C b/gcc/testsuite/g++.dg/other/gc4.C
new file mode 100644
index 0000000..50c16b3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/gc4.C
@@ -0,0 +1,14 @@
+// PR c++/41120
+// { dg-options "--param ggc-min-heapsize=0 --param ggc-min-expand=0" }
+
+struct A
+{
+  A();
+};
+
+struct B
+{
+  A a;
+};
+
+B b;

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