Skip to content

Commit c09c065

Browse files
committed
[OPENMP]Fix PR43772: No warning in non-combined target regions.
Need to analyze inner target regions in case of implicit mapping of the data members when target region is created in one of the class member functions.
1 parent 43a46f1 commit c09c065

5 files changed

+38
-7
lines changed

clang/lib/Sema/SemaOpenMP.cpp

+18-3
Original file line numberDiff line numberDiff line change
@@ -2768,6 +2768,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
27682768
DSAStackTy *Stack;
27692769
Sema &SemaRef;
27702770
bool ErrorFound = false;
2771+
bool TryCaptureCXXThisMembers = false;
27712772
CapturedStmt *CS = nullptr;
27722773
llvm::SmallVector<Expr *, 4> ImplicitFirstprivate;
27732774
llvm::SmallVector<Expr *, 4> ImplicitMap;
@@ -2779,12 +2780,26 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
27792780
if (!S->hasAssociatedStmt() || !S->getAssociatedStmt())
27802781
return;
27812782
visitSubCaptures(S->getInnermostCapturedStmt());
2783+
// Try to capture inner this->member references to generate correct mappings
2784+
// and diagnostics.
2785+
if (TryCaptureCXXThisMembers ||
2786+
(isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()) &&
2787+
llvm::any_of(S->getInnermostCapturedStmt()->captures(),
2788+
[](const CapturedStmt::Capture &C) {
2789+
return C.capturesThis();
2790+
}))) {
2791+
bool SavedTryCaptureCXXThisMembers = TryCaptureCXXThisMembers;
2792+
TryCaptureCXXThisMembers = true;
2793+
Visit(S->getInnermostCapturedStmt()->getCapturedStmt());
2794+
TryCaptureCXXThisMembers = SavedTryCaptureCXXThisMembers;
2795+
}
27822796
}
27832797

27842798
public:
27852799
void VisitDeclRefExpr(DeclRefExpr *E) {
2786-
if (E->isTypeDependent() || E->isValueDependent() ||
2787-
E->containsUnexpandedParameterPack() || E->isInstantiationDependent())
2800+
if (TryCaptureCXXThisMembers || E->isTypeDependent() ||
2801+
E->isValueDependent() || E->containsUnexpandedParameterPack() ||
2802+
E->isInstantiationDependent())
27882803
return;
27892804
if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) {
27902805
// Check the datasharing rules for the expressions in the clauses.
@@ -3018,7 +3033,7 @@ class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> {
30183033
})) {
30193034
Visit(E->getBase());
30203035
}
3021-
} else {
3036+
} else if (!TryCaptureCXXThisMembers) {
30223037
Visit(E->getBase());
30233038
}
30243039
}

clang/test/OpenMP/distribute_simd_loop_messages.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44
// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4 %s -Wuninitialized
55
// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=50 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp5 %s -Wuninitialized
66

7+
class S5 {
8+
int a;
9+
S5() : a(0) {}
10+
11+
public:
12+
S5(int v) : a(v) {}
13+
S5 &operator=(S5 &s) {
14+
#pragma omp target
15+
#pragma omp teams
16+
#pragma omp distribute simd
17+
for (int k = 0; k < s.a; ++k) // expected-warning {{Non-trivial type 'S5' is mapped, only trivial types are guaranteed to be mapped correctly}}
18+
++s.a;
19+
return *this;
20+
}
21+
};
22+
723
static int sii;
824
// expected-note@+1 {{defined as threadprivate or thread local}}
925
#pragma omp threadprivate(sii)

clang/test/OpenMP/teams_distribute_codegen.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ struct SS{
158158
// CK3: define {{.*}}i32 @{{.+}}foo{{.+}}(
159159
int foo(void) {
160160

161-
// CK3: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 1, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0)
161+
// CK3: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 2, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* %{{.+}}, i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0)
162162
// CK3: call void @[[OFFL1:.+]]([[SSI]]* %{{.+}})
163163
#pragma omp target
164164
#pragma omp teams distribute
@@ -174,7 +174,7 @@ struct SS{
174174
// CK3: define internal void @[[OUTL1]]({{.+}})
175175
// CK3: call void @__kmpc_for_static_init_4(
176176
// CK3: call void @__kmpc_for_static_fini(
177-
// CK3: ret void
177+
// CK3: ret void
178178

179179
return a[0];
180180
}

clang/test/OpenMP/teams_distribute_parallel_for_codegen.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ struct SS{
161161
// CK3: define {{.*}}i32 @{{.+}}foo{{.+}}(
162162
int foo(void) {
163163

164-
// CK3: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 1, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0)
164+
// CK3: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 2, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* %{{.+}}, i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0)
165165
// CK3: call void @[[OFFL1:.+]]([[SSI]]* %{{.+}})
166166
#pragma omp target
167167
#pragma omp teams distribute parallel for

clang/test/OpenMP/teams_distribute_simd_codegen.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ struct SS{
165165
// CK3: define {{.*}}i32 @{{.+}}foo{{.+}}(
166166
int foo(void) {
167167

168-
// CK3: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 1, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 1)
168+
// CK3: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 2, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* %{{.+}}, i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 1)
169169
// CK3: call void @[[OFFL1:.+]]([[SSI]]* %{{.+}})
170170
#pragma omp target
171171
#pragma omp teams distribute simd

0 commit comments

Comments
 (0)