https://github.com/SunilKuravinakop updated https://github.com/llvm/llvm-project/pull/92055
>From 6946c9f1285d5a27eafcdbf13f79c0641736198d Mon Sep 17 00:00:00 2001 From: Sunil Kuravinakop <kurav...@pe28vega.us.cray.com> Date: Thu, 9 May 2024 12:09:15 -0500 Subject: [PATCH 1/5] Avoiding DeclRefExpr with "non_odr_use_unevaluated" to declare "Implicit Private variable" DeclRefExpr. Changes to be committed: modified: clang/lib/Sema/SemaOpenMP.cpp --- clang/lib/Sema/SemaOpenMP.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index cf5447f223d45..bb6518099b4df 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -3757,7 +3757,8 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> { void VisitDeclRefExpr(DeclRefExpr *E) { if (TryCaptureCXXThisMembers || E->isTypeDependent() || E->isValueDependent() || E->containsUnexpandedParameterPack() || - E->isInstantiationDependent()) + E->isInstantiationDependent() || + E->isNonOdrUse() == clang::NOUR_Unevaluated) return; if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { // Check the datasharing rules for the expressions in the clauses. >From 862907f4a6d7cebfb1b816e9ec890c39d0da112e Mon Sep 17 00:00:00 2001 From: Sunil Kuravinakop <kurav...@pe28vega.us.cray.com> Date: Mon, 13 May 2024 01:28:59 -0500 Subject: [PATCH 2/5] Adding checks for proper declaration of DeclRefExpr under the task directive (when variable can be non_odr_use_unevaluated). Changes to be committed: modified: clang/test/OpenMP/task_ast_print.cpp --- clang/test/OpenMP/task_ast_print.cpp | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/clang/test/OpenMP/task_ast_print.cpp b/clang/test/OpenMP/task_ast_print.cpp index 12923e6ab4244..9d545c5f6716c 100644 --- a/clang/test/OpenMP/task_ast_print.cpp +++ b/clang/test/OpenMP/task_ast_print.cpp @@ -5,6 +5,7 @@ // RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -ast-print %s | FileCheck %s // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -verify -Wno-vla %s -ast-print | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -ast-dump %s | FileCheck %s --check-prefix=DUMP // expected-no-diagnostics #ifndef HEADER @@ -208,4 +209,37 @@ int main(int argc, char **argv) { extern template int S<int>::TS; extern template long S<long>::TS; +int +implicit_firstprivate() { + +#pragma omp parallel num_threads(1) + { + int i = 0; + // DUMP : OMPTaskDirective + // DUMP-NEXT : OMPFirstprivateClause + // DUMP-NEXT : DeclRefExpr {{.+}} 'i' {{.+}} refers_to_enclosing_variable_or_capture + #pragma omp task + { + int j = sizeof(i); + j = i; + } + } +} + +int +no_implicit_firstprivate() { + +#pragma omp parallel num_threads(1) + { + int i = 0; + // DUMP : OMPTaskDirective + // DUMP-NEXT : CapturedStmt + // DUMP : DeclRefExpr {{.+}} 'i' {{.+}} non_odr_use_unevaluated refers_to_enclosing_variable_or_capture + #pragma omp task + { + int j = sizeof(i); + } + } +} + #endif >From 96c997ad09d87e48af7929b527259c5037242e10 Mon Sep 17 00:00:00 2001 From: Sunil Kuravinakop <kurav...@pe28vega.us.cray.com> Date: Tue, 14 May 2024 04:47:00 -0500 Subject: [PATCH 3/5] Minor changes to the test case. Changes to be committed: modified: clang/test/OpenMP/task_ast_print.cpp --- clang/test/OpenMP/task_ast_print.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/clang/test/OpenMP/task_ast_print.cpp b/clang/test/OpenMP/task_ast_print.cpp index 9d545c5f6716c..cb2cc63f63214 100644 --- a/clang/test/OpenMP/task_ast_print.cpp +++ b/clang/test/OpenMP/task_ast_print.cpp @@ -209,15 +209,16 @@ int main(int argc, char **argv) { extern template int S<int>::TS; extern template long S<long>::TS; -int +// DUMP-LABEL: FunctionDecl {{.*}} implicit_firstprivate +void implicit_firstprivate() { #pragma omp parallel num_threads(1) { int i = 0; - // DUMP : OMPTaskDirective - // DUMP-NEXT : OMPFirstprivateClause - // DUMP-NEXT : DeclRefExpr {{.+}} 'i' {{.+}} refers_to_enclosing_variable_or_capture + // DUMP: OMPTaskDirective + // DUMP-NEXT: OMPFirstprivateClause + // DUMP-NEXT: DeclRefExpr {{.+}} 'i' {{.+}} refers_to_enclosing_variable_or_capture #pragma omp task { int j = sizeof(i); @@ -226,15 +227,16 @@ implicit_firstprivate() { } } -int +// DUMP-LABEL: FunctionDecl {{.*}} no_implicit_firstprivate +void no_implicit_firstprivate() { #pragma omp parallel num_threads(1) { int i = 0; - // DUMP : OMPTaskDirective - // DUMP-NEXT : CapturedStmt - // DUMP : DeclRefExpr {{.+}} 'i' {{.+}} non_odr_use_unevaluated refers_to_enclosing_variable_or_capture + // DUMP: OMPTaskDirective + // DUMP-NEXT: CapturedStmt + // DUMP: DeclRefExpr {{.+}} 'i' {{.+}} non_odr_use_unevaluated refers_to_enclosing_variable_or_capture #pragma omp task { int j = sizeof(i); >From fbc1920af4d1d27800ad8d151d7418e1da300528 Mon Sep 17 00:00:00 2001 From: Sunil Kuravinakop <kurav...@pe28vega.us.cray.com> Date: Wed, 15 May 2024 02:21:18 -0500 Subject: [PATCH 4/5] Changes to incorporate Deepak's suggestion: This could still match if non_odr_use_unevaluated shows up, can't it? Can we add a check that non_odr_use_unevaluated should not be part of the DeclRefRexpr under this firstprivate clause? An example of DeclRefExpr seen on "-Xclang -ast-dump" is: -DeclRefExpr 0x187e0e0 <line:225:6> 'int' lvalue Var 0x187da20 'i' 'int' refers_to_enclosing_variable_or_capture Changes to be committed: modified: clang/test/OpenMP/task_ast_print.cpp --- clang/test/OpenMP/task_ast_print.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/OpenMP/task_ast_print.cpp b/clang/test/OpenMP/task_ast_print.cpp index cb2cc63f63214..23b63aff5d69b 100644 --- a/clang/test/OpenMP/task_ast_print.cpp +++ b/clang/test/OpenMP/task_ast_print.cpp @@ -218,7 +218,7 @@ implicit_firstprivate() { int i = 0; // DUMP: OMPTaskDirective // DUMP-NEXT: OMPFirstprivateClause - // DUMP-NEXT: DeclRefExpr {{.+}} 'i' {{.+}} refers_to_enclosing_variable_or_capture + // DUMP-NEXT: DeclRefExpr {{.+}} 'i' 'int' refers_to_enclosing_variable_or_capture #pragma omp task { int j = sizeof(i); >From e3567b6809544ba0f2a69eb361640284235aa30a Mon Sep 17 00:00:00 2001 From: Sunil Kuravinakop <kurav...@pe28vega.us.cray.com> Date: Wed, 15 May 2024 11:46:06 -0500 Subject: [PATCH 5/5] Adding DUMP-NOT for check variable 'i': DUMP-NOT: DeclRefExpr {{.+}} 'i' {{.+}} non_odr_use_unevaluated Changes to be committed: modified: clang/test/OpenMP/task_ast_print.cpp --- clang/test/OpenMP/task_ast_print.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/test/OpenMP/task_ast_print.cpp b/clang/test/OpenMP/task_ast_print.cpp index 23b63aff5d69b..2a6b8908a1e2d 100644 --- a/clang/test/OpenMP/task_ast_print.cpp +++ b/clang/test/OpenMP/task_ast_print.cpp @@ -218,7 +218,12 @@ implicit_firstprivate() { int i = 0; // DUMP: OMPTaskDirective // DUMP-NEXT: OMPFirstprivateClause - // DUMP-NEXT: DeclRefExpr {{.+}} 'i' 'int' refers_to_enclosing_variable_or_capture + // DUMP-NOT: DeclRefExpr {{.+}} 'i' {{.+}} non_odr_use_unevaluated + // DUMP: DeclRefExpr {{.+}} 'i' 'int' refers_to_enclosing_variable_or_capture + // DUMP: CapturedStmt + // DUMP: BinaryOperator {{.+}} 'int' lvalue '=' + // DUMP-NEXT: DeclRefExpr {{.+}} 'j' 'int' + // DUMP: DeclRefExpr {{.+}} 'i' {{.+}} non_odr_use_unevaluated #pragma omp task { int j = sizeof(i); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits