Skip to content

Commit 0c99d19

Browse files
committed
[OPENMP]Fix sharing of threadprivate variables with TLS support.
If the threadprivate variable is used in the copyin clause on inner parallel directive with TLS support, we capture this variable in all outer OpenMP scopes. It leads to the fact that in all scopes we're working with the original variable, not the threadprivate copies. llvm-svn: 366483
1 parent 892758a commit 0c99d19

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

clang/lib/Sema/SemaOpenMP.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,13 @@ bool Sema::isOpenMPPrivateDecl(const ValueDecl *D, unsigned Level) const {
18821882
!isOpenMPSimdDirective(DSAStack->getCurrentDirective()))
18831883
return true;
18841884
}
1885+
if (const auto *VD = dyn_cast<VarDecl>(D)) {
1886+
if (DSAStack->isThreadPrivate(const_cast<VarDecl *>(VD)) &&
1887+
DSAStack->isForceVarCapturing() &&
1888+
!DSAStack->hasExplicitDSA(
1889+
D, [](OpenMPClauseKind K) { return K == OMPC_copyin; }, Level))
1890+
return true;
1891+
}
18851892
return DSAStack->hasExplicitDSA(
18861893
D, [](OpenMPClauseKind K) { return K == OMPC_private; }, Level) ||
18871894
(DSAStack->isClauseParsingMode() &&

clang/test/OpenMP/parallel_copyin_codegen.cpp

+23-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// RUN: %clang_cc1 -verify -fopenmp -x c++ -std=c++11 -DLAMBDA -triple x86_64-linux -emit-llvm %s -o - | FileCheck -check-prefix=TLS-LAMBDA %s
2020
// RUN: %clang_cc1 -verify -fopenmp -x c++ -fblocks -DBLOCKS -triple x86_64-linux -emit-llvm %s -o - | FileCheck -check-prefix=TLS-BLOCKS %s
2121
// RUN: %clang_cc1 -verify -fopenmp -x c++ -std=c++11 -DARRAY -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck -check-prefix=TLS-ARRAY %s
22+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -DNESTED -triple x86_64-linux -emit-llvm %s -o - | FileCheck %s -check-prefix=NESTED
2223

2324
// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-linux -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY1 %s
2425
// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-linux -emit-pch -o %t %s
@@ -28,7 +29,7 @@
2829
// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -std=c++11 -DARRAY -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY1 %s
2930
// SIMD-ONLY1-NOT: {{__kmpc|__tgt}}
3031
// expected-no-diagnostics
31-
#ifndef ARRAY
32+
#if !defined(ARRAY) && !defined(NESTED)
3233
#ifndef HEADER
3334
#define HEADER
3435

@@ -493,7 +494,7 @@ int main() {
493494
// TLS-CHECK: ret void
494495

495496
#endif
496-
#else
497+
#elif defined(ARRAY)
497498
// ARRAY-LABEL: array_func
498499
// TLS-ARRAY-LABEL: array_func
499500

@@ -522,6 +523,24 @@ void array_func() {
522523
#pragma omp parallel copyin(a, s)
523524
;
524525
}
525-
#endif
526-
526+
#elif defined(NESTED)
527+
int t;
528+
#pragma omp threadprivate(t)
529+
// NESTED: foo
530+
void foo() {
531+
// NESTED: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @{{.+}}, i32 0, void (i32*, i32*, ...)* bitcast (void (i32*, i32*)* [[OUTLINED:@.+]] to void (i32*, i32*, ...)*))
532+
#pragma omp parallel
533+
#pragma omp parallel copyin(t)
534+
++t;
535+
}
536+
// NESTED: define {{.*}}void [[OUTLINED]](
537+
// NESTED: [[T:%.+]] = call i32* [[THRP_T:@.+]]()
538+
// NESTED: call void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* @{{.+}}, i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i32*)* [[OUTLINED1:@.+]] to void (i32*, i32*, ...)*), i32* [[T]])
539+
540+
// NESTED: define {{.*}}void [[OUTLINED1]](
541+
// NESTED: [[T_MASTER:%.+]] = load i32*, i32** %
542+
// NESTED: [[T:%.+]] = call i32* [[THRP_T]]()
543+
// NESTED: [[T_MASTER_VAL:%.+]] = load i32, i32* [[T_MASTER]],
544+
// NESTED: store i32 [[T_MASTER_VAL]], i32* [[T]],
545+
#endif // NESTED
527546

0 commit comments

Comments
 (0)