r311617 - ObjC++: decorate ObjC interfaces in MSABI properly

Saleem Abdulrasool via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 23 15:38:58 PDT 2017


Author: compnerd
Date: Wed Aug 23 15:38:58 2017
New Revision: 311617

URL: http://llvm.org/viewvc/llvm-project?rev=311617&view=rev
Log:
ObjC++: decorate ObjC interfaces in MSABI properly

`id` needs to be handled specially since it is a `TypedefType` which is
sugar for an `ObjCObjectPointerType` whose pointee is an
`ObjCObjectType` with base `BuiltinType::ObjCIdType` and no protocols
and the first level of pointer gets it own type implementation.  `Class`
is similar with the `ObjCClassType` as the base instead.

The qualifiers on the base type of the `ObjCObjectType` need to be
dropped because the innermost `mangleType` will handle the qualifiers
itself.

`id` is desugared to `struct objc_object *` which should be encoded as
`PAUobjc_object@@`.  `Class` is desugared to `struct objc_class *` which
should be encoded as `PAUobjc_class@@`.

We were previously applying an extra modifier `A` which will be handled
during the recursive call.

This now properly decorates interface types as well as `Class` and `id`.
This corrects the interactions between C++ and ObjC++ for the type
specifier decoration.

Added:
    cfe/trunk/test/CodeGenObjCXX/msabi-objc-types.mm
Modified:
    cfe/trunk/lib/AST/MicrosoftMangle.cpp
    cfe/trunk/test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=311617&r1=311616&r2=311617&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Wed Aug 23 15:38:58 2017
@@ -2324,13 +2324,15 @@ void MicrosoftCXXNameMangler::mangleType
   manglePointerExtQualifiers(Quals, PointeeType);
   mangleType(PointeeType, Range);
 }
+
 void MicrosoftCXXNameMangler::mangleType(const ObjCObjectPointerType *T,
                                          Qualifiers Quals, SourceRange Range) {
+  if (T->isObjCIdType() || T->isObjCClassType())
+    return mangleType(T->getPointeeType(), Range, QMM_Drop);
+
   QualType PointeeType = T->getPointeeType();
   manglePointerCVQualifiers(Quals);
   manglePointerExtQualifiers(Quals, PointeeType);
-  // Object pointers never have qualifiers.
-  Out << 'A';
   mangleType(PointeeType, Range);
 }
 
@@ -2438,7 +2440,7 @@ void MicrosoftCXXNameMangler::mangleType
                                          SourceRange Range) {
   // We don't allow overloading by different protocol qualification,
   // so mangling them isn't necessary.
-  mangleType(T->getBaseType(), Range);
+  mangleType(T->getBaseType(), Range, QMM_Drop);
 }
 
 void MicrosoftCXXNameMangler::mangleType(const BlockPointerType *T,

Modified: cfe/trunk/test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm?rev=311617&r1=311616&r2=311617&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm Wed Aug 23 15:38:58 2017
@@ -9,7 +9,7 @@ struct A {
 
 // Verify that we destruct things from left to right in the MS C++ ABI: a, b, c, d.
 //
-// CHECK-LABEL: define void @"\01?test_arc_order@@YAXUA@@PAAAPAUobjc_object@@01 at Z"
+// CHECK-LABEL: define void @"\01?test_arc_order@@YAXUA@@PAUobjc_object@@01 at Z"
 // CHECK:                       (<{ %struct.A, i8*, %struct.A, i8* }>* inalloca)
 void test_arc_order(A a, id __attribute__((ns_consumed)) b , A c, id __attribute__((ns_consumed)) d) {
   // CHECK: call x86_thiscallcc void @"\01??1A@@QAE at XZ"(%struct.A* %{{.*}})

Added: cfe/trunk/test/CodeGenObjCXX/msabi-objc-types.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/msabi-objc-types.mm?rev=311617&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/msabi-objc-types.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/msabi-objc-types.mm Wed Aug 23 15:38:58 2017
@@ -0,0 +1,122 @@
+// RUN: %clang_cc1 -triple thumbv7-windows-msvc -fdeclspec -std=c++11 -fobjc-runtime=ios-6.0 -o - -emit-llvm %s | FileCheck %s
+
+ at class I;
+
+id kid;
+// CHECK: @"\01?kid@@3PAUobjc_object@@A" = global
+
+Class klass;
+// CHECK: @"\01?klass@@3PAUobjc_class@@A" = global
+
+I *kI;
+// CHECK: @"\01?kI@@3PAUI@@A" = global
+
+void f(I *) {}
+// CHECK-LABEL: "\01?f@@YAXPAUI@@@Z"
+
+void f(const I *) {}
+// CHECK-LABEL: "\01?f@@YAXPBUI@@@Z"
+
+void f(I &) {}
+// CHECK-LABEL: "\01?f@@YAXAAUI@@@Z"
+
+void f(const I &) {}
+// CHECK-LABEL: "\01?f@@YAXABUI@@@Z"
+
+void f(const I &&) {}
+// CHECK-LABEL: "\01?f@@YAX$$QBUI@@@Z"
+
+void g(id) {}
+// CHECK-LABEL: "\01?g@@YAXPAUobjc_object@@@Z"
+
+void g(id &) {}
+// CHECK-LABEL: "\01?g@@YAXAAPAUobjc_object@@@Z"
+
+void g(const id &) {}
+// CHECK-LABEL: "\01?g@@YAXABPAUobjc_object@@@Z"
+
+void g(id &&) {}
+// CHECK-LABEL: "\01?g@@YAX$$QAPAUobjc_object@@@Z"
+
+void h(Class) {}
+// CHECK-LABEL: "\01?h@@YAXPAUobjc_class@@@Z"
+
+void h(Class &) {}
+// CHECK-LABEL: "\01?h@@YAXAAPAUobjc_class@@@Z"
+
+void h(const Class &) {}
+// CHECK-LABEL: "\01?h@@YAXABPAUobjc_class@@@Z"
+
+void h(Class &&) {}
+// CHECK-LABEL: "\01?h@@YAX$$QAPAUobjc_class@@@Z"
+
+I *i() { return nullptr; }
+// CHECK-LABEL: "\01?i@@YAPAUI@@XZ"
+
+const I *j() { return nullptr; }
+// CHECK-LABEL: "\01?j@@YAPBUI@@XZ"
+
+I &k() { return *kI; }
+// CHECK-LABEL: "\01?k@@YAAAUI@@XZ"
+
+const I &l() { return *kI; }
+// CHECK-LABEL: "\01?l@@YAABUI@@XZ"
+
+struct __declspec(dllexport) s {
+  struct s &operator=(const struct s &) = delete;
+
+  void m(I *) {}
+  // CHECK-LABEL: "\01?m at s@@QAAXPAUI@@@Z"
+
+  void m(const I *) {}
+  // CHECK-LABEL: "\01?m at s@@QAAXPBUI@@@Z"
+
+  void m(I &) {}
+  // CHECK-LABEL: "\01?m at s@@QAAXAAUI@@@Z"
+
+  void m(const I &) {}
+  // CHECK-LABEL: "\01?m at s@@QAAXABUI@@@Z"
+
+  void m(I &&) {}
+  // CHECK-LABEL: "\01?m at s@@QAAX$$QAUI@@@Z"
+
+  void m(const I &&) {}
+  // CHECK-LABEL: "\01?m at s@@QAAX$$QBUI@@@Z"
+
+  void m(id) {}
+  // CHECK-LABEL: "\01?m at s@@QAAXPAUobjc_object@@@Z"
+
+  void m(id &) {}
+  // CHECK-LABEL: "\01?m at s@@QAAXAAPAUobjc_object@@@Z"
+
+  void m(id &&) {}
+  // CHECK-LABEL: "\01?m at s@@QAAX$$QAPAUobjc_object@@@Z"
+
+  void m(const id &) {}
+  // CHECK-LABEL: "\01?m at s@@QAAXABPAUobjc_object@@@Z"
+
+  void m(const id &&) {}
+  // CHECK-LABEL: "\01?m at s@@QAAX$$QBPAUobjc_object@@@Z"
+
+  void m(Class *) {}
+  // CHECK-LABEL: "\01?m at s@@QAAXPAPAUobjc_class@@@Z"
+
+  void m(const Class *) {}
+  // CHECK-LABEL: "\01?m at s@@QAAXPBPAUobjc_class@@@Z"
+
+  void m(Class) {}
+  // CHECK-LABEL: "\01?m at s@@QAAXPAUobjc_class@@@Z"
+
+  void m(Class &) {}
+  // CHECK-LABEL: "\01?m at s@@QAAXAAPAUobjc_class@@@Z"
+
+  void m(const Class &) {}
+  // CHECK-LABEL: "\01?m at s@@QAAXABPAUobjc_class@@@Z"
+
+  void m(Class &&) {}
+  // CHECK-LABEL: "\01?m at s@@QAAX$$QAPAUobjc_class@@@Z"
+
+  void m(const Class &&) {}
+  // CHECK-LABEL: "\01?m at s@@QAAX$$QBPAUobjc_class@@@Z"
+};
+




More information about the cfe-commits mailing list