public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] Fix diagnostics on invalid collapsed OpenMP loop in  C++ (PR c++/41967)
@ 2009-11-06 18:12 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2009-11-06 18:12 UTC (permalink / raw)
  To: gcc-patches

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-11-06 17:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-06 18:12 [committed] Fix diagnostics on invalid collapsed OpenMP loop in C++ (PR c++/41967) Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).