1 // RUN: %clang_cc1 -no-opaque-pointers -fobjc-runtime=macosx-10.10.0 -emit-llvm -o - %s -fno-objc-convert-messages-to-runtime-calls -fobjc-exceptions -fexceptions | FileCheck %s --check-prefix=MSGS
2 // RUN: %clang_cc1 -no-opaque-pointers -fobjc-runtime=macosx-10.10.0 -emit-llvm -o - %s -fobjc-exceptions -fexceptions | FileCheck %s --check-prefix=CALLS
3 // RUN: %clang_cc1 -no-opaque-pointers -fobjc-runtime=macosx-10.9.0 -emit-llvm -o - %s -fobjc-exceptions -fexceptions | FileCheck %s --check-prefix=MSGS
4 // RUN: %clang_cc1 -no-opaque-pointers -fobjc-runtime=macosx-fragile-10.10.0 -emit-llvm -o - %s -fobjc-exceptions -fexceptions | FileCheck %s --check-prefix=MSGS
5 // RUN: %clang_cc1 -no-opaque-pointers -fobjc-runtime=ios-8.0 -emit-llvm -o - %s -fobjc-exceptions -fexceptions | FileCheck %s --check-prefix=CALLS
6 // RUN: %clang_cc1 -no-opaque-pointers -fobjc-runtime=ios-7.0 -emit-llvm -o - %s -fobjc-exceptions -fexceptions | FileCheck %s --check-prefix=MSGS
7 // Note: This line below is for tvos for which the driver passes through to use the ios9.0 runtime.
8 // RUN: %clang_cc1 -no-opaque-pointers -fobjc-runtime=ios-9.0 -emit-llvm -o - %s -fobjc-exceptions -fexceptions | FileCheck %s --check-prefix=CALLS
9 // RUN: %clang_cc1 -no-opaque-pointers -fobjc-runtime=watchos-2.0 -emit-llvm -o - %s -fobjc-exceptions -fexceptions | FileCheck %s --check-prefix=CALLS
15 + (id)allocWithZone:(void*)zone;
22 // CHECK-LABEL: define {{.*}}void @test1
24 // MSGS: {{call.*@objc_msgSend}}
25 // MSGS: {{call.*@objc_msgSend}}
26 // MSGS: {{call.*@objc_msgSend}}
27 // MSGS: {{call.*@objc_msgSend}}
28 // MSGS: {{call.*@objc_msgSend}}
29 // CALLS: {{call.*@objc_alloc}}
30 // CALLS: {{call.*@objc_allocWithZone}}
31 // CALLS: {{call.*@objc_retain}}
32 // CALLS: {{call.*@objc_release}}
33 // CALLS: {{tail call.*@objc_autorelease}}
35 [NSObject allocWithZone:nil];
41 // CHECK-LABEL: define {{.*}}void @check_invoke
42 void check_invoke(void) {
43 // MSGS: {{invoke.*@objc_msgSend}}
44 // MSGS: {{invoke.*@objc_msgSend}}
45 // CALLS: {{invoke.*@objc_alloc}}
46 // CALLS: {{invoke.*@objc_allocWithZone}}
49 [NSObject allocWithZone:nil];
54 // CHECK-LABEL: define {{.*}}void @test2
56 // MSGS: {{call.*@objc_msgSend}}
57 // MSGS: {{call.*@objc_msgSend}}
58 // MSGS: {{call.*@objc_msgSend}}
59 // CALLS: {{call.*@objc_msgSend}}
60 // CALLS: {{call.*@objc_msgSend}}
61 // CALLS: {{call.*@objc_msgSend}}
63 [NSObject allocWithZone:(void*)-1];
64 [NSObject allocWithZone:x];
70 + (A*) allocWithZone:(void*)zone;
72 - (A*) allocWithZone:(void*)zone;
77 // Make sure we get a bitcast on the return type as the
78 // call will return i8* which we have to cast to A*
79 // CHECK-LABEL: define {{.*}}void @test_alloc_class_ptr
80 A* test_alloc_class_ptr(void) {
81 // CALLS: {{call.*@objc_alloc}}
82 // CALLS-NEXT: bitcast i8*
87 // Make sure we get a bitcast on the return type as the
88 // call will return i8* which we have to cast to A*
89 // CHECK-LABEL: define {{.*}}void @test_alloc_class_ptr
90 A* test_allocWithZone_class_ptr(void) {
91 // CALLS: {{call.*@objc_allocWithZone}}
92 // CALLS-NEXT: bitcast i8*
94 return [B allocWithZone:nil];
97 // Only call objc_alloc on a Class, not an instance
98 // CHECK-LABEL: define {{.*}}void @test_alloc_instance
99 void test_alloc_instance(A *a) {
100 // CALLS: {{call.*@objc_alloc}}
101 // CALLS: {{call.*@objc_allocWithZone}}
102 // CALLS: {{call.*@objc_msgSend}}
103 // CALLS: {{call.*@objc_msgSend}}
105 [A allocWithZone:nil];
107 [a allocWithZone:nil];
110 // Make sure we get a bitcast on the return type as the
111 // call will return i8* which we have to cast to A*
112 // CHECK-LABEL: define {{.*}}void @test_retain_class_ptr
113 A* test_retain_class_ptr(B *b) {
114 // CALLS: {{call.*@objc_retain}}
115 // CALLS-NEXT: bitcast i8*
120 // Make sure we get a bitcast on the return type as the
121 // call will return i8* which we have to cast to A*
122 // CHECK-LABEL: define {{.*}}void @test_autorelease_class_ptr
123 A* test_autorelease_class_ptr(B *b) {
124 // CALLS: {{tail call.*@objc_autorelease}}
125 // CALLS-NEXT: bitcast i8*
127 return [b autorelease];
132 + (id)allocWithZone:(int)intArg;
136 // Make sure we only accept pointer types
137 // CHECK-LABEL: define {{.*}}void @test_allocWithZone_int
138 C* test_allocWithZone_int(void) {
139 // MSGS: {{call.*@objc_msgSend}}
140 // CALLS: {{call.*@objc_msgSend}}
141 return [C allocWithZone:3];
144 // Make sure we use a message and not a call as the return type is
145 // not a pointer type.
146 // CHECK-LABEL: define {{.*}}void @test_cannot_message_return_float
147 float test_cannot_message_return_float(C *c) {
148 // MSGS: {{call.*@objc_msgSend}}
149 // CALLS: {{call.*@objc_msgSend}}
154 + (instancetype)alloc;
155 + (instancetype)allocWithZone:(void*)zone;
160 @implementation TestSelf
161 // CHECK-LABEL: define internal i8* @"\01+[TestSelf classMeth]"(
163 // MSGS: {{call.*@objc_msgSend}}
164 // MSGS: {{call.*@objc_msgSend}}
165 // CALLS: {{call.*@objc_allocWithZone\(}}
166 // CALLS: {{call.*@objc_alloc\(}}
167 [self allocWithZone:nil];
170 // CHECK-LABEL: define internal i8* @"\01-[TestSelf instanceMeth]"(
172 // MSGS: {{call.*@objc_msgSend}}
173 // MSGS: {{call.*@objc_msgSend}}
174 // CALLS: {{call.*@objc_msgSend}}
175 // CALLS: {{call.*@objc_msgSend}}
176 [self allocWithZone:nil];
181 @interface NSString : NSObject
183 - (void)retain_super;
186 @implementation NSString
188 // Make sure we can convert a message to a dynamic receiver to a call
189 // CHECK-LABEL: define {{.*}}void @retain_self
190 + (void)retain_self {
191 // MSGS: {{call.*@objc_msgSend}}
192 // CALLS: {{call.*@objc_retain}}
196 // Make sure we never convert a message to super to a call
197 // CHECK-LABEL: define {{.*}}void @retain_super
198 - (void)retain_super {
199 // MSGS: {{call.*@objc_msgSend}}
200 // CALLS: {{call.*@objc_msgSend}}
208 // CHECK-LABEL: define {{.*}}void @testException_release
209 void testException_release(NSObject *a) {
210 // MSGS: {{invoke.*@objc_msgSend}}
211 // CALLS: invoke{{.*}}void @objc_release(i8* %
218 // CHECK-LABEL: define {{.*}}void @testException_autorelease
219 void testException_autorelease(NSObject *a) {
221 // MSGS: {{invoke.*@objc_msgSend}}
222 // CALLS: invoke{{.*}}objc_autorelease(i8* %
228 // CHECK-LABEL: define {{.*}}void @testException_retain
229 void testException_retain(NSObject *a) {
231 // MSGS: {{invoke.*@objc_msgSend}}
232 // CALLS: invoke{{.*}}@objc_retain(i8* %
239 // CHECK-LABEL: define {{.*}}void @testException_alloc(
240 void testException_alloc(void) {
242 // MSGS: {{invoke.*@objc_msgSend}}
243 // CALLS: invoke{{.*}}@objc_alloc(i8* %
249 // CHECK-LABEL: define {{.*}}void @testException_allocWithZone
250 void testException_allocWithZone(void) {
252 // MSGS: {{invoke.*@objc_msgSend}}
253 // CALLS: invoke{{.*}}@objc_allocWithZone(i8* %
254 [A allocWithZone:nil];