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]

[committed] Fix diagnostics on invalid collapsed OpenMP loop in C++ (PR c++/41967)


Hi!

On this testcase C++ (C works) after properly diagnosing not perfectly
nested loop for omp collapsed for loop looped forever complaining about
expected }.  The cp_parser_require call was wrong, the } is supposed to be
consumed by next iteration of the loop.  And, if it is CPP_EOF, we have to
stop.

Committed after bootstrap/regtest on x86_64-linux and i686-linux to trunk
and 4.4 branch.

2009-11-06  Jakub Jelinek  <jakub@redhat.com>

	PR c++/41967
	* parser.c (cp_parser_omp_for_loop): After diagnosing not perfectly
	nested loop and parsing statements, don't cp_parser_require }, instead
	exit the loop if next token is CPP_EOF.

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

--- gcc/cp/parser.c.jj	2009-11-06 09:59:57.000000000 +0100
+++ gcc/cp/parser.c	2009-11-06 14:13:36.000000000 +0100
@@ -21614,7 +21614,8 @@ cp_parser_omp_for_loop (cp_parser *parse
 	    }
 	  collapse_err = true;
 	  cp_parser_statement_seq_opt (parser, NULL);
-	  cp_parser_require (parser, CPP_CLOSE_BRACE, "%<}%>");
+	  if (cp_lexer_next_token_is (parser->lexer, CPP_EOF))
+	    break;
 	}
     }
 
--- gcc/testsuite/g++.dg/gomp/pr41967.C.jj	2009-11-06 14:29:55.000000000 +0100
+++ gcc/testsuite/g++.dg/gomp/pr41967.C	2009-11-06 14:28:40.000000000 +0100
@@ -0,0 +1,17 @@
+// PR c++/41967
+// { dg-do compile }
+// { dg-options "-fopenmp" }
+
+int
+foo ()
+{
+  int sum = 0;
+#pragma omp for collapse(2)
+  for (int i = 0; i < 5; ++i)
+    {
+      for (int j = 0; j < 5; ++j)
+	++sum;
+      ++sum;	// { dg-error "collapsed loops not perfectly nested" }
+    }
+  return sum;
+}

	Jakub


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