================ @@ -20796,6 +20796,204 @@ struct MappableVarListInfo { }; } // namespace +static DeclRefExpr *buildImplicitMap(Sema &S, QualType BaseType, + DSAStackTy *Stack, + SmallVectorImpl<OMPClause *> &Maps) { + + const RecordDecl *RD = BaseType->getAsRecordDecl(); + SourceRange Range = RD->getSourceRange(); + DeclarationNameInfo ImplicitName; + // Dummy variable _s for Mapper. + VarDecl *VD = buildVarDecl(S, Range.getEnd(), BaseType, "_s"); + DeclRefExpr *MapperVarRef = + buildDeclRefExpr(S, VD, BaseType, SourceLocation()); + + // Create implicit map clause for mapper. + SmallVector<Expr *, 4> SExprs; + for (auto *FD : RD->fields()) { + Expr *BE = S.BuildMemberExpr( + MapperVarRef, /*IsArrow=*/false, Range.getBegin(), + NestedNameSpecifierLoc(), Range.getBegin(), FD, + DeclAccessPair::make(FD, FD->getAccess()), + /*HadMultipleCandidates=*/false, + DeclarationNameInfo(FD->getDeclName(), FD->getSourceRange().getBegin()), + FD->getType(), VK_LValue, OK_Ordinary); + SExprs.push_back(BE); + } + CXXScopeSpec MapperIdScopeSpec; + DeclarationNameInfo MapperId; + OpenMPDirectiveKind DKind = Stack->getCurrentDirective(); + + OMPClause *MapClause = S.OpenMP().ActOnOpenMPMapClause( + nullptr, OMPC_MAP_MODIFIER_unknown, SourceLocation(), MapperIdScopeSpec, + MapperId, DKind == OMPD_target_enter_data ? OMPC_MAP_to : OMPC_MAP_tofrom, + /*IsMapTypeImplicit=*/true, SourceLocation(), SourceLocation(), SExprs, + OMPVarListLocTy()); + Maps.push_back(MapClause); + return MapperVarRef; +} + +static ExprResult buildImplicitMapper(Sema &S, QualType BaseType, + DSAStackTy *Stack) { + + // Build impilicit map for mapper + SmallVector<OMPClause *, 4> Maps; + DeclRefExpr *MapperVarRef = buildImplicitMap(S, BaseType, Stack, Maps); + + const RecordDecl *RD = BaseType->getAsRecordDecl(); + // AST context is RD's ParentASTContext(). + ASTContext &Ctx = RD->getParentASTContext(); + // DeclContext is RD's DeclContext. + DeclContext *DCT = const_cast<DeclContext *>(RD->getDeclContext()); + + // Create implicit default mapper for "RD". + DeclarationName MapperId; + auto &DeclNames = Ctx.DeclarationNames; + MapperId = DeclNames.getIdentifier(&Ctx.Idents.get("default")); + auto *DMD = OMPDeclareMapperDecl::Create(Ctx, DCT, SourceLocation(), MapperId, + BaseType, MapperId, Maps, nullptr); + Scope *Scope = S.getScopeForContext(DCT); + if (Scope) + S.PushOnScopeChains(DMD, Scope, /*AddToContext*/ false); + DCT->addDecl(DMD); + DMD->setAccess(clang::AS_none); + auto *VD = cast<DeclRefExpr>(MapperVarRef)->getDecl(); + VD->setDeclContext(DMD); + VD->setLexicalDeclContext(DMD); + DMD->addDecl(VD); + DMD->setMapperVarRef(MapperVarRef); + FieldDecl *FD = *RD->field_begin(); + // create mapper refence. + return DeclRefExpr::Create(Ctx, NestedNameSpecifierLoc{}, FD->getLocation(), + DMD, false, SourceLocation(), BaseType, VK_LValue); +} + +// Look up the user-defined mapper given the mapper name and mapper type, +// return true if found one. +static bool hasUserDefinedMapper(Sema &SemaRef, Scope *S, + CXXScopeSpec &MapperIdScopeSpec, + const DeclarationNameInfo &MapperId, + QualType Type) { + // Find all user-defined mappers with the given MapperId. + SmallVector<UnresolvedSet<8>, 4> Lookups; + LookupResult Lookup(SemaRef, MapperId, Sema::LookupOMPMapperName); + Lookup.suppressDiagnostics(); + if (S) + while (S && SemaRef.LookupParsedName(Lookup, S, &MapperIdScopeSpec, ---------------- alexey-bataev wrote:
```suggestion while (S && SemaRef.LookupParsedName(Lookup, S, &MapperIdScopeSpec, ``` https://github.com/llvm/llvm-project/pull/101101 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits