From: Alexey Bataev Date: Fri, 21 Jun 2019 15:08:30 +0000 (+0000) Subject: [OPENMP]Fix PR42159: do not capture threadprivate variables. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=49034bc138925640b3b88473f99e27e418d7669b;p=clang [OPENMP]Fix PR42159: do not capture threadprivate variables. 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 --- diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 19057eb398..b531d31c1c 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -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(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(DVarPrivate.PrivateCopy->getDecl()); diff --git a/test/OpenMP/parallel_copyin_codegen.cpp b/test/OpenMP/parallel_copyin_codegen.cpp index 5e056b9ccb..8fa9edd2c1 100644 --- a/test/OpenMP/parallel_copyin_codegen.cpp +++ b/test/OpenMP/parallel_copyin_codegen.cpp @@ -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(); #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]],