r343338 - AST: add missing ObjC extensions to MS style name decoration
Saleem Abdulrasool via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 28 09:47:53 PDT 2018
Author: compnerd
Date: Fri Sep 28 09:47:53 2018
New Revision: 343338
URL: http://llvm.org/viewvc/llvm-project?rev=343338&view=rev
Log:
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!
Modified:
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/test/CodeGenObjCXX/msabi-objc-extensions.mm
Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=343338&r1=343337&r2=343338&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Fri Sep 28 09:47:53 2018
@@ -375,6 +375,8 @@ private:
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 @@ void MicrosoftCXXNameMangler::mangleObjC
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 @@ void MicrosoftCXXNameMangler::mangleType
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 @@ void MicrosoftCXXNameMangler::mangleType
for (const auto &Q : T->quals())
mangleObjCProtocol(Q);
+
+ if (T->isSpecialized())
+ for (const auto &TA : T->getTypeArgs())
+ mangleType(TA, Range, QMM_Drop);
+
Out << '@';
Out << '@';
Modified: cfe/trunk/test/CodeGenObjCXX/msabi-objc-extensions.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/msabi-objc-extensions.mm?rev=343338&r1=343337&r2=343338&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/msabi-objc-extensions.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/msabi-objc-extensions.mm Fri Sep 28 09:47:53 2018
@@ -4,6 +4,7 @@
@protocol Q;
@class I;
+ at class J<T>;
void f(id<P>, id, id<P>, id) {}
// CHECK-LABEL: "?f@@YAXPAU?$.objc_object at U?$Protocol at UP@@@__ObjC@@@@PAU.objc_object@@01 at Z"
@@ -64,3 +65,34 @@ S<__autoreleasing id> g() { return S<__a
__autoreleasing id h() { return nullptr; }
// CHECK-LABEL: "?h@@YAPAU.objc_object@@XZ"
+
+void f(I *) {}
+// CHECK-LABEL: "?f@@YAXPAU.objc_cls_I@@@Z"
+
+void f(__kindof I *) {}
+// CHECK-LABEL: "?f@@YAXPAU?$KindOf at U.objc_cls_I@@@__ObjC@@@Z"
+
+void f(__kindof I<P> *) {}
+// CHECK-LABEL: "?f@@YAXPAU?$KindOf at U?$.objc_cls_I at U?$Protocol at UP@@@__ObjC@@@@@__ObjC@@@Z"
+
+void f(S<I *>) {}
+// CHECK-LABEL: "?f@@YAXU?$S at U?$Strong at PAU.objc_cls_I@@@__ObjC@@@@@Z"
+
+void f(S<__kindof I *>) {}
+// CHECK-LABEL: "?f@@YAXU?$S at U?$Strong at PAU?$KindOf at U.objc_cls_I@@@__ObjC@@@__ObjC@@@@@Z"
+
+void f(S<__kindof I<P> *>) {}
+// CHECK-LABEL: "?f@@YAXU?$S at U?$Strong at PAU?$KindOf at U?$.objc_cls_I at U?$Protocol at UP@@@__ObjC@@@@@__ObjC@@@__ObjC@@@@@Z"
+
+void f(S<__weak __kindof I *>) {}
+// CHECK-LABEL: "?f@@YAXU?$S at U?$Weak at PAU?$KindOf at U.objc_cls_I@@@__ObjC@@@__ObjC@@@@@Z"
+
+void f(S<__weak __kindof I<P> *>) {}
+// CHECK-LABEL: "?f@@YAXU?$S at U?$Weak at PAU?$KindOf at U?$.objc_cls_I at U?$Protocol at UP@@@__ObjC@@@@@__ObjC@@@__ObjC@@@@@Z"
+
+void f(J<I *> *) {}
+// CHECK-LABEL: "?f@@YAXPAU?$.objc_cls_J at PAU.objc_cls_I@@@@@Z"
+
+void f(J<__kindof I *> *) {}
+// CHECK-LABEL: "?f@@YAXPAU?$.objc_cls_J at PAU?$KindOf at U.objc_cls_I@@@__ObjC@@@@@Z"
+
More information about the cfe-commits
mailing list