Skip to content

Commit ce67fcf

Browse files
Avoid unevaluated implicit private (#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`. --------- Authored-by: Sunil Kuravinakop <[email protected]>
1 parent e8692b8 commit ce67fcf

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3757,7 +3757,8 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
37573757
void VisitDeclRefExpr(DeclRefExpr *E) {
37583758
if (TryCaptureCXXThisMembers || E->isTypeDependent() ||
37593759
E->isValueDependent() || E->containsUnexpandedParameterPack() ||
3760-
E->isInstantiationDependent())
3760+
E->isInstantiationDependent() ||
3761+
E->isNonOdrUse() == clang::NOUR_Unevaluated)
37613762
return;
37623763
if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) {
37633764
// Check the datasharing rules for the expressions in the clauses.

clang/test/OpenMP/task_ast_print.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -ast-print %s | FileCheck %s
66
// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
77
// RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -verify -Wno-vla %s -ast-print | FileCheck %s
8+
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -ast-dump %s | FileCheck %s --check-prefix=DUMP
89
// expected-no-diagnostics
910

1011
#ifndef HEADER
@@ -208,4 +209,44 @@ int main(int argc, char **argv) {
208209
extern template int S<int>::TS;
209210
extern template long S<long>::TS;
210211

212+
// DUMP-LABEL: FunctionDecl {{.*}} implicit_firstprivate
213+
void
214+
implicit_firstprivate() {
215+
216+
#pragma omp parallel num_threads(1)
217+
{
218+
int i = 0;
219+
// DUMP: OMPTaskDirective
220+
// DUMP-NEXT: OMPFirstprivateClause
221+
// DUMP-NOT: DeclRefExpr {{.+}} 'i' {{.+}} non_odr_use_unevaluated
222+
// DUMP: DeclRefExpr {{.+}} 'i' 'int' refers_to_enclosing_variable_or_capture
223+
// DUMP: CapturedStmt
224+
// DUMP: BinaryOperator {{.+}} 'int' lvalue '='
225+
// DUMP-NEXT: DeclRefExpr {{.+}} 'j' 'int'
226+
// DUMP: DeclRefExpr {{.+}} 'i' {{.+}} non_odr_use_unevaluated
227+
#pragma omp task
228+
{
229+
int j = sizeof(i);
230+
j = i;
231+
}
232+
}
233+
}
234+
235+
// DUMP-LABEL: FunctionDecl {{.*}} no_implicit_firstprivate
236+
void
237+
no_implicit_firstprivate() {
238+
239+
#pragma omp parallel num_threads(1)
240+
{
241+
int i = 0;
242+
// DUMP: OMPTaskDirective
243+
// DUMP-NEXT: CapturedStmt
244+
// DUMP: DeclRefExpr {{.+}} 'i' {{.+}} non_odr_use_unevaluated refers_to_enclosing_variable_or_capture
245+
#pragma omp task
246+
{
247+
int j = sizeof(i);
248+
}
249+
}
250+
}
251+
211252
#endif

0 commit comments

Comments
 (0)