Skip to content

Commit 48bad08

Browse files
committed
[OPENMP]Improve handling of possibly incorrectly mapped types.
Need to analayze the type of the expression for mapping, not the type of the declaration.
1 parent 65c0805 commit 48bad08

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

clang/lib/Sema/SemaOpenMP.cpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -16008,8 +16008,22 @@ static void checkMappableExpressionList(
1600816008
return MC.getAssociatedDeclaration();
1600916009
});
1601016010
assert(I != CurComponents.end() && "Null decl on map clause.");
16011-
QualType Type =
16012-
I->getAssociatedDeclaration()->getType().getNonReferenceType();
16011+
QualType Type;
16012+
auto *ASE = dyn_cast<ArraySubscriptExpr>(VE->IgnoreParens());
16013+
auto *OASE = dyn_cast<OMPArraySectionExpr>(VE->IgnoreParens());
16014+
if (ASE) {
16015+
Type = ASE->getType().getNonReferenceType();
16016+
} else if (OASE) {
16017+
QualType BaseType =
16018+
OMPArraySectionExpr::getBaseOriginalType(OASE->getBase());
16019+
if (const auto *ATy = BaseType->getAsArrayTypeUnsafe())
16020+
Type = ATy->getElementType();
16021+
else
16022+
Type = BaseType->getPointeeType();
16023+
Type = Type.getNonReferenceType();
16024+
} else {
16025+
Type = VE->getType();
16026+
}
1601316027

1601416028
// OpenMP 4.5 [2.10.5, target update Construct, Restrictions, p.4]
1601516029
// A list item in a to or from clause must have a mappable type.
@@ -16019,6 +16033,8 @@ static void checkMappableExpressionList(
1601916033
DSAS, Type))
1602016034
continue;
1602116035

16036+
Type = I->getAssociatedDeclaration()->getType().getNonReferenceType();
16037+
1602216038
if (CKind == OMPC_map) {
1602316039
// target enter data
1602416040
// OpenMP [2.10.2, Restrictions, p. 99]

clang/test/OpenMP/target_map_messages.cpp

+23-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 200 %s -Wno-openmp-mapping -Wuninitialized
1+
// RUN: %clang_cc1 -verify=expected,warn -fopenmp -ferror-limit 200 %s -Wuninitialized
22
// RUN: %clang_cc1 -DCCODE -verify -fopenmp -ferror-limit 200 -x c %s -Wno-openmp -Wuninitialized
33

44
// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 200 %s -Wno-openmp-target -Wuninitialized
@@ -499,13 +499,13 @@ T tmain(T argc) {
499499
#pragma omp target data map(tofrom: argc > 0 ? x : y) // expected-error 2 {{expected expression containing only member accesses and/or array sections based on named variables}}
500500
#pragma omp target data map(argc)
501501
#pragma omp target data map(S1) // expected-error {{'S1' does not refer to a value}}
502-
#pragma omp target data map(a, b, c, d, f) // expected-error {{incomplete type 'S1' where a complete type is required}}
503-
#pragma omp target data map(ba)
504-
#pragma omp target data map(ca)
502+
#pragma omp target data map(a, b, c, d, f) // expected-error {{incomplete type 'S1' where a complete type is required}} warn-warning 2 {{Type 'const S2' is not trivially copyable and not guaranteed to be mapped correctly}} warn-warning 2 {{Type 'const S3' is not trivially copyable and not guaranteed to be mapped correctly}}
503+
#pragma omp target data map(ba) // warn-warning 2 {{Type 'const S2 [5]' is not trivially copyable and not guaranteed to be mapped correctly}}
504+
#pragma omp target data map(ca) // warn-warning 2 {{Type 'const S3 [5]' is not trivially copyable and not guaranteed to be mapped correctly}}
505505
#pragma omp target data map(da)
506506
#pragma omp target data map(S2::S2s)
507507
#pragma omp target data map(S2::S2sc)
508-
#pragma omp target data map(e, g)
508+
#pragma omp target data map(e, g) // warn-warning 2 {{Type 'S4' is not trivially copyable and not guaranteed to be mapped correctly}} warn-warning 2 {{Type 'S5' is not trivially copyable and not guaranteed to be mapped correctly}}
509509
#pragma omp target data map(h) // expected-error {{threadprivate variables are not allowed in 'map' clause}}
510510
#pragma omp target data map(k) map(k) // expected-error 2 {{variable already marked as mapped in current construct}} expected-note 2 {{used here}}
511511
#pragma omp target map(k), map(k[:5]) // expected-error 2 {{pointer cannot be mapped along with a section derived from itself}} expected-note 2 {{used here}}
@@ -558,6 +558,17 @@ struct SC1{
558558
int b[10];
559559
};
560560

561+
class S8 {
562+
public:
563+
virtual void foo() = 0;
564+
} *s8;
565+
566+
class S9 {
567+
public:
568+
virtual void foo() {}
569+
} s9;
570+
571+
561572
int main(int argc, char **argv) {
562573
const int d = 5;
563574
const int da[5] = { 0 };
@@ -595,14 +606,14 @@ int main(int argc, char **argv) {
595606
#pragma omp target data map(tofrom: argc > 0 ? argv[1] : argv[2]) // expected-error {{xpected expression containing only member accesses and/or array sections based on named variables}}
596607
#pragma omp target data map(argc)
597608
#pragma omp target data map(S1) // expected-error {{'S1' does not refer to a value}}
598-
#pragma omp target data map(a, b, c, d, f) // expected-error {{incomplete type 'S1' where a complete type is required}}
609+
#pragma omp target data map(a, b, c, d, f) // expected-error {{incomplete type 'S1' where a complete type is required}} warn-warning {{Type 'const S2' is not trivially copyable and not guaranteed to be mapped correctly}} warn-warning {{Type 'const S3' is not trivially copyable and not guaranteed to be mapped correctly}}
599610
#pragma omp target data map(argv[1])
600-
#pragma omp target data map(ba)
601-
#pragma omp target data map(ca)
611+
#pragma omp target data map(ba) // warn-warning {{Type 'const S2 [5]' is not trivially copyable and not guaranteed to be mapped correctly}}
612+
#pragma omp target data map(ca) // warn-warning {{Type 'const S3 [5]' is not trivially copyable and not guaranteed to be mapped correctly}}
602613
#pragma omp target data map(da)
603614
#pragma omp target data map(S2::S2s)
604615
#pragma omp target data map(S2::S2sc)
605-
#pragma omp target data map(e, g)
616+
#pragma omp target data map(e, g) // warn-warning {{Type 'S4' is not trivially copyable and not guaranteed to be mapped correctly}} warn-warning {{Type 'S5' is not trivially copyable and not guaranteed to be mapped correctly}}
606617
#pragma omp target data map(h) // expected-error {{threadprivate variables are not allowed in 'map' clause}}
607618
#pragma omp target data map(k), map(k) // expected-error {{variable already marked as mapped in current construct}} expected-note {{used here}}
608619
#pragma omp target map(k), map(k[:5]) // expected-error {{pointer cannot be mapped along with a section derived from itself}} expected-note {{used here}}
@@ -635,7 +646,7 @@ int main(int argc, char **argv) {
635646
{}
636647
#pragma omp target firstprivate(j) map(j) // expected-error {{firstprivate variable cannot be in a map clause in '#pragma omp target' directive}} expected-note {{defined as firstprivate}}
637648
{}
638-
#pragma omp target map(m)
649+
#pragma omp target map(m) // warn-warning {{Type 'S6<int>' is not trivially copyable and not guaranteed to be mapped correctly}}
639650
{}
640651
// expected-note@+1 {{used here}}
641652
#pragma omp target map(s.s.s)
@@ -681,6 +692,8 @@ int main(int argc, char **argv) {
681692
{ s.a++; }
682693
#pragma omp target map(s.s.s.b[:2])
683694
{ s.s.s.b[0]++; }
695+
#pragma omp target map(s8[0:1], s9) // warn-warning {{Type 'class S8' is not trivially copyable and not guaranteed to be mapped correctly}} warn-warning {{Type 'class S9' is not trivially copyable and not guaranteed to be mapped correctly}}
696+
{}
684697

685698
return tmain<int, 3>(argc)+tmain<from, 4>(argc); // expected-note {{in instantiation of function template specialization 'tmain<int, 3>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<int, 4>' requested here}}
686699
}

0 commit comments

Comments
 (0)