Index: include/clang/AST/Stmt.h =================================================================== --- include/clang/AST/Stmt.h +++ include/clang/AST/Stmt.h @@ -388,9 +388,11 @@ /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes. Stmt *IgnoreImplicit(); - /// \brief Skip no-op (attributed, compound) container stmts and skip captured - /// stmt at the top, if \a IgnoreCaptured is true. - Stmt *IgnoreContainers(bool IgnoreCaptured = false); + /// \brief Skip no-op (attributed, compound if \a IgnoreCompound is true) + /// container stmts and skip captured stmt at the top, if \a IgnoreCaptured + /// is true. + Stmt *IgnoreContainers(bool IgnoreCaptured = false, + bool IgnoreCompound = true); const Stmt *stripLabelLikeStatements() const; Stmt *stripLabelLikeStatements() { Index: lib/AST/Stmt.cpp =================================================================== --- lib/AST/Stmt.cpp +++ lib/AST/Stmt.cpp @@ -111,9 +111,10 @@ return s; } -/// \brief Skip no-op (attributed, compound) container stmts and skip captured -/// stmt at the top, if \a IgnoreCaptured is true. -Stmt *Stmt::IgnoreContainers(bool IgnoreCaptured) { +/// \brief Skip no-op (attributed, compound if \a IgnoreCompound is true) +/// container stmts and skip captured stmt at the top, if \a IgnoreCaptured +/// is true. +Stmt *Stmt::IgnoreContainers(bool IgnoreCaptured, bool IgnoreCompound) { Stmt *S = this; if (IgnoreCaptured) if (auto CapS = dyn_cast_or_null(S)) @@ -121,10 +122,13 @@ while (true) { if (auto AS = dyn_cast_or_null(S)) S = AS->getSubStmt(); - else if (auto CS = dyn_cast_or_null(S)) { - if (CS->size() != 1) - break; - S = CS->body_back(); + else if (IgnoreCompound) { + if (auto CS = dyn_cast_or_null(S)) { + if (CS->size() != 1) + break; + S = CS->body_back(); + } else + break; } else break; } Index: lib/Sema/SemaOpenMP.cpp =================================================================== --- lib/Sema/SemaOpenMP.cpp +++ lib/Sema/SemaOpenMP.cpp @@ -5133,7 +5133,8 @@ llvm::MapVector Captures; SmallVector IterSpaces; IterSpaces.resize(NestedLoopCount); - Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); + Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true, + /* IgnoreCompound */ false); for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, NestedLoopCount, CollapseLoopCountExpr, 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@+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@+3 {{loop step is expected to be positive due to this condition}} // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}} #pragma omp for