================
@@ -1458,6 +1462,76 @@ void Sema::ActOnPragmaExport(IdentifierInfo *IdentId,
SourceLocation NameLoc,
VisibilityAttr::Default);
}
+void Sema::ActOnPragmaMap(IdentifierInfo *IdentId, SourceLocation NameLoc,
+ Scope *curScope, const StringRef MappedName) {
+ assert(!MappedName.empty());
+
+ // All identifiers must be in UTF-8. On z/OS the mapped name was parsed with
+ // CA_ToLiteralEncodingForAsm, so it is in IBM-1047 and must be converted
back.
+ llvm::SmallString<16> MappedNameUTF;
+ if (llvm::TextEncodingConverter *Conv =
+ PP.getTextEncoding().getzOSFromAsmLiteralEncodingConverter()) {
+ [[maybe_unused]] std::error_code EC =
+ Conv->convert(MappedName, MappedNameUTF);
+ assert(!EC && "This conversion should always succeed");
+ } else {
+ MappedNameUTF = MappedName;
+ }
+
+ AttributeCommonInfo AttrInfo(IdentId, NameLoc,
+ AttributeCommonInfo::Form::Pragma());
+ AsmLabelAttr *Attr =
+ AsmLabelAttr::CreateImplicit(Context, MappedNameUTF.str(), AttrInfo);
+
+ PendingPragmaMapInfo Info;
+ Info.NameLoc = NameLoc;
+ Info.Attr = Attr;
+ Info.Used = false;
+
+ NamedDecl *PrevDecl =
+ lookupExternCFunctionOrVariable(IdentId, NameLoc, curScope);
+ if (!PrevDecl) {
+ LoadExternalMappedUndeclaredIdentifiers();
+ auto PendingName = PendingMappedNames.find(IdentId);
+ if (PendingName != PendingMappedNames.end()) {
+ auto &Info = PendingName->second;
+ if (!Info.Attr->isEquivalent(Attr)) {
+ Diag(NameLoc, diag::warn_pragma_different_asm_label) << IdentId;
+ return;
+ }
+ }
+ PendingMappedNames[IdentId] = Info;
----------------
kazutakahirata wrote:
`PendingMappedNames` is currently looked up twice via `find` and `operator[]`.
Could we use `try_emplace` to combine the two lookups?
```suggestion
auto [It, Inserted] = PendingMappedNames.try_emplace(IdentId, Info);
if (!Inserted) {
if (!It->second.Attr->isEquivalent(Attr)) {
Diag(NameLoc, diag::warn_pragma_different_asm_label) << IdentId;
return;
}
It->second = Info;
}
```
https://github.com/llvm/llvm-project/pull/243723
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits