summaryrefslogtreecommitdiff
path: root/lib/AST/MicrosoftMangle.cpp
diff options
context:
space:
mode:
authorSaleem Abdulrasool <compnerd@compnerd.org>2018-01-26 19:08:26 +0000
committerSaleem Abdulrasool <compnerd@compnerd.org>2018-01-26 19:08:26 +0000
commit71f3942a168f5298872a359d4cf9be2da98223b3 (patch)
tree11ada541031842c5e797aef7b1999afa57ea51f7 /lib/AST/MicrosoftMangle.cpp
parent6ff69520b3d28bb7c4e882fdc18ff97032a5a567 (diff)
downloadclang-71f3942a168f5298872a359d4cf9be2da98223b3.tar.gz
AST: support protocol conformances on id/class/interfaces in MS ABI
Add support for mangling ObjC protocol conformances in MS ABI as if they are COM interfaces. By diverging from the itanium mangling of `objc_protocol` prefixed names, this approach allows for a semi-reasonable, albeit of questionable sanity, undecoration via existing tooling. There is also the possibility of adding an extension and taking part of the namespace to add the conformance via the `L` and `Z` "modifiers", but the existing tooling would not be able to properly undecorated the symbol even though incidentally `undname` currently produces something legible while wine's implementation is not able to cope with the extension. This allows for the disambiguation of overloads where the parameter differs only in the protocol conformance of the ObjC type, e.g. ``` @protocol P; void f(std::vector<id>); void f(std::vector<id<P>>); ``` which clang would previously fail due to the mangling being identical as the protocol conformance was ignored. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@323547 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/MicrosoftMangle.cpp')
-rw-r--r--lib/AST/MicrosoftMangle.cpp33
1 files changed, 30 insertions, 3 deletions
diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp
index 81bdb6708d..9b395a7a11 100644
--- a/lib/AST/MicrosoftMangle.cpp
+++ b/lib/AST/MicrosoftMangle.cpp
@@ -2450,9 +2450,36 @@ void MicrosoftCXXNameMangler::mangleType(const ObjCInterfaceType *T, Qualifiers,
void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T, Qualifiers,
SourceRange Range) {
- // We don't allow overloading by different protocol qualification,
- // so mangling them isn't necessary.
- mangleType(T->getBaseType(), Range, QMM_Drop);
+ if (T->qual_empty())
+ return mangleType(T->getBaseType(), Range, QMM_Drop);
+
+ ArgBackRefMap OuterArgsContext;
+ BackRefVec OuterTemplateContext;
+
+ TypeBackReferences.swap(OuterArgsContext);
+ NameBackReferences.swap(OuterTemplateContext);
+
+ mangleTagTypeKind(TTK_Struct);
+
+ Out << "?$";
+ if (T->isObjCId())
+ mangleSourceName("objc_object");
+ else if (T->isObjCClass())
+ mangleSourceName("objc_class");
+ else
+ mangleSourceName(T->getInterface()->getName());
+
+ for (const auto &Q : T->quals()) {
+ Out << 'Y'; // cointerface
+ mangleSourceName(Q->getName());
+ Out << '@';
+ }
+ Out << '@';
+
+ Out << '@';
+
+ TypeBackReferences.swap(OuterArgsContext);
+ NameBackReferences.swap(OuterTemplateContext);
}
void MicrosoftCXXNameMangler::mangleType(const BlockPointerType *T,