[PATCH] D42614: AST: support ObjC lifetime qualifiers in MS ABI
Saleem Abdulrasool via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 27 10:30:14 PST 2018
compnerd created this revision.
compnerd added a reviewer: rjmccall.
Herald added a subscriber: cfe-commits.
Add support for Objective C lifetime qualifiers in MS ABI. Because
there is no formal way to add a custom extension on a pointer qualifier,
re-use C++/CX (which is deprecated) and C++/CLI manglings to provide a
decoration.
We map the lifetimes as the following:
- none/explicitly none (__unsafe_unretained) as having no extended qualifier
- strong (__strong) as having cli::pin_ptr<T>
- weak (__weak) as a C++/CX tracking ref
- autorealeasing (__autoreleasing) as having a C++/CX ref
One side effect of this change is that the decoration of normal
functions is altered with the implicit lifetime qualifier (__strong)
where it is not needed since functions cannot be overloaded on just the
lifetime qualifier.
Repository:
rC Clang
https://reviews.llvm.org/D42614
Files:
lib/AST/MicrosoftMangle.cpp
test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm
test/CodeGenObjCXX/msabi-objc-lifetimes.mm
Index: test/CodeGenObjCXX/msabi-objc-lifetimes.mm
===================================================================
--- /dev/null
+++ test/CodeGenObjCXX/msabi-objc-lifetimes.mm
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple thumbv7-windows-msvc -fobjc-arc -fobjc-runtime=ios-6.0 -o - -emit-llvm %s | FileCheck %s
+
+template <typename T>
+struct S {};
+
+void f(S<__unsafe_unretained id>) {}
+// CHECK-LABEL: "\01?f@@YAXU?$S at PAUobjc_object@@@@@Z"
+
+void f(S<__autoreleasing id>) {}
+// CHECK-LABEL: "\01?f@@YAXU?$S at P$AAUobjc_object@@@@@Z"
+
+void f(S<__strong id>) {}
+// CHECK-LABEL: "\01?f@@YAXU?$S at P$BAUobjc_object@@@@@Z"
+
+void f(S<__weak id>) {}
+// CHECK-LABEL: "\01?f@@YAXU?$S at P$CAUobjc_object@@@@@Z"
+
Index: test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm
===================================================================
--- test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm
+++ test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm
@@ -9,9 +9,9 @@
// 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@@PAUobjc_object@@01 at Z"
+// CHECK-LABEL: define void @"\01?test_arc_order@@YAXUA@@P$BAUobjc_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) {
+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* %{{.*}})
// CHECK: call void @objc_storeStrong(i8** %{{.*}}, i8* null)
// CHECK: call x86_thiscallcc void @"\01??1A@@QAE at XZ"(%struct.A* %{{.*}})
Index: lib/AST/MicrosoftMangle.cpp
===================================================================
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -1569,6 +1569,21 @@
if (Quals.hasUnaligned() ||
(!PointeeType.isNull() && PointeeType.getLocalQualifiers().hasUnaligned()))
Out << 'F';
+
+ switch (Quals.getObjCLifetime()) {
+ case Qualifiers::OCL_None:
+ case Qualifiers::OCL_ExplicitNone:
+ break;
+ case Qualifiers::OCL_Autoreleasing:
+ Out << "$A"; // C++/CX Ref Parameter
+ break;
+ case Qualifiers::OCL_Strong:
+ Out << "$B"; // C++/CLI cli::pin_ptr<T>
+ break;
+ case Qualifiers::OCL_Weak:
+ Out << "$C"; // C++/CX Tracking Ref Parameter
+ break;
+ }
}
void MicrosoftCXXNameMangler::manglePointerCVQualifiers(Qualifiers Quals) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42614.131687.patch
Type: text/x-patch
Size: 2540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180127/98ef3c27/attachment.bin>
More information about the cfe-commits
mailing list