]> granicus.if.org Git - clang/commitdiff
[OPENMP] Fix possible assert for target regions with incorrect inner
authorAlexey Bataev <a.bataev@hotmail.com>
Thu, 30 Nov 2017 18:01:54 +0000 (18:01 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Thu, 30 Nov 2017 18:01:54 +0000 (18:01 +0000)
teams region.

If the inner teams region is not correct, it may cause an assertion when
processing outer target region. Patch fixes this problem.

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

lib/Sema/SemaOpenMP.cpp
test/OpenMP/teams_distribute_loop_messages.cpp
test/OpenMP/teams_distribute_parallel_for_messages.cpp
test/OpenMP/teams_distribute_parallel_for_simd_messages.cpp
test/OpenMP/teams_distribute_simd_messages.cpp
test/OpenMP/teams_messages.cpp

index 68497cb2df5dd463a7e33bc7052f6b8d5730fec5..19dffac5f38314f8838d403d3fd5be125873d6dd 100644 (file)
@@ -2674,7 +2674,6 @@ static bool checkNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack,
       NestingProhibited = ParentRegion != OMPD_target;
       OrphanSeen = ParentRegion == OMPD_unknown;
       Recommend = ShouldBeInTargetRegion;
-      Stack->setParentTeamsRegionLoc(Stack->getConstructLoc());
     }
     if (!NestingProhibited &&
         !isOpenMPTargetExecutionDirective(CurrentRegion) &&
@@ -6569,6 +6568,8 @@ StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses,
 
   getCurFunction()->setHasBranchProtectedScope();
 
+  DSAStack->setParentTeamsRegionLoc(StartLoc);
+
   return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt);
 }
 
@@ -7071,6 +7072,9 @@ StmtResult Sema::ActOnOpenMPTeamsDistributeDirective(
          "omp teams distribute loop exprs were not built");
 
   getCurFunction()->setHasBranchProtectedScope();
+
+  DSAStack->setParentTeamsRegionLoc(StartLoc);
+
   return OMPTeamsDistributeDirective::Create(
       Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B);
 }
@@ -7119,6 +7123,9 @@ StmtResult Sema::ActOnOpenMPTeamsDistributeSimdDirective(
     return StmtError();
 
   getCurFunction()->setHasBranchProtectedScope();
+
+  DSAStack->setParentTeamsRegionLoc(StartLoc);
+
   return OMPTeamsDistributeSimdDirective::Create(
       Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B);
 }
@@ -7167,6 +7174,9 @@ StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForSimdDirective(
     return StmtError();
 
   getCurFunction()->setHasBranchProtectedScope();
+
+  DSAStack->setParentTeamsRegionLoc(StartLoc);
+
   return OMPTeamsDistributeParallelForSimdDirective::Create(
       Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B);
 }
@@ -7213,6 +7223,9 @@ StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForDirective(
          "omp for loop exprs were not built");
 
   getCurFunction()->setHasBranchProtectedScope();
+
+  DSAStack->setParentTeamsRegionLoc(StartLoc);
+
   return OMPTeamsDistributeParallelForDirective::Create(
       Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B,
       DSAStack->isCancelRegion());
index ea2604eebf0f8485046f8b05c7f3e9c06e54f745..fcec84e9d3af163bc16301d670a9d956178638ef 100644 (file)
@@ -689,6 +689,9 @@ void test_loop_eh() {
       void g() { throw 0; }
     };
   }
+  #pragma omp target
+  #pragma omp teams distribute
+  f; // expected-error {{use of undeclared identifier 'f'}}
 }
 
 void test_loop_firstprivate_lastprivate() {
index 9b8d756ba3bdc2c9b2deb7dae47c106861d25c79..9843b442e5b47b0acefe0b3dbc1ea8376149a77a 100644 (file)
@@ -9,6 +9,9 @@ static int pvt;
 #pragma omp teams distribute parallel for // expected-error {{unexpected OpenMP directive '#pragma omp teams distribute parallel for'}}
 
 int main(int argc, char **argv) {
+  #pragma omp target
+  #pragma omp teams distribute parallel for
+  f; // expected-error {{use of undeclared identifier 'f'}}
 #pragma omp target
 #pragma omp teams distribute parallel for { // expected-warning {{extra tokens at the end of '#pragma omp teams distribute parallel for' are ignored}}
   for (int i = 0; i < argc; ++i)
index 7876c38980ee1b8ebc9bc6031cc70c013668cf0d..12ac8f9a9479fd48e889f890e449291b7f102c91 100644 (file)
@@ -9,6 +9,9 @@ static int pvt;
 #pragma omp teams distribute parallel for simd // expected-error {{unexpected OpenMP directive '#pragma omp teams distribute parallel for simd'}}
 
 int main(int argc, char **argv) {
+  #pragma omp target
+  #pragma omp teams distribute parallel for simd
+  f; // expected-error {{use of undeclared identifier 'f'}}
 #pragma omp target
 #pragma omp teams distribute parallel for simd { // expected-warning {{extra tokens at the end of '#pragma omp teams distribute parallel for simd' are ignored}}
   for (int i = 0; i < argc; ++i)
index 9095caf387876725293f1429279618a8fde5b011..b00de796b0ed8fa47d2d47735c90dfab33de08a6 100644 (file)
@@ -9,6 +9,9 @@ static int pvt;
 #pragma omp teams distribute simd // expected-error {{unexpected OpenMP directive '#pragma omp teams distribute simd'}}
 
 int main(int argc, char **argv) {
+  #pragma omp target
+  #pragma omp teams distribute simd
+  f; // expected-error {{use of undeclared identifier 'f'}}
 #pragma omp target
 #pragma omp teams distribute simd { // expected-warning {{extra tokens at the end of '#pragma omp teams distribute simd' are ignored}}
   for (int i = 0; i < argc; ++i)
index 3a42a0e8dd6aaf424416ffc2a9668b203ff6195b..642fe73cac75ad2e705b8378011bde1e1dc0ee08 100644 (file)
@@ -6,6 +6,9 @@ void foo() {
 #pragma omp teams // expected-error {{unexpected OpenMP directive '#pragma omp teams'}}
 
 int main(int argc, char **argv) {
+  #pragma omp target
+  #pragma omp teams
+  f; // expected-error {{use of undeclared identifier 'f'}}
   #pragma omp target
   #pragma omp teams { // expected-warning {{extra tokens at the end of '#pragma omp teams' are ignored}}
   foo();