Skip to content

Commit 9d29860

Browse files
committed
Create implicit mappers when mapping arrays of structs when a member has a mapper.
This builds upon #101101, which used implicit compiler-generated mappers when mapping an array-section of structs with members that have user-defained default mappers. Now we do the same when mapping arrays of structs.
1 parent b6f9800 commit 9d29860

7 files changed

+388
-16
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,9 @@ OpenMP Support
10651065
open parenthesis. (#GH139665)
10661066
- An error is now emitted when OpenMP ``collapse`` and ``ordered`` clauses have
10671067
an argument larger than what can fit within a 64-bit integer.
1068+
- Fixed mapping of arrays of structs containing nested structs with user defined
1069+
mappers, by using compiler-generated default mappers for the outer structs for
1070+
such maps.
10681071

10691072
Improvements
10701073
^^^^^^^^^^^^

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22060,20 +22060,34 @@ static void checkMappableExpressionList(
2206022060
Type.getCanonicalType(), UnresolvedMapper);
2206122061
if (ER.isInvalid())
2206222062
continue;
22063-
if (!ER.get() && isa<ArraySectionExpr>(VE)) {
22064-
// Create implicit mapper as needed.
22065-
QualType BaseType = VE->getType().getCanonicalType();
22066-
if (BaseType->isSpecificBuiltinType(BuiltinType::ArraySection)) {
22067-
const auto *OASE = cast<ArraySectionExpr>(VE->IgnoreParenImpCasts());
22068-
QualType BType = ArraySectionExpr::getBaseOriginalType(OASE->getBase());
22069-
QualType ElemType;
22070-
if (const auto *ATy = BType->getAsArrayTypeUnsafe())
22071-
ElemType = ATy->getElementType();
22072-
else
22073-
ElemType = BType->getPointeeType();
22063+
22064+
// If no user-defined mapper is found, we need to create an implicit one for
22065+
// arrays/array-sections on structs that have members that have
22066+
// user-defined mappers. This is needed to ensure that the mapper for the
22067+
// member is invoked when mapping each element of the array/array-section.
22068+
if (!ER.get()) {
22069+
QualType BaseType;
22070+
22071+
if (isa<ArraySectionExpr>(VE)) {
22072+
BaseType = VE->getType().getCanonicalType();
22073+
if (BaseType->isSpecificBuiltinType(BuiltinType::ArraySection)) {
22074+
const auto *OASE = cast<ArraySectionExpr>(VE->IgnoreParenImpCasts());
22075+
QualType BType =
22076+
ArraySectionExpr::getBaseOriginalType(OASE->getBase());
22077+
QualType ElemType;
22078+
if (const auto *ATy = BType->getAsArrayTypeUnsafe())
22079+
ElemType = ATy->getElementType();
22080+
else
22081+
ElemType = BType->getPointeeType();
22082+
BaseType = ElemType.getCanonicalType();
22083+
}
22084+
} else if (VE->getType()->isArrayType()) {
22085+
const ArrayType *AT = VE->getType()->getAsArrayTypeUnsafe();
22086+
const QualType ElemType = AT->getElementType();
2207422087
BaseType = ElemType.getCanonicalType();
2207522088
}
22076-
if (BaseType->getAsRecordDecl() &&
22089+
22090+
if (!BaseType.isNull() && BaseType->getAsRecordDecl() &&
2207722091
isImplicitMapperNeeded(SemaRef, DSAS, BaseType, VE)) {
2207822092
ER = buildImplicitMapper(SemaRef, BaseType, DSAS);
2207922093
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -ast-dump %s | FileCheck %s --check-prefix=DUM
2+
3+
typedef struct {
4+
int a;
5+
} C;
6+
#pragma omp declare mapper(C s) map(to : s.a)
7+
8+
typedef struct {
9+
int e;
10+
C f;
11+
int h;
12+
} D;
13+
14+
void foo() {
15+
D sa[10];
16+
sa[1].e = 111;
17+
sa[1].f.a = 222;
18+
19+
#pragma omp target map(tofrom : sa)
20+
{
21+
sa[0].e = 333;
22+
sa[1].f.a = 444;
23+
}
24+
}
25+
26+
// DUM: -OMPDeclareMapperDecl{{.*}}<<invalid sloc>> <invalid sloc>
27+
// DUM-NEXT: |-OMPMapClause {{.*}}<<invalid sloc>> <implicit>
28+
// DUM-NEXT: | |-MemberExpr {{.*}}<line:9:3> 'int' lvalue .e
29+
// DUM-NEXT: | | `-DeclRefExpr {{.*}}<<invalid sloc>> 'D' lvalue Var {{.*}} '_s' 'D'
30+
// DUM-NEXT: | |-MemberExpr {{.*}}<line:10:3> 'C' lvalue .f {{.*}}
31+
// DUM-NEXT: | | `-DeclRefExpr {{.*}}<<invalid sloc>> 'D' lvalue Var {{.*}} '_s' 'D'
32+
// DUM-NEXT: | `-MemberExpr {{.*}}<line:11:3> 'int' lvalue .h {{.*}}
33+
// DUM-NEXT: | `-DeclRefExpr {{.*}}<<invalid sloc>> 'D' lvalue Var {{.*}} '_s' 'D'
34+
// ]DUM-NEXT: `-VarDecl {{.*}} <line:12:1> col:1 implicit used _s 'D'

0 commit comments

Comments
 (0)