[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.

llvm-svn: 364061
This commit is contained in:
Alexey Bataev 2019-06-21 15:08:30 +00:00
parent b0ba049f58
commit e0eb66bbff
2 changed files with 8 additions and 4 deletions

View File

@ -1866,11 +1866,14 @@ VarDecl *Sema::isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo,
DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode());
if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind))
return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); 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, DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate,
[](OpenMPDirectiveKind) { return true; }, [](OpenMPDirectiveKind) { return true; },
DSAStack->isClauseParsingMode()); 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 || if (DVarPrivate.CKind != OMPC_unknown ||
(VD && DSAStack->getDefaultDSA() == DSA_none)) (VD && DSAStack->getDefaultDSA() == DSA_none))
return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl());

View File

@ -239,8 +239,8 @@ int main() {
vec[0] = t_var; vec[0] = t_var;
s_arr[0] = var; s_arr[0] = var;
} }
#pragma omp parallel copyin(t_var) #pragma omp parallel copyin(t_var) default(none)
{} ++t_var;
return tmain<int>(); return tmain<int>();
#endif #endif
} }
@ -363,6 +363,7 @@ int main() {
// TLS-CHECK: [[DONE]] // TLS-CHECK: [[DONE]]
// CHECK: call {{.*}}void @__kmpc_barrier(%{{.+}}* [[IMPLICIT_BARRIER_LOC]], i32 [[GTID]]) // CHECK: call {{.*}}void @__kmpc_barrier(%{{.+}}* [[IMPLICIT_BARRIER_LOC]], i32 [[GTID]])
// CHECK: add nsw i32 %{{.+}}, 1
// CHECK: ret void // CHECK: ret void
// TLS-CHECK: [[GTID_ADDR:%.+]] = load i32*, i32** [[GTID_ADDR_ADDR]], // TLS-CHECK: [[GTID_ADDR:%.+]] = load i32*, i32** [[GTID_ADDR_ADDR]],