File gcc43-pr37189.patch of Package gcc43

2008-09-03  Jakub Jelinek  <jakub@redhat.com>

	PR c++/37189
	* cp-tree.h (defer_mark_used_calls, deferred_mark_used_calls): New
	extern decls.
	* decl2.c (mark_used): If defer_mark_used_calls, push decl into
	deferred_mark_used_calls vector and exit early.
	* decl.c (defer_mark_used_calls, deferred_mark_used_calls): New
	variables.
	(finish_function): Set defer_mark_used_calls for the duration of the
	function.  Call mark_used on any queued decls.

	PR c++/37189
	* g++.dg/gomp/pr37189.C: New test.

Index: gcc/cp/decl2.c
===================================================================
--- gcc/cp/decl2.c.orig	2009-09-21 11:42:17.000000000 +0200
+++ gcc/cp/decl2.c	2009-09-21 11:44:36.000000000 +0200
@@ -3745,6 +3745,15 @@ mark_used (tree decl)
   /* If we don't need a value, then we don't need to synthesize DECL.  */
   if (skip_evaluation)
     return;
+
+  /* If within finish_function, defer the rest until that function
+     finishes, otherwise it might recurse.  */
+  if (defer_mark_used_calls)
+    {
+      VEC_safe_push (tree, gc, deferred_mark_used_calls, decl);
+      return;
+    }
+
   /* Normally, we can wait until instantiation-time to synthesize
      DECL.  However, if DECL is a static data member initialized with
      a constant, we need the value right now because a reference to
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c.orig	2009-09-21 11:44:13.000000000 +0200
+++ gcc/cp/decl.c	2009-09-21 11:44:36.000000000 +0200
@@ -227,6 +227,11 @@ struct named_label_entry GTY(())
    function, two inside the body of a function in a local class, etc.)  */
 int function_depth;
 
+/* To avoid unwanted recursion, finish_function defers all mark_used calls
+   encountered during its execution until it finishes.  */
+bool defer_mark_used_calls;
+VEC(tree, gc) *deferred_mark_used_calls;
+
 /* States indicating how grokdeclarator() should handle declspecs marked
    with __attribute__((deprecated)).  An object declared as
    __attribute__((deprecated)) suppresses warnings of uses of other
@@ -11788,6 +11793,9 @@ finish_function (int flags)
   if (fndecl == NULL_TREE)
     return error_mark_node;
 
+  gcc_assert (!defer_mark_used_calls);
+  defer_mark_used_calls = true;
+
   if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fndecl)
       && DECL_VIRTUAL_P (fndecl)
       && !processing_template_decl)
@@ -11989,6 +11997,17 @@ finish_function (int flags)
        cxx_pop_function_context and then reset via pop_function_context.  */
     current_function_decl = NULL_TREE;
 
+  defer_mark_used_calls = false;
+  if (deferred_mark_used_calls)
+    {
+      unsigned int i;
+      tree decl;
+
+      for (i = 0; VEC_iterate (tree, deferred_mark_used_calls, i, decl); i++)
+	mark_used (decl);
+      VEC_free (tree, gc, deferred_mark_used_calls);
+    }
+
   return fndecl;
 }
 
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h.orig	2009-09-21 11:42:17.000000000 +0200
+++ gcc/cp/cp-tree.h	2009-09-21 11:44:36.000000000 +0200
@@ -4270,6 +4270,9 @@ extern void initialize_artificial_var		(
 extern tree check_var_type			(tree, tree);
 extern tree reshape_init (tree, tree);
 
+extern bool defer_mark_used_calls;
+extern GTY(()) VEC(tree, gc) *deferred_mark_used_calls;
+
 /* in decl2.c */
 extern bool check_java_method			(tree);
 extern tree build_memfn_type			(tree, tree, cp_cv_quals);
Index: gcc/testsuite/g++.dg/gomp/pr37189.C
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/g++.dg/gomp/pr37189.C	2009-09-21 11:44:36.000000000 +0200
@@ -0,0 +1,27 @@
+// PR c++/37189
+// { dg-do compile }
+// { dg-options "-fopenmp" }
+
+struct S
+{
+  S () {}
+  S (S const &) {}
+};
+
+struct T
+{
+  S s;
+};
+
+void
+bar (T &)
+{
+}
+
+int
+foo ()
+{
+  T t;
+  #pragma omp task
+    bar (t);
+}