re PR c++/34607 (ICE with invalid for loop after #pragma omp for)
authorJakub Jelinek <jakub@redhat.com>
Tue, 22 Jan 2008 17:25:37 +0000 (18:25 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 22 Jan 2008 17:25:37 +0000 (18:25 +0100)
PR c++/34607
* c-parser.c (c_parser_omp_for_loop): Don't call c_finish_omp_for
if DECL_INITIAL (decl) is error_mark_node.

* semantics.c (finish_omp_for): Don't call c_finish_omp_for
if decl or init is error_mark_node.

* gcc.dg/gomp/pr34607.c: New test.
* g++.dg/gomp/pr34607.C: New test.

From-SVN: r131730

gcc/ChangeLog
gcc/c-parser.c
gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/gomp/pr34607.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/gomp/pr34607.c [new file with mode: 0644]

index a428833..2f80c36 100644 (file)
@@ -1,5 +1,9 @@
 2008-01-22  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/34607
+       * c-parser.c (c_parser_omp_for_loop): Don't call c_finish_omp_for
+       if DECL_INITIAL (decl) is error_mark_node.
+
        PR c++/34914
        * c-common.c (handle_vector_size_attribute): Only allow
        integral, scalar float and fixed point types.  Handle OFFSET_TYPE
index 107b114..72f8a21 100644 (file)
@@ -7547,6 +7547,8 @@ c_parser_omp_for_loop (c_parser *parser)
       decl = check_for_loop_decls ();
       if (decl == NULL)
        goto error_init;
+      if (DECL_INITIAL (decl) == error_mark_node)
+       decl = error_mark_node;
       init = decl;
     }
   else if (c_parser_next_token_is (parser, CPP_NAME)
@@ -7597,7 +7599,7 @@ c_parser_omp_for_loop (c_parser *parser)
   c_break_label = save_break;
   c_cont_label = save_cont;
 
-  /* Only bother calling c_finish_omp_for if we havn't already generated
+  /* Only bother calling c_finish_omp_for if we haven't already generated
      an error from the initialization parsing.  */
   if (decl != NULL && decl != error_mark_node && init != error_mark_node)
     return c_finish_omp_for (loc, decl, init, cond, incr, body, NULL);
index b039b37..eab41cf 100644 (file)
@@ -1,5 +1,9 @@
 2008-01-22  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/34607
+       * semantics.c (finish_omp_for): Don't call c_finish_omp_for
+       if decl or init is error_mark_node.
+
        PR c++/34918
        * error.c (dump_expr): Handle VECTOR_CST.
 
index 8cf9ceb..5afc701 100644 (file)
@@ -3827,7 +3827,7 @@ tree
 finish_omp_for (location_t locus, tree decl, tree init, tree cond,
                tree incr, tree body, tree pre_body)
 {
-  tree omp_for;
+  tree omp_for = NULL;
 
   if (decl == NULL)
     {
@@ -3919,7 +3919,8 @@ finish_omp_for (location_t locus, tree decl, tree init, tree cond,
        TREE_OPERAND (cond, n)
          = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
     }
-  omp_for = c_finish_omp_for (locus, decl, init, cond, incr, body, pre_body);
+  if (decl != error_mark_node && init != error_mark_node)
+    omp_for = c_finish_omp_for (locus, decl, init, cond, incr, body, pre_body);
   if (omp_for != NULL
       && TREE_CODE (OMP_FOR_INCR (omp_for)) == MODIFY_EXPR
       && TREE_SIDE_EFFECTS (TREE_OPERAND (OMP_FOR_INCR (omp_for), 1))
index aae550a..ab1f6b8 100644 (file)
@@ -1,5 +1,9 @@
 2008-01-22  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/34607
+       * gcc.dg/gomp/pr34607.c: New test.
+       * g++.dg/gomp/pr34607.C: New test.
+
        PR c++/34914
        * g++.dg/ext/vector10.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/gomp/pr34607.C b/gcc/testsuite/g++.dg/gomp/pr34607.C
new file mode 100644 (file)
index 0000000..1dbba4a
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/34607
+// { dg-do compile }
+// { dg-options "-fopenmp" }
+
+void
+foo ()
+{
+#pragma omp for
+  for (int i =; i < 2; ++i)    // { dg-error "expected primary-expression" }
+    ;
+#pragma omp for
+  for (T i = 54; i < 56; i++)  // { dg-error "was not declared|expected" }
+    ;
+  T j;                         // { dg-error "was not declared|expected" }
+#pragma omp for
+  for (j = 1; j < 3; j++)      // { dg-error "was not declared" }
+    ;                          // { dg-error "expected" }
+}
diff --git a/gcc/testsuite/gcc.dg/gomp/pr34607.c b/gcc/testsuite/gcc.dg/gomp/pr34607.c
new file mode 100644 (file)
index 0000000..1b96099
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR c++/34607 */
+/* { dg-do compile } */
+/* { dg-options "-fopenmp -std=gnu99" } */
+
+void
+foo ()
+{
+#pragma omp for
+  for (int i =; i < 2; ++i)    /* { dg-error "expected expression before" } */
+    ;
+#pragma omp for
+  for (T i = 54; i < 56; i++)  /* { dg-error "expected iteration declaration" } */
+    ;
+  T j;                         /* { dg-error "undeclared|for each function|expected" } */
+#pragma omp for
+  for (j = 1; j < 3; j++)      /* { dg-error "undeclared" } */
+    ;
+}