re PR c/67502 (ICE with collapsed for simd loop inside of parallel)
authorJakub Jelinek <jakub@redhat.com>
Thu, 10 Sep 2015 07:28:27 +0000 (09:28 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 10 Sep 2015 07:28:27 +0000 (09:28 +0200)
PR c/67502
* c-parser.c (c_parser_omp_for_loop): Emit DECL_EXPR stmts
into OMP_FOR_PRE_BODY rather than before the loop.

* c-c++-common/gomp/pr67502.c: New test.

From-SVN: r227605

gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/gomp/pr67502.c [new file with mode: 0644]

index d7eeb2da4e4bc175f1342d5b6dd074f14599d58b..cfc20aa3b5f0699ef8c18bc6ebdba26af4d54af5 100644 (file)
@@ -1,3 +1,9 @@
+2015-09-10  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/67502
+       * c-parser.c (c_parser_omp_for_loop): Emit DECL_EXPR stmts
+       into OMP_FOR_PRE_BODY rather than before the loop.
+
 2015-09-09  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/67501
index 072f94b89151fe1e1391d3e526063558dc8e7526..4d9cbe050273a20d2bd917b3cf28f87c39d1e267 100644 (file)
@@ -12869,7 +12869,8 @@ c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
                       tree clauses, tree *cclauses)
 {
   tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl;
-  tree declv, condv, incrv, initv, ret = NULL;
+  tree declv, condv, incrv, initv, ret = NULL_TREE;
+  tree pre_body = NULL_TREE, this_pre_body;
   bool fail = false, open_brace_parsed = false;
   int i, collapse = 1, nbraces = 0;
   location_t for_loc;
@@ -12913,8 +12914,23 @@ c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
        {
          if (i > 0)
            vec_safe_push (for_block, c_begin_compound_stmt (true));
+         this_pre_body = push_stmt_list ();
          c_parser_declaration_or_fndef (parser, true, true, true, true, true,
                                         NULL, vNULL);
+         if (this_pre_body)
+           {
+             this_pre_body = pop_stmt_list (this_pre_body);
+             if (pre_body)
+               {
+                 tree t = pre_body;   
+                 pre_body = push_stmt_list ();
+                 add_stmt (t);
+                 add_stmt (this_pre_body);
+                 pre_body = pop_stmt_list (pre_body);
+               }
+             else
+               pre_body = this_pre_body;
+           }
          decl = check_for_loop_decls (for_loc, flag_isoc99);
          if (decl == NULL)
            goto error_init;
@@ -13109,7 +13125,7 @@ c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
   if (!fail)
     {
       stmt = c_finish_omp_for (loc, code, declv, initv, condv,
-                              incrv, body, NULL);
+                              incrv, body, pre_body);
       if (stmt)
        {
          if (cclauses != NULL
index dbf06c64a15297f9aef5e39bb8af7fbdc8cbf213..140766d3ef736a112bc8d4b97d6c3991f2279836 100644 (file)
@@ -1,3 +1,8 @@
+2015-09-10  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/67502
+       * c-c++-common/gomp/pr67502.c: New test.
+
 2015-09-09  Marek Polacek  <polacek@redhat.com>
 
        PR middle-end/67512
diff --git a/gcc/testsuite/c-c++-common/gomp/pr67502.c b/gcc/testsuite/c-c++-common/gomp/pr67502.c
new file mode 100644 (file)
index 0000000..74fef4d
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR c/67502 */
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+/* { dg-additional-options "-std=c99" { target c } } */
+
+void bar (int, int);
+
+void
+foo (void)
+{
+#pragma omp parallel
+#pragma omp for simd collapse(2)
+  for (int i = 0; i < 16; ++i)
+    for (int j = 0; j < 16; ++j)
+      bar (i, j);
+}