[clang] Avoid unevaluated implicit private (PR #92055)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 13 18:23:47 PDT 2024
https://github.com/SunilKuravinakop created https://github.com/llvm/llvm-project/pull/92055
For every variable used under `#pragma omp task` directive (`DeclRefExpr`) an ImplicitPrivateVariable is created in the AST, if `private` or `shared` clauses are not present. If the variable has the property of `non_odr_use_unevaluated` e.g. for statements which use `sizeof( i )` `i` will have `non_odr_use_unevaluated` . In such cases CodeGen was asserting by avoiding emitting of LLVM IR for such variables. To prevent this assertion this checkin avoids adding the ImplicitPrivateVariable for variables with `non_odr_use_unevaluated`.
>From 6946c9f1285d5a27eafcdbf13f79c0641736198d Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop <kuravina at pe28vega.us.cray.com>
Date: Thu, 9 May 2024 12:09:15 -0500
Subject: [PATCH 1/2] 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 <kuravina at pe28vega.us.cray.com>
Date: Mon, 13 May 2024 01:28:59 -0500
Subject: [PATCH 2/2] 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
More information about the cfe-commits
mailing list