]> granicus.if.org Git - clang/commitdiff
Merging r366483:
authorHans Wennborg <hans@hanshq.net>
Mon, 22 Jul 2019 17:45:30 +0000 (17:45 +0000)
committerHans Wennborg <hans@hanshq.net>
Mon, 22 Jul 2019 17:45:30 +0000 (17:45 +0000)
------------------------------------------------------------------------
r366483 | abataev | 2019-07-18 21:40:24 +0200 (Thu, 18 Jul 2019) | 6 lines

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

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

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

index bec2fd8d3c0856919e37cc138bdc0e35282744d5..4ac87469bf449c5b937179779b456bb8b0c19383 100644 (file)
@@ -1882,6 +1882,13 @@ bool Sema::isOpenMPPrivateDecl(const ValueDecl *D, unsigned Level) const {
         !isOpenMPSimdDirective(DSAStack->getCurrentDirective()))
       return true;
   }
+  if (const auto *VD = dyn_cast<VarDecl>(D)) {
+    if (DSAStack->isThreadPrivate(const_cast<VarDecl *>(VD)) &&
+        DSAStack->isForceVarCapturing() &&
+        !DSAStack->hasExplicitDSA(
+            D, [](OpenMPClauseKind K) { return K == OMPC_copyin; }, Level))
+      return true;
+  }
   return DSAStack->hasExplicitDSA(
              D, [](OpenMPClauseKind K) { return K == OMPC_private; }, Level) ||
          (DSAStack->isClauseParsingMode() &&
index 8fa9edd2c1ac579c71299605fd4c59aa2b32da40..87c11f040619bbd823da97f82f750bc79543de68 100644 (file)
@@ -19,6 +19,7 @@
 // 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
 // RUN: %clang_cc1 -verify -fopenmp -x c++ -fblocks -DBLOCKS -triple x86_64-linux -emit-llvm %s -o - | FileCheck -check-prefix=TLS-BLOCKS %s
 // 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
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -DNESTED -triple x86_64-linux -emit-llvm %s -o - | FileCheck %s -check-prefix=NESTED
 
 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-linux -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY1 %s
 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-linux -emit-pch -o %t %s
@@ -28,7 +29,7 @@
 // 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
 // SIMD-ONLY1-NOT: {{__kmpc|__tgt}}
 // expected-no-diagnostics
-#ifndef ARRAY
+#if !defined(ARRAY) && !defined(NESTED)
 #ifndef HEADER
 #define HEADER
 
@@ -493,7 +494,7 @@ int main() {
 // TLS-CHECK: ret void
 
 #endif
-#else
+#elif defined(ARRAY)
 // ARRAY-LABEL: array_func
 // TLS-ARRAY-LABEL: array_func
 
@@ -522,6 +523,24 @@ void array_func() {
 #pragma omp parallel copyin(a, s)
   ;
 }
-#endif
-
+#elif defined(NESTED)
+int t;
+#pragma omp threadprivate(t)
+// NESTED: foo
+void foo() {
+  // 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*, ...)*))
+#pragma omp parallel
+#pragma omp parallel copyin(t)
+  ++t;
+}
+// NESTED: define {{.*}}void [[OUTLINED]](
+// NESTED: [[T:%.+]] = call i32* [[THRP_T:@.+]]()
+// 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]])
+
+// NESTED: define {{.*}}void [[OUTLINED1]](
+// NESTED: [[T_MASTER:%.+]] = load i32*, i32** %
+// NESTED: [[T:%.+]] = call i32* [[THRP_T]]()
+// NESTED: [[T_MASTER_VAL:%.+]] = load i32, i32* [[T_MASTER]],
+// NESTED: store i32 [[T_MASTER_VAL]], i32* [[T]],
+#endif // NESTED