Skip to content

Commit 02b6849

Browse files
authored
[Clang][OpenMP] Fix mapping of arrays of structs with members with mappers (#142511)
This builds upon #101101 from @jyu2-git, which used compiler-generated mappers when mapping an array-section of structs with members that have user-defined default mappers. Now we do the same when mapping arrays of structs.
1 parent 0c62571 commit 02b6849

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
@@ -1102,6 +1102,9 @@ OpenMP Support
11021102
- An error is now emitted when OpenMP ``collapse`` and ``ordered`` clauses have
11031103
an argument larger than what can fit within a 64-bit integer.
11041104
- Added support for private variable reduction.
1105+
- Fixed mapping of arrays of structs containing nested structs with user defined
1106+
mappers, by using compiler-generated default mappers for the outer structs for
1107+
such maps.
11051108

11061109
Improvements
11071110
^^^^^^^^^^^^

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22057,20 +22057,34 @@ static void checkMappableExpressionList(
2205722057
Type.getCanonicalType(), UnresolvedMapper);
2205822058
if (ER.isInvalid())
2205922059
continue;
22060-
if (!ER.get() && isa<ArraySectionExpr>(VE)) {
22061-
// Create implicit mapper as needed.
22062-
QualType BaseType = VE->getType().getCanonicalType();
22063-
if (BaseType->isSpecificBuiltinType(BuiltinType::ArraySection)) {
22064-
const auto *OASE = cast<ArraySectionExpr>(VE->IgnoreParenImpCasts());
22065-
QualType BType = ArraySectionExpr::getBaseOriginalType(OASE->getBase());
22066-
QualType ElemType;
22067-
if (const auto *ATy = BType->getAsArrayTypeUnsafe())
22068-
ElemType = ATy->getElementType();
22069-
else
22070-
ElemType = BType->getPointeeType();
22060+
22061+
// If no user-defined mapper is found, we need to create an implicit one for
22062+
// arrays/array-sections on structs that have members that have
22063+
// user-defined mappers. This is needed to ensure that the mapper for the
22064+
// member is invoked when mapping each element of the array/array-section.
22065+
if (!ER.get()) {
22066+
QualType BaseType;
22067+
22068+
if (isa<ArraySectionExpr>(VE)) {
22069+
BaseType = VE->getType().getCanonicalType();
22070+
if (BaseType->isSpecificBuiltinType(BuiltinType::ArraySection)) {
22071+
const auto *OASE = cast<ArraySectionExpr>(VE->IgnoreParenImpCasts());
22072+
QualType BType =
22073+
ArraySectionExpr::getBaseOriginalType(OASE->getBase());
22074+
QualType ElemType;
22075+
if (const auto *ATy = BType->getAsArrayTypeUnsafe())
22076+
ElemType = ATy->getElementType();
22077+
else
22078+
ElemType = BType->getPointeeType();
22079+
BaseType = ElemType.getCanonicalType();
22080+
}
22081+
} else if (VE->getType()->isArrayType()) {
22082+
const ArrayType *AT = VE->getType()->getAsArrayTypeUnsafe();
22083+
const QualType ElemType = AT->getElementType();
2207122084
BaseType = ElemType.getCanonicalType();
2207222085
}
22073-
if (BaseType->getAsRecordDecl() &&
22086+
22087+
if (!BaseType.isNull() && BaseType->getAsRecordDecl() &&
2207422088
isImplicitMapperNeeded(SemaRef, DSAS, BaseType, VE)) {
2207522089
ER = buildImplicitMapper(SemaRef, BaseType, DSAS);
2207622090
}
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)