]> granicus.if.org Git - clang/commitdiff
ObjC++: decorate ObjC interfaces in MSABI properly
authorSaleem Abdulrasool <compnerd@compnerd.org>
Wed, 23 Aug 2017 22:38:58 +0000 (22:38 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Wed, 23 Aug 2017 22:38:58 +0000 (22:38 +0000)
`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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311617 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/MicrosoftMangle.cpp
test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm
test/CodeGenObjCXX/msabi-objc-types.mm [new file with mode: 0644]

index 24b16f892e7a9c12a19c48ed8687a668fd1206ab..5afaeef1eec0371ba8ad7de6b44ac31b475103c8 100644 (file)
@@ -2324,13 +2324,15 @@ void MicrosoftCXXNameMangler::mangleType(const PointerType *T, Qualifiers Quals,
   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(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);
+  mangleType(T->getBaseType(), Range, QMM_Drop);
 }
 
 void MicrosoftCXXNameMangler::mangleType(const BlockPointerType *T,
index 0b01b27fa799c15b46dbbb9b5bf978746a788b26..cb71bcf0aad31f896e154064d8fa836b300dae6c 100644 (file)
@@ -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@Z"
+// CHECK-LABEL: define void @"\01?test_arc_order@@YAXUA@@PAUobjc_object@@01@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@XZ"(%struct.A* %{{.*}})
diff --git a/test/CodeGenObjCXX/msabi-objc-types.mm b/test/CodeGenObjCXX/msabi-objc-types.mm
new file mode 100644 (file)
index 0000000..013a9c8
--- /dev/null
@@ -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
+
+@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@s@@QAAXPAUI@@@Z"
+
+  void m(const I *) {}
+  // CHECK-LABEL: "\01?m@s@@QAAXPBUI@@@Z"
+
+  void m(I &) {}
+  // CHECK-LABEL: "\01?m@s@@QAAXAAUI@@@Z"
+
+  void m(const I &) {}
+  // CHECK-LABEL: "\01?m@s@@QAAXABUI@@@Z"
+
+  void m(I &&) {}
+  // CHECK-LABEL: "\01?m@s@@QAAX$$QAUI@@@Z"
+
+  void m(const I &&) {}
+  // CHECK-LABEL: "\01?m@s@@QAAX$$QBUI@@@Z"
+
+  void m(id) {}
+  // CHECK-LABEL: "\01?m@s@@QAAXPAUobjc_object@@@Z"
+
+  void m(id &) {}
+  // CHECK-LABEL: "\01?m@s@@QAAXAAPAUobjc_object@@@Z"
+
+  void m(id &&) {}
+  // CHECK-LABEL: "\01?m@s@@QAAX$$QAPAUobjc_object@@@Z"
+
+  void m(const id &) {}
+  // CHECK-LABEL: "\01?m@s@@QAAXABPAUobjc_object@@@Z"
+
+  void m(const id &&) {}
+  // CHECK-LABEL: "\01?m@s@@QAAX$$QBPAUobjc_object@@@Z"
+
+  void m(Class *) {}
+  // CHECK-LABEL: "\01?m@s@@QAAXPAPAUobjc_class@@@Z"
+
+  void m(const Class *) {}
+  // CHECK-LABEL: "\01?m@s@@QAAXPBPAUobjc_class@@@Z"
+
+  void m(Class) {}
+  // CHECK-LABEL: "\01?m@s@@QAAXPAUobjc_class@@@Z"
+
+  void m(Class &) {}
+  // CHECK-LABEL: "\01?m@s@@QAAXAAPAUobjc_class@@@Z"
+
+  void m(const Class &) {}
+  // CHECK-LABEL: "\01?m@s@@QAAXABPAUobjc_class@@@Z"
+
+  void m(Class &&) {}
+  // CHECK-LABEL: "\01?m@s@@QAAX$$QAPAUobjc_class@@@Z"
+
+  void m(const Class &&) {}
+  // CHECK-LABEL: "\01?m@s@@QAAX$$QBPAUobjc_class@@@Z"
+};
+