r273908 - [OpenMP] Diagnose missing cases of statements between target and teams directives

Kelvin Li via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 27 12:15:43 PDT 2016


Author: kli
Date: Mon Jun 27 14:15:43 2016
New Revision: 273908

URL: http://llvm.org/viewvc/llvm-project?rev=273908&view=rev
Log:
[OpenMP] Diagnose missing cases of statements between target and teams directives

Clang fails to diagnose cases such as
#pragma omp target
  while(0) {
    #pragma omp teams
    {}
  }

A patch by David Sheinkman.


Modified:
    cfe/trunk/lib/Sema/SemaOpenMP.cpp
    cfe/trunk/test/OpenMP/nesting_of_regions.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=273908&r1=273907&r2=273908&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Mon Jun 27 14:15:43 2016
@@ -6537,6 +6537,9 @@ StmtResult Sema::ActOnOpenMPTargetDirect
       }
       assert(I != CS->body_end() && "Not found statement");
       S = *I;
+    } else {
+      auto *OED = dyn_cast<OMPExecutableDirective>(S);
+      OMPTeamsFound = OED && isOpenMPTeamsDirective(OED->getDirectiveKind());
     }
     if (!OMPTeamsFound) {
       Diag(StartLoc, diag::err_omp_target_contains_not_only_teams);

Modified: cfe/trunk/test/OpenMP/nesting_of_regions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nesting_of_regions.cpp?rev=273908&r1=273907&r2=273908&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/nesting_of_regions.cpp (original)
+++ cfe/trunk/test/OpenMP/nesting_of_regions.cpp Mon Jun 27 14:15:43 2016
@@ -2960,6 +2960,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}}
+  {
+    while (0)      // expected-note {{statement outside teams construct here}}
+#pragma omp teams  // expected-note {{nested teams construct here}}
+    ++a;
+  }
 #pragma omp target
   {
 #pragma omp taskloop




More information about the cfe-commits mailing list