Skip to content

Commit b097018

Browse files
authored
[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.
1 parent b1a93db commit b097018

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13433,10 +13433,14 @@ StmtResult SemaOpenMP::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses,
1343313433
auto I = CS->body_begin();
1343413434
while (I != CS->body_end()) {
1343513435
const auto *OED = dyn_cast<OMPExecutableDirective>(*I);
13436-
if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind()) ||
13437-
OMPTeamsFound) {
13438-
13436+
bool IsTeams = OED && isOpenMPTeamsDirective(OED->getDirectiveKind());
13437+
if (!IsTeams || I != CS->body_begin()) {
1343913438
OMPTeamsFound = false;
13439+
if (IsTeams && I != CS->body_begin()) {
13440+
// This is the two teams case. Since the InnerTeamsRegionLoc will
13441+
// point to this second one reset the iterator to the other teams.
13442+
--I;
13443+
}
1344013444
break;
1344113445
}
1344213446
++I;

clang/test/OpenMP/Inputs/nesting_of_regions.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4880,6 +4880,12 @@ void foo() {
48804880
#pragma omp teams // expected-note {{nested teams construct here}}
48814881
++a;
48824882
}
4883+
#pragma omp target // expected-error {{target construct with nested teams region contains statements outside of the teams construct}}
4884+
{
4885+
#pragma omp teams // expected-note {{nested teams construct here}}
4886+
++a;
4887+
++a; // expected-note {{statement outside teams construct here}}
4888+
}
48834889
#pragma omp target // expected-error {{target construct with nested teams region contains statements outside of the teams construct}}
48844890
{
48854891
while (0) // expected-note {{statement outside teams construct here}}
@@ -14133,6 +14139,12 @@ void foo() {
1413314139
#pragma omp teams // expected-note {{nested teams construct here}}
1413414140
++a;
1413514141
}
14142+
#pragma omp target // expected-error {{target construct with nested teams region contains statements outside of the teams construct}}
14143+
{
14144+
#pragma omp teams // expected-note {{nested teams construct here}}
14145+
++a;
14146+
++a; // expected-note {{statement outside teams construct here}}
14147+
}
1413614148
#pragma omp target
1413714149
{
1413814150
#pragma omp taskloop

0 commit comments

Comments
 (0)