[clang] dbe8678 - [OPENMP]Do not capture global marked as shared in OpenMP region.
Alexey Bataev via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 7 14:42:25 PDT 2020
Author: Alexey Bataev
Date: 2020-04-07T17:33:17-04:00
New Revision: dbe86786f7f19c3f1338437f4275797e08501efd
URL: https://github.com/llvm/llvm-project/commit/dbe86786f7f19c3f1338437f4275797e08501efd
DIFF: https://github.com/llvm/llvm-project/commit/dbe86786f7f19c3f1338437f4275797e08501efd.diff
LOG: [OPENMP]Do not capture global marked as shared in OpenMP region.
No need to capture the global variable marked as shared in the OpenMP
region, the original variable can be used.
Added:
Modified:
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/parallel_codegen.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index e9b18f6e9307..e969b7044a89 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -2107,6 +2107,9 @@ VarDecl *Sema::isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo,
// Threadprivate variables must not be captured.
if (isOpenMPThreadPrivate(DVarPrivate.CKind))
return nullptr;
+ // Global shared must not be captured.
+ if (VD && !VD->hasLocalStorage() && DVarPrivate.CKind == OMPC_shared)
+ 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,
diff --git a/clang/test/OpenMP/parallel_codegen.cpp b/clang/test/OpenMP/parallel_codegen.cpp
index 586187f09521..d42312193709 100644
--- a/clang/test/OpenMP/parallel_codegen.cpp
+++ b/clang/test/OpenMP/parallel_codegen.cpp
@@ -21,10 +21,10 @@
// CHECK-DEBUG-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
// CHECK-DEBUG-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] c";unknown;unknown;0;0;;\00"
// CHECK-DEBUG-DAG: [[DEF_LOC_2:@.+]] = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
-// CHECK-DEBUG-DAG: [[LOC1:@.+]] = private unnamed_addr constant [{{.+}} x i8] c";{{.*}}parallel_codegen.cpp;main;[[@LINE+22]];1;;\00"
+// CHECK-DEBUG-DAG: [[LOC1:@.+]] = private unnamed_addr constant [{{.+}} x i8] c";{{.*}}parallel_codegen.cpp;main;[[@LINE+23]];1;;\00"
// CHECK-DEBUG-DAG: [[LOC2:@.+]] = private unnamed_addr constant [{{.+}} x i8] c";{{.*}}parallel_codegen.cpp;tmain;[[@LINE+11]];1;;\00"
// IRBUILDER-DEBUG-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
-// IRBUILDER-DEBUG-DAG: [[LOC1:@.+]] = private unnamed_addr constant [{{.+}} x i8] c";{{.*}}parallel_codegen.cpp;main;[[@LINE+19]];0;;\00"
+// IRBUILDER-DEBUG-DAG: [[LOC1:@.+]] = private unnamed_addr constant [{{.+}} x i8] c";{{.*}}parallel_codegen.cpp;main;[[@LINE+20]];0;;\00"
// IRBUILDER-DEBUG-DAG: [[LOC2:@.+]] = private unnamed_addr constant [{{.+}} x i8] c";{{.*}}parallel_codegen.cpp;tmain<char **>;[[@LINE+8]];0;;\00"
template <class T>
@@ -41,10 +41,11 @@ int tmain(T argc) {
return 0;
}
+int global;
int main (int argc, char **argv) {
int a[argc];
-#pragma omp parallel
- foo(a[1]);
+#pragma omp parallel shared(global, a) default(none)
+ (void)global, foo(a[1]);
return tmain(argv);
}
More information about the cfe-commits
mailing list