diff options
author | Mike Rice <michael.p.rice@intel.com> | 2024-06-24 13:31:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-24 13:31:39 -0700 |
commit | b097018fdafe61f1fe10337a71f56e5386930d54 (patch) | |
tree | 44efe113a2c4736cd4060b285d88387af66513a1 | |
parent | b1a93dbaba87119556c1138b64cde6aa5ee8a854 (diff) | |
download | llvm-b097018fdafe61f1fe10337a71f56e5386930d54.zip llvm-b097018fdafe61f1fe10337a71f56e5386930d54.tar.gz llvm-b097018fdafe61f1fe10337a71f56e5386930d54.tar.bz2 |
[clang][OpenMP] Fix teams nesting of region check (#94806)
The static verifier flagged dead code in the check since the loop will
only execute once and never reach the iterator increment.
The loop needs to iterate twice to correctly diagnose when a statement
is after the teams.
Since there are two iterations again, reset the iterator to the first
teams directive when the double teams case is seen so the diagnostic can
report both locations.
-rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 10 | ||||
-rw-r--r-- | clang/test/OpenMP/Inputs/nesting_of_regions.cpp | 12 |
2 files changed, 19 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 5c759ae..7697246 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -13433,10 +13433,14 @@ StmtResult SemaOpenMP::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, auto I = CS->body_begin(); while (I != CS->body_end()) { const auto *OED = dyn_cast<OMPExecutableDirective>(*I); - if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind()) || - OMPTeamsFound) { - + bool IsTeams = OED && isOpenMPTeamsDirective(OED->getDirectiveKind()); + if (!IsTeams || I != CS->body_begin()) { OMPTeamsFound = false; + if (IsTeams && I != CS->body_begin()) { + // This is the two teams case. Since the InnerTeamsRegionLoc will + // point to this second one reset the iterator to the other teams. + --I; + } break; } ++I; diff --git a/clang/test/OpenMP/Inputs/nesting_of_regions.cpp b/clang/test/OpenMP/Inputs/nesting_of_regions.cpp index e671f9b..969ddfc 100644 --- a/clang/test/OpenMP/Inputs/nesting_of_regions.cpp +++ b/clang/test/OpenMP/Inputs/nesting_of_regions.cpp @@ -4882,6 +4882,12 @@ void foo() { } #pragma omp target // expected-error {{target construct with nested teams region contains statements outside of the teams construct}} { +#pragma omp teams // expected-note {{nested teams construct here}} + ++a; + ++a; // expected-note {{statement outside teams construct here}} + } +#pragma omp target // expected-error {{target construct with nested teams region contains statements outside of the teams construct}} + { while (0) // expected-note {{statement outside teams construct here}} #pragma omp teams // expected-note {{nested teams construct here}} ++a; @@ -14133,6 +14139,12 @@ void foo() { #pragma omp teams // expected-note {{nested teams construct here}} ++a; } +#pragma omp target // expected-error {{target construct with nested teams region contains statements outside of the teams construct}} + { +#pragma omp teams // expected-note {{nested teams construct here}} + ++a; + ++a; // expected-note {{statement outside teams construct here}} + } #pragma omp target { #pragma omp taskloop |