[PATCH] Robustify #pragma omp for parsing (PR c++/34607)

Jakub Jelinek jakub@redhat.com
Tue Jan 22 17:53:00 GMT 2008


Hi!

This patch robustifies #pragma omp for parsing, both C and C++ frontends
ICEd on the attached testcases.

Regtested on x86_64-linux, ok for trunk?

2007-08-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.

	* 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.

--- gcc/c-parser.c.jj	2007-12-17 10:04:14.000000000 +0100
+++ gcc/c-parser.c	2008-01-22 16:17:37.000000000 +0100
@@ -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);
--- gcc/cp/semantics.c.jj	2008-01-19 16:46:14.000000000 +0100
+++ gcc/cp/semantics.c	2008-01-22 16:35:41.000000000 +0100
@@ -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 d
 	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))
--- gcc/testsuite/gcc.dg/gomp/pr34607.c.jj	2008-01-22 16:39:20.000000000 +0100
+++ gcc/testsuite/gcc.dg/gomp/pr34607.c	2008-01-22 16:48:50.000000000 +0100
@@ -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" } */
+    ;
+}
--- gcc/testsuite/g++.dg/gomp/pr34607.C.jj	2008-01-22 16:39:00.000000000 +0100
+++ gcc/testsuite/g++.dg/gomp/pr34607.C	2008-01-22 16:51:23.000000000 +0100
@@ -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" }
+}

	Jakub



More information about the Gcc-patches mailing list