Hi!

In PR69315, we've recently allowed recursive genericization, unfortunately
the bc_label handling isn't prepared for that, we ICE if we cp_genericize
some function (usually newly instantiated method) while inside of some loop
in the outer function.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk/6.2?

2016-07-20  Jakub Jelinek  <ja...@redhat.com>

        PR c++/71941
        * cp-gimplify.c (cp_genericize): For nested cp_genericize calls
        save/restore bc_label array.

        * g++.dg/gomp/pr71941.C: New test.

--- gcc/cp/cp-gimplify.c.jj     2016-07-18 20:44:59.000000000 +0200
+++ gcc/cp/cp-gimplify.c        2016-07-20 12:14:28.203381211 +0200
@@ -1632,6 +1632,13 @@ cp_genericize (tree fndecl)
   if (DECL_CLONED_FUNCTION_P (fndecl))
     return;
 
+  /* Allow cp_genericize calls to be nested.  */
+  tree save_bc_label[2];
+  save_bc_label[bc_break] = bc_label[bc_break];
+  save_bc_label[bc_continue] = bc_label[bc_continue];
+  bc_label[bc_break] = NULL_TREE;
+  bc_label[bc_continue] = NULL_TREE;
+
   /* Expand all the array notations here.  */
   if (flag_cilkplus 
       && contains_array_notation_expr (DECL_SAVED_TREE (fndecl)))
@@ -1651,6 +1658,8 @@ cp_genericize (tree fndecl)
 
   gcc_assert (bc_label[bc_break] == NULL);
   gcc_assert (bc_label[bc_continue] == NULL);
+  bc_label[bc_break] = save_bc_label[bc_break];
+  bc_label[bc_continue] = save_bc_label[bc_continue];
 }
 
 /* Build code to apply FN to each member of ARG1 and ARG2.  FN may be
--- gcc/testsuite/g++.dg/gomp/pr71941.C.jj      2016-07-20 12:11:29.793638764 
+0200
+++ gcc/testsuite/g++.dg/gomp/pr71941.C 2016-07-20 12:11:14.000000000 +0200
@@ -0,0 +1,22 @@
+// PR c++/71941
+// { dg-do compile }
+// { dg-options "-fopenmp" }
+
+struct A { A (); A (A &); ~A (); };
+
+template <int N>
+struct B
+{
+  struct C { A a; C () : a () {} };
+  C c;
+  void foo ();
+};
+
+void
+bar ()
+{
+  B<0> b;
+#pragma omp task
+  for (int i = 0; i < 2; i++)
+    b.foo ();
+}

        Jakub

Reply via email to