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
This commit is contained in:
Saleem Abdulrasool 2018-09-28 16:47:53 +00:00
parent 29b2980159
commit f3a981e801
2 changed files with 62 additions and 3 deletions

View File

@ -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::mangleObjCLifetime(const QualType Type,
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(const ObjCInterfaceType *T, Qualifiers,
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(const ObjCObjectType *T, Qualifiers,
for (const auto &Q : T->quals())
mangleObjCProtocol(Q);
if (T->isSpecialized())
for (const auto &TA : T->getTypeArgs())
mangleType(TA, Range, QMM_Drop);
Out << '@';
Out << '@';

View File

@ -4,6 +4,7 @@
@protocol Q;
@class I;
@class J<T>;
void f(id<P>, id, id<P>, id) {}
// CHECK-LABEL: "?f@@YAXPAU?$.objc_object@U?$Protocol@UP@@@__ObjC@@@@PAU.objc_object@@01@Z"
@ -64,3 +65,34 @@ S<__autoreleasing id> g() { return S<__autoreleasing id>(); }
__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@U.objc_cls_I@@@__ObjC@@@Z"
void f(__kindof I<P> *) {}
// CHECK-LABEL: "?f@@YAXPAU?$KindOf@U?$.objc_cls_I@U?$Protocol@UP@@@__ObjC@@@@@__ObjC@@@Z"
void f(S<I *>) {}
// CHECK-LABEL: "?f@@YAXU?$S@U?$Strong@PAU.objc_cls_I@@@__ObjC@@@@@Z"
void f(S<__kindof I *>) {}
// CHECK-LABEL: "?f@@YAXU?$S@U?$Strong@PAU?$KindOf@U.objc_cls_I@@@__ObjC@@@__ObjC@@@@@Z"
void f(S<__kindof I<P> *>) {}
// CHECK-LABEL: "?f@@YAXU?$S@U?$Strong@PAU?$KindOf@U?$.objc_cls_I@U?$Protocol@UP@@@__ObjC@@@@@__ObjC@@@__ObjC@@@@@Z"
void f(S<__weak __kindof I *>) {}
// CHECK-LABEL: "?f@@YAXU?$S@U?$Weak@PAU?$KindOf@U.objc_cls_I@@@__ObjC@@@__ObjC@@@@@Z"
void f(S<__weak __kindof I<P> *>) {}
// CHECK-LABEL: "?f@@YAXU?$S@U?$Weak@PAU?$KindOf@U?$.objc_cls_I@U?$Protocol@UP@@@__ObjC@@@@@__ObjC@@@__ObjC@@@@@Z"
void f(J<I *> *) {}
// CHECK-LABEL: "?f@@YAXPAU?$.objc_cls_J@PAU.objc_cls_I@@@@@Z"
void f(J<__kindof I *> *) {}
// CHECK-LABEL: "?f@@YAXPAU?$.objc_cls_J@PAU?$KindOf@U.objc_cls_I@@@__ObjC@@@@@Z"