[clang] b097018 - [clang][OpenMP] Fix teams nesting of region check (#94806)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 24 13:31:42 PDT 2024


Author: Mike Rice
Date: 2024-06-24T13:31:39-07:00
New Revision: b097018fdafe61f1fe10337a71f56e5386930d54

URL: https://github.com/llvm/llvm-project/commit/b097018fdafe61f1fe10337a71f56e5386930d54
DIFF: https://github.com/llvm/llvm-project/commit/b097018fdafe61f1fe10337a71f56e5386930d54.diff

LOG: [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.

Added: 
    

Modified: 
    clang/lib/Sema/SemaOpenMP.cpp
    clang/test/OpenMP/Inputs/nesting_of_regions.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 5c759aedf9798..7697246ea5e59 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 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