]> granicus.if.org Git - clang/commitdiff
[OPENMP]Fix PR42159: do not capture threadprivate variables.
authorAlexey Bataev <a.bataev@hotmail.com>
Fri, 21 Jun 2019 15:08:30 +0000 (15:08 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Fri, 21 Jun 2019 15:08:30 +0000 (15:08 +0000)
The threadprivate variables should not be captured in the outlined
regions, otherwise it leads to the compiler crash.

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

lib/Sema/SemaOpenMP.cpp
test/OpenMP/parallel_copyin_codegen.cpp

index 19057eb39863ab9a80d75e7739820fbabf810b06..b531d31c1ca90d5fb5f828810ff9f66d2cd5533f 100644 (file)
@@ -1866,11 +1866,14 @@ VarDecl *Sema::isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo,
         DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode());
     if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind))
       return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl());
+    // Threadprivate variables must not be captured.
+    if (isOpenMPThreadPrivate(DVarPrivate.CKind))
+      return nullptr;
+    // The variable is not private or it is the variable in the directive with
+    // default(none) clause and not used in any clause.
     DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate,
                                    [](OpenMPDirectiveKind) { return true; },
                                    DSAStack->isClauseParsingMode());
-    // The variable is not private or it is the variable in the directive with
-    // default(none) clause and not used in any clause.
     if (DVarPrivate.CKind != OMPC_unknown ||
         (VD && DSAStack->getDefaultDSA() == DSA_none))
       return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl());
index 5e056b9ccb0c1a6447f22a2417fc5211f7396df9..8fa9edd2c1ac579c71299605fd4c59aa2b32da40 100644 (file)
@@ -239,8 +239,8 @@ int main() {
     vec[0] = t_var;
     s_arr[0] = var;
   }
-#pragma omp parallel copyin(t_var)
-  {}
+#pragma omp parallel copyin(t_var) default(none)
+  ++t_var;
   return tmain<int>();
 #endif
 }
@@ -363,6 +363,7 @@ int main() {
 // TLS-CHECK: [[DONE]]
 
 // CHECK: call {{.*}}void @__kmpc_barrier(%{{.+}}* [[IMPLICIT_BARRIER_LOC]], i32 [[GTID]])
+// CHECK: add nsw i32 %{{.+}}, 1
 // CHECK: ret void
 
 // TLS-CHECK: [[GTID_ADDR:%.+]] = load i32*, i32** [[GTID_ADDR_ADDR]],