[OpenMP 5.0] Fix user-defined mapper lookup in sema
This patches fixes the case when a user-defined mapper is attached to
the elements of an array, and to report error when a mapper is used for
types other than struct, class, and union.
Patch by Lingda Li <lildmh@gmail.com>
Differential Revision: https://reviews.llvm.org/D67978
llvm-svn: 373023
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 17586c9..6e2a344 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -14754,6 +14754,11 @@
Expr *UnresolvedMapper) {
if (MapperIdScopeSpec.isInvalid())
return ExprError();
+ // Get the actual type for the array type.
+ if (Type->isArrayType()) {
+ assert(Type->getAsArrayTypeUnsafe() && "Expect to get a valid array type");
+ Type = Type->getAsArrayTypeUnsafe()->getElementType().getCanonicalType();
+ }
// Find all user-defined mappers with the given MapperId.
SmallVector<UnresolvedSet<8>, 4> Lookups;
LookupResult Lookup(SemaRef, MapperId, Sema::LookupOMPMapperName);
@@ -14800,11 +14805,14 @@
MapperIdScopeSpec.getWithLocInContext(SemaRef.Context), MapperId,
/*ADL=*/false, /*Overloaded=*/true, URS.begin(), URS.end());
}
+ SourceLocation Loc = MapperId.getLoc();
// [OpenMP 5.0], 2.19.7.3 declare mapper Directive, Restrictions
// The type must be of struct, union or class type in C and C++
- if (!Type->isStructureOrClassType() && !Type->isUnionType())
- return ExprEmpty();
- SourceLocation Loc = MapperId.getLoc();
+ if (!Type->isStructureOrClassType() && !Type->isUnionType() &&
+ (MapperIdScopeSpec.isSet() || MapperId.getAsString() != "default")) {
+ SemaRef.Diag(Loc, diag::err_omp_mapper_wrong_type);
+ return ExprError();
+ }
// Perform argument dependent lookup.
if (SemaRef.getLangOpts().CPlusPlus && !MapperIdScopeSpec.isSet())
argumentDependentLookup(SemaRef, MapperId, Loc, Type, Lookups);