[PATCH] D24615: [OpenMP] clang doesnt diagnose if there is a lexical block around a for stmt for OpenMP loops. It is technically not allowed in the OpenMP standard

David Sheinkman via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 15 10:15:05 PDT 2016


davidsh created this revision.
davidsh added reviewers: carlo.bertolli, arpith-jacob, kkwli0, sfantao, ABataev.
davidsh added a subscriber: cfe-commits.


#pragma omp for
{
for(...)
}

This is technically not allowed by the standard, gcc doesnt allow such code.


https://reviews.llvm.org/D24615

Files:
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/for_loop_messages.cpp

Index: test/OpenMP/for_loop_messages.cpp
===================================================================
--- test/OpenMP/for_loop_messages.cpp
+++ test/OpenMP/for_loop_messages.cpp
@@ -353,6 +353,14 @@
   }
 
 #pragma omp parallel
+// expected-error at +2 {{statement after '#pragma omp for' must be a for loop}}
+#pragma omp for
+  {
+  for (int i = 0; i < 16; ++i)
+    ;
+  }
+
+#pragma omp parallel
 // expected-note at +3 {{loop step is expected to be positive due to this condition}}
 // expected-error at +2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}
 #pragma omp for
Index: lib/Sema/SemaOpenMP.cpp
===================================================================
--- lib/Sema/SemaOpenMP.cpp
+++ lib/Sema/SemaOpenMP.cpp
@@ -5133,7 +5133,9 @@
   llvm::MapVector<Expr *, DeclRefExpr *> Captures;
   SmallVector<LoopIterationSpace, 4> IterSpaces;
   IterSpaces.resize(NestedLoopCount);
-  Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true);
+  Stmt *CurStmt = AStmt;
+  if (auto CapS = dyn_cast_or_null<CapturedStmt>(CurStmt))
+    CurStmt = CapS->getCapturedStmt();
   for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) {
     if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt,
                                   NestedLoopCount, CollapseLoopCountExpr,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24615.71512.patch
Type: text/x-patch
Size: 1334 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160915/baff6a79/attachment.bin>


More information about the cfe-commits mailing list