This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gomp] Fix C ICE on invalid OMP for (PR c/25996)


Hi!

The C parser returns error_mark_nodes for errorneous expressions rather than
NULL (as the C++ parser seems to do).  c_finish_omp_for is certainly not
prepared to handle error_mark_node in decl or init arguments (but handles
error_mark_node cond or incr just fine).

Ok for trunk?

2006-04-19  Jakub Jelinek  <jakub@redhat.com>

	PR c/25996
	* c-parser.c (c_parser_omp_for_loop): Don't call c_finish_omp_for if
	either decl or init is error_mark_node.

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

--- gcc/c-parser.c.jj	2006-04-11 09:09:50.000000000 +0200
+++ gcc/c-parser.c	2006-04-19 11:44:30.000000000 +0200
@@ -7379,7 +7379,7 @@ c_parser_omp_for_loop (c_parser *parser)
 
   /* Only bother calling c_finish_omp_for if we havn't already generated
      an error from the initialization parsing.  */
-  if (decl != NULL)
+  if (decl != NULL && decl != error_mark_node && init != error_mark_node)
     return c_finish_omp_for (loc, decl, init, cond, incr, body, NULL);
   return NULL;
 
--- gcc/testsuite/gcc.dg/gomp/pr25996.c.jj	2006-04-19 11:46:59.000000000 +0200
+++ gcc/testsuite/gcc.dg/gomp/pr25996.c	2006-04-19 11:49:26.000000000 +0200
@@ -0,0 +1,32 @@
+/* PR c/25996 */
+
+void
+test1 (void)
+{
+#pragma omp for
+  for (i = 0; i < 1; ++i); /* { dg-error "undeclared|for each function" } */
+}
+
+void
+test2 (void)
+{
+  int i;
+#pragma omp for
+  for (i = j; i < 1; ++i); /* { dg-error "undeclared" } */
+}
+
+void
+test3 (void)
+{
+  int i;
+#pragma omp for
+  for (i = 0; i < j; ++i); /* { dg-error "undeclared|invalid controlling predicate" } */
+}
+
+void
+test4 (void)
+{
+  int i;
+#pragma omp for
+  for (i = 0; i < 10; i += j); /* { dg-error "undeclared|invalid increment expression" } */
+}
--- gcc/testsuite/g++.dg/gomp/pr25996.C.jj	2006-04-19 11:50:51.000000000 +0200
+++ gcc/testsuite/g++.dg/gomp/pr25996.C	2006-04-19 11:53:41.000000000 +0200
@@ -0,0 +1,32 @@
+// PR c/25996
+
+void
+test1 (void)
+{
+#pragma omp for
+  for (i = 0; i < 1; ++i); // { dg-error "not declared|expected iteration decl" }
+}
+
+void
+test2 (void)
+{
+  int i;
+#pragma omp for
+  for (i = j; i < 1; ++i); // { dg-error "not declared|expected iteration decl" }
+}
+
+void
+test3 (void)
+{
+  int i;
+#pragma omp for
+  for (i = 0; i < j; ++i); // { dg-error "not declared|invalid controlling predicate" }
+}
+
+void
+test4 (void)
+{
+  int i;
+#pragma omp for
+  for (i = 0; i < 10; i += j); // { dg-error "not declared|invalid increment expression" }
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]