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

View: New views
1 Messages — Rating Filter:   Alert me  

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

by Jakub Jelinek :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

        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