[clang] [clang][OpenMP] Fix teams nesting of region check (PR #94806)
Mike Rice via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 7 14:50:08 PDT 2024
https://github.com/mikerice1969 created https://github.com/llvm/llvm-project/pull/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.
>From 61ea96129753641f7528c0f29c78143a2281cde9 Mon Sep 17 00:00:00 2001
From: Mike Rice <michael.p.rice at intel.com>
Date: Fri, 7 Jun 2024 14:26:37 -0700
Subject: [PATCH] [clang][OpenMP] Fix teams nesting of region check
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.
---
clang/lib/Sema/SemaOpenMP.cpp | 10 +++++++---
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 6e6815328e913..0fe04094c5912 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -13434,10 +13434,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 e671f9b0cf412..969ddfcce4cb0 100644
--- a/clang/test/OpenMP/Inputs/nesting_of_regions.cpp
+++ b/clang/test/OpenMP/Inputs/nesting_of_regions.cpp
@@ -4880,6 +4880,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 // expected-error {{target construct with nested teams region contains statements outside of the teams construct}}
{
while (0) // expected-note {{statement outside teams construct here}}
@@ -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
More information about the cfe-commits
mailing list