From dbe86786f7f19c3f1338437f4275797e08501efd Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Tue, 7 Apr 2020 17:14:59 -0400 Subject: [PATCH] [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. --- clang/lib/Sema/SemaOpenMP.cpp | 3 +++ clang/test/OpenMP/parallel_codegen.cpp | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index e9b18f6..e969b70 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 586187f..d423121 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;[[@LINE+8]];0;;\00" template @@ -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); } -- 2.7.4