]> granicus.if.org Git - clang/commitdiff
[OpenMP] diagnose orphaned teams construct
authorKelvin Li <kkwli0@gmail.com>
Tue, 26 Jul 2016 04:32:50 +0000 (04:32 +0000)
committerKelvin Li <kkwli0@gmail.com>
Tue, 26 Jul 2016 04:32:50 +0000 (04:32 +0000)
The OpenMP spec mandates that 'a teams construct must be contained within a
target construct'. Currently, this scenario is not diagnosed. This patch is
to add check for orphaned teams construct and issue an error message.

Differential Revision: https://reviews.llvm.org/D22785

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276726 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaOpenMP.cpp
test/OpenMP/nesting_of_regions.cpp

index dacc56f86f2be2889327217db3c109004c4aefe5..db827a63f883637dabb2c7d2047c0dedc7a5004d 100644 (file)
@@ -8389,6 +8389,9 @@ def err_omp_argument_type_isdeviceptr : Error <
 def warn_omp_nesting_simd : Warning<
   "OpenMP only allows an ordered construct with the simd clause nested in a simd construct">,
   InGroup<SourceUsesOpenMP>;
+def err_omp_orphaned_device_directive : Error<
+  "orphaned 'omp %0' directives are prohibited"
+  "; perhaps you forget to enclose the directive into a %select{|||target |teams }1region?">;
 } // end of OpenMP category
 
 let CategoryName = "Related Result Type Issue" in {
index 14029e20c3435f8f3b51b55e558cac3d79548cd8..33d10eb9b5621f7075dc04de85bd06eaeb0edace 100644 (file)
@@ -3172,6 +3172,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack,
     auto OffendingRegion = ParentRegion;
     bool NestingProhibited = false;
     bool CloseNesting = true;
+    bool OrphanSeen = false; 
     enum {
       NoRecommend,
       ShouldBeInParallelRegion,
@@ -3213,9 +3214,10 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack,
       }
       return false;
     }
-    // Allow some constructs to be orphaned (they could be used in functions,
-    // called from OpenMP regions with the required preconditions).
-    if (ParentRegion == OMPD_unknown)
+    // Allow some constructs (except teams) to be orphaned (they could be
+    // used in functions, called from OpenMP regions with the required 
+    // preconditions).
+    if (ParentRegion == OMPD_unknown && !isOpenMPTeamsDirective(CurrentRegion))
       return false;
     if (CurrentRegion == OMPD_cancellation_point ||
         CurrentRegion == OMPD_cancel) {
@@ -3315,6 +3317,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack,
       // If specified, a teams construct must be contained within a target
       // construct.
       NestingProhibited = ParentRegion != OMPD_target;
+      OrphanSeen = ParentRegion == OMPD_unknown;
       Recommend = ShouldBeInTargetRegion;
       Stack->setParentTeamsRegionLoc(Stack->getConstructLoc());
     }
@@ -3354,9 +3357,14 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack,
       CloseNesting = false;
     }
     if (NestingProhibited) {
-      SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region)
-          << CloseNesting << getOpenMPDirectiveName(OffendingRegion)
-          << Recommend << getOpenMPDirectiveName(CurrentRegion);
+      if (OrphanSeen) {
+        SemaRef.Diag(StartLoc, diag::err_omp_orphaned_device_directive)
+            << getOpenMPDirectiveName(CurrentRegion) << Recommend;
+      } else {
+        SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region)
+            << CloseNesting << getOpenMPDirectiveName(OffendingRegion)
+            << Recommend << getOpenMPDirectiveName(CurrentRegion);
+      }
       return true;
     }
   }
index 13ef64fc27ea64cb243353f1b3f2c34c24af51e9..6c44d94a67b303aabc41b4818f5f371fa898fc6f 100644 (file)
@@ -3693,6 +3693,8 @@ void foo() {
   }    
 
 // TEAMS DIRECTIVE
+#pragma omp teams // expected-error {{orphaned 'omp teams' directives are prohibited; perhaps you forget to enclose the directive into a target region?}}
+  bar();
 #pragma omp target
 #pragma omp teams
 #pragma omp parallel