r323547 - AST: support protocol conformances on id/class/interfaces in MS ABI

Saleem Abdulrasool via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 26 11:08:26 PST 2018


Author: compnerd
Date: Fri Jan 26 11:08:26 2018
New Revision: 323547

URL: http://llvm.org/viewvc/llvm-project?rev=323547&view=rev
Log:
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.

Added:
    cfe/trunk/test/CodeGenObjCXX/msabi-protocol-conformance.mm
Modified:
    cfe/trunk/lib/AST/MicrosoftMangle.cpp

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=323547&r1=323546&r2=323547&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Fri Jan 26 11:08:26 2018
@@ -2450,9 +2450,36 @@ void MicrosoftCXXNameMangler::mangleType
 
 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,

Added: cfe/trunk/test/CodeGenObjCXX/msabi-protocol-conformance.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/msabi-protocol-conformance.mm?rev=323547&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/msabi-protocol-conformance.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/msabi-protocol-conformance.mm Fri Jan 26 11:08:26 2018
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple thumbv7-windows-msvc -fobjc-runtime=ios-6.0 -o - -emit-llvm %s | FileCheck %s
+
+ at protocol P;
+ at protocol Q;
+
+ at class I;
+
+void f(id<P>, id, id<P>, id) {}
+// CHECK-LABEL: "\01?f@@YAXPAU?$objc_object at YP@@@@PAUobjc_object@@01 at Z"
+
+void f(id, id<P>, id<P>, id) {}
+// CHECK-LABEL: "\01?f@@YAXPAUobjc_object@@PAU?$objc_object at YP@@@@10 at Z"
+
+void f(id<P>, id<P>) {}
+// CHECK-LABEL: "\01?f@@YAXPAU?$objc_object at YP@@@@0 at Z"
+
+void f(id<P>) {}
+// CHECK-LABEL: "\01?f@@YAXPAU?$objc_object at YP@@@@@Z"
+
+void f(id<P, Q>) {}
+// CHECK-LABEL: "\01?f@@YAXPAU?$objc_object at YP@@YQ@@@@@Z"
+
+void f(Class<P>) {}
+// CHECK-LABEL: "\01?f@@YAXPAU?$objc_class at YP@@@@@Z"
+
+void f(Class<P, Q>) {}
+// CHECK-LABEL: "\01?f@@YAXPAU?$objc_class at YP@@YQ@@@@@Z"
+
+void f(I<P> *) {}
+// CHECK-LABEL: "\01?f@@YAXPAU?$I at YP@@@@@Z"
+
+void f(I<P, Q> *) {}
+// CHECK-LABEL: "\01?f@@YAXPAU?$I at YP@@YQ@@@@@Z"
+




More information about the cfe-commits mailing list