AST: add missing ObjC extensions to MS style name decoration
Add support for encoding type arguments for lightweight generics in
Objective-C++ mode. Additionally, add support for the `__kindof` modifier.
This should complete the coverage of the ObjC extensions that clang currently
supports under the MS style name decoration scheme.
This is implemented similar to the Objective-C lifetime qualifiers decoration:
a template specialization in the `__ObjC` namespace so that we can interoperate
with Microsoft's tools as well as ensure that we do not accidentally collide
with new features in the Microsoft implementation.
Since the `__kindof` appertains to the type and not the pointer, we apply the
template specialization to the underlying type instead of the pointer type.
Unfortunately, until D52581 is resolved, the generated name is not really
compatible with the MS tools as well as breaks interoperability with
Objective-C++ and C++.
This resolves PR37754!
llvm-svn: 343338
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index 6f1a1f4..1d4bdaa 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -375,6 +375,8 @@
void mangleObjCProtocol(const ObjCProtocolDecl *PD);
void mangleObjCLifetime(const QualType T, Qualifiers Quals,
SourceRange Range);
+ void mangleObjCKindOfType(const ObjCObjectType *T, Qualifiers Quals,
+ SourceRange Range);
};
}
@@ -1553,6 +1555,23 @@
mangleArtificalTagType(TTK_Struct, TemplateMangling, {"__ObjC"});
}
+void MicrosoftCXXNameMangler::mangleObjCKindOfType(const ObjCObjectType *T,
+ Qualifiers Quals,
+ SourceRange Range) {
+ llvm::SmallString<64> TemplateMangling;
+ llvm::raw_svector_ostream Stream(TemplateMangling);
+ MicrosoftCXXNameMangler Extra(Context, Stream);
+
+ Stream << "?$";
+ Extra.mangleSourceName("KindOf");
+ Extra.mangleType(QualType(T, 0)
+ .stripObjCKindOfType(getASTContext())
+ ->getAs<ObjCObjectType>(),
+ Quals, Range);
+
+ mangleArtificalTagType(TTK_Struct, TemplateMangling, {"__ObjC"});
+}
+
void MicrosoftCXXNameMangler::mangleQualifiers(Qualifiers Quals,
bool IsMember) {
// <cvr-qualifiers> ::= [E] [F] [I] <base-cvr-qualifiers>
@@ -2624,9 +2643,12 @@
mangle(T->getDecl(), ".objc_cls_");
}
-void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T, Qualifiers,
- SourceRange Range) {
- if (T->qual_empty())
+void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T,
+ Qualifiers Quals, SourceRange Range) {
+ if (T->isKindOfType())
+ return mangleObjCKindOfType(T, Quals, Range);
+
+ if (T->qual_empty() && !T->isSpecialized())
return mangleType(T->getBaseType(), Range, QMM_Drop);
ArgBackRefMap OuterArgsContext;
@@ -2647,6 +2669,11 @@
for (const auto &Q : T->quals())
mangleObjCProtocol(Q);
+
+ if (T->isSpecialized())
+ for (const auto &TA : T->getTypeArgs())
+ mangleType(TA, Range, QMM_Drop);
+
Out << '@';
Out << '@';