blob: 1db00affe8246beedf993864da23c51f2ae9990a [file] [log] [blame]
John McCalld1e40d52011-10-02 01:16:38 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -O2 -disable-llvm-optzns -o - %s | FileCheck %s
2// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=CHECK-GLOBALS %s
John McCallf85e1932011-06-15 23:02:42 +00003
4// CHECK: define void @test0
5void test0(id x) {
6 // CHECK: [[X:%.*]] = alloca i8*
7 // CHECK-NEXT: [[PARM:%.*]] = call i8* @objc_retain(i8* {{.*}})
8 // CHECK-NEXT: store i8* [[PARM]], i8** [[X]]
9 // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]]
10 // CHECK-NEXT: call void @objc_release(i8* [[TMP]])
11 // CHECK-NEXT: ret void
12}
13
14// CHECK: define i8* @test1(i8*
15id test1(id x) {
John McCallf48f7962012-01-29 02:35:02 +000016 // CHECK: [[X:%.*]] = alloca i8*
John McCallf85e1932011-06-15 23:02:42 +000017 // CHECK-NEXT: [[Y:%.*]] = alloca i8*
18 // CHECK-NEXT: alloca i32
19 // CHECK-NEXT: [[PARM:%.*]] = call i8* @objc_retain(i8* {{%.*}})
20 // CHECK-NEXT: store i8* [[PARM]], i8** [[X]]
21 // CHECK-NEXT: store i8* null, i8** [[Y]]
22 // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]]
John McCallf48f7962012-01-29 02:35:02 +000023 // CHECK-NEXT: [[RET:%.*]] = call i8* @objc_retain(i8* [[T0]])
John McCallf85e1932011-06-15 23:02:42 +000024 // CHECK-NEXT: store i32
25 // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]]
26 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
27 // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]]
28 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
John McCallf48f7962012-01-29 02:35:02 +000029 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_autoreleaseReturnValue(i8* [[RET]])
John McCallf85e1932011-06-15 23:02:42 +000030 // CHECK-NEXT: ret i8* [[T1]]
31 id y;
32 return y;
33}
34
35@interface Test2
36+ (void) class_method;
37- (void) inst_method;
38@end
39@implementation Test2
40
41// The self pointer of a class method is not retained.
42// CHECK: define internal void @"\01+[Test2 class_method]"
43// CHECK: alloca
44// CHECK-NEXT: alloca
45// CHECK-NEXT: store
46// CHECK-NEXT: store
47// CHECK-NEXT: ret void
48+ (void) class_method {}
49
50// The self pointer of an instance method is not retained.
51// CHECK: define internal void @"\01-[Test2 inst_method]"
52// CHECK: alloca
53// CHECK-NEXT: alloca
54// CHECK-NEXT: store
55// CHECK-NEXT: store
56// CHECK-NEXT: ret void
57- (void) inst_method {}
58@end
59
60@interface Test3
61+ (id) alloc;
62- (id) initWith: (int) x;
63- (id) copy;
64@end
65
66// CHECK: define void @test3_unelided()
67void test3_unelided() {
68 extern void test3_helper(void);
69
70 // CHECK: [[X:%.*]] = alloca [[TEST3:%.*]]*
71 // CHECK-NEXT: store [[TEST3]]* null, [[TEST3]]** [[X]], align
72 Test3 *x;
73
74 // Call to +alloc.
75 // CHECK-NEXT: load {{.*}}* @"\01L_OBJC_CLASSLIST_REFERENCES_
76 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
77 // CHECK-NEXT: bitcast
78 // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
79 // CHECK-NEXT: bitcast
80 // CHECK-NEXT: bitcast
81 // CHECK-NEXT: call void @objc_release(i8*
82 [Test3 alloc];
83
84 // CHECK-NEXT: [[T0:%.*]] = load [[TEST3]]** [[X]]
85 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
86 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST3]]* [[T0]] to i8*
87 // CHECK-NEXT: [[COPY:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend {{.*}})(i8* [[T1]],
88 // CHECK-NEXT: call void @objc_release(i8* [[COPY]]) nounwind
89 [x copy];
90
91 // CHECK-NEXT: [[T0:%.*]] = load [[TEST3]]** [[X]]
92 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST3]]* [[T0]] to i8*
93 // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind
94 // CHECK-NEXT: ret void
95}
96
97// CHECK: define void @test3()
98void test3() {
99 // CHECK: [[X:%.*]] = alloca i8*
100
101 id x = [[Test3 alloc] initWith: 5];
102
103 // Call to +alloc.
104 // CHECK-NEXT: load {{.*}}* @"\01L_OBJC_CLASSLIST_REFERENCES_
105 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
106 // CHECK-NEXT: bitcast
107 // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
108 // CHECK-NEXT: bitcast
109
110 // Call to -initWith: with elided retain of consumed argument.
111 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
112 // CHECK-NEXT: bitcast
113 // CHECK-NEXT: [[INIT:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i32)*)(i8*
114 // CHECK-NEXT: bitcast
115 // CHECK-NEXT: [[INIT:%.*]] = bitcast
116 // Assignment for initialization, retention elided.
117 // CHECK-NEXT: store i8* [[INIT]], i8** [[X]]
118
119 // Call to -copy.
120 // CHECK-NEXT: [[V:%.*]] = load i8** [[X]]
121 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
122 // CHECK-NEXT: [[COPY:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend {{.*}})(i8* [[V]],
123
124 // Assignment to x.
125 // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]]
126 // CHECK-NEXT: store i8* [[COPY]], i8** [[X]]
127 // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) nounwind
128
129 x = [x copy];
130
131 // Cleanup for x.
132 // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]]
133 // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) nounwind
134
135 // CHECK-NEXT: ret void
136}
137
138// CHECK: define i8* @test4()
139id test4() {
140 // Call to +alloc.
141 // CHECK: load {{.*}}* @"\01L_OBJC_CLASSLIST_REFERENCES_
142 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
143 // CHECK-NEXT: bitcast
144 // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
145 // CHECK-NEXT: [[ALLOC:%.*]] = bitcast
146
147 // Call to -initWith: with elided retain of consumed argument.
148 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
149 // CHECK-NEXT: [[ALLOC:%.*]] = bitcast
150 // CHECK-NEXT: [[INIT:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i32)*)(i8* [[ALLOC]],
151
152 // Initialization of return value, occuring within full-expression.
153 // Retain/release elided.
154 // CHECK-NEXT: bitcast
155 // CHECK-NEXT: [[INIT:%.*]] = bitcast
156 // CHECK-NEXT: [[RET:%.*]] = call i8* @objc_autoreleaseReturnValue(i8* [[INIT]])
157
158 // CHECK-NEXT: ret i8* [[RET]]
159
160 return [[Test3 alloc] initWith: 6];
161}
162
163@interface Test5 {
164@public
165 id var;
166}
167@end
168
169// CHECK: define void @test5
170void test5(Test5 *x, id y) {
171 // Prologue.
172 // CHECK: [[X:%.*]] = alloca [[TEST5:%.*]]*,
173 // CHECK-NEXT: [[Y:%.*]] = alloca i8*
174 // CHECK-NEXT: bitcast [[TEST5]]* {{%.*}} to i8*
175 // CHECK-NEXT: call i8* @objc_retain
176 // CHECK-NEXT: [[PARMX:%.*]] = bitcast i8* {{%.*}} to [[TEST5]]*
177 // CHECK-NEXT: store [[TEST5]]* [[PARMX]], [[TEST5]]** [[X]]
178 // CHECK-NEXT: call i8* @objc_retain
179 // CHECK-NEXT: store
180
181 // CHECK-NEXT: load [[TEST5]]** [[X]]
182 // CHECK-NEXT: load i64* @"OBJC_IVAR_$_Test5.var"
183 // CHECK-NEXT: bitcast
184 // CHECK-NEXT: getelementptr
185 // CHECK-NEXT: [[VAR:%.*]] = bitcast
186 // CHECK-NEXT: [[TMP:%.*]] = load i8** [[VAR]]
187 // CHECK-NEXT: store i8* null, i8** [[VAR]]
188 // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) nounwind
189 x->var = 0;
190
191 // CHECK-NEXT: [[YVAL:%.*]] = load i8** [[Y]]
192 // CHECK-NEXT: load [[TEST5]]** [[X]]
193 // CHECK-NEXT: load i64* @"OBJC_IVAR_$_Test5.var"
194 // CHECK-NEXT: bitcast
195 // CHECK-NEXT: getelementptr
196 // CHECK-NEXT: [[VAR:%.*]] = bitcast
197 // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* [[YVAL]]) nounwind
198 // CHECK-NEXT: [[TMP:%.*]] = load i8** [[VAR]]
199 // CHECK-NEXT: store i8* [[T0]], i8** [[VAR]]
200 // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) nounwind
201 x->var = y;
202
203 // Epilogue.
204 // CHECK-NEXT: [[TMP:%.*]] = load i8** [[Y]]
205 // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) nounwind
206 // CHECK-NEXT: [[T0:%.*]] = load [[TEST5]]** [[X]]
207 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST5]]* [[T0]] to i8*
208 // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind
209 // CHECK-NEXT: ret void
210}
211
212id test6_helper(void) __attribute__((ns_returns_retained));
213// CHECK: define void @test6()
214void test6() {
215 // CHECK: [[X:%.*]] = alloca i8*
216 // CHECK-NEXT: [[CALL:%.*]] = call i8* @test6_helper()
217 // CHECK-NEXT: store i8* [[CALL]], i8** [[X]]
218 // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]]
219 // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind, !clang.imprecise_release
220 // CHECK-NEXT: ret void
221 id x = test6_helper();
222}
223
224void test7_helper(id __attribute__((ns_consumed)));
225// CHECK: define void @test7()
226void test7() {
227 // CHECK: [[X:%.*]] = alloca i8*
228 // CHECK-NEXT: store i8* null, i8** [[X]]
229 // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]]
230 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) nounwind
231 // CHECK-NEXT: call void @test7_helper(i8* [[T1]])
232 // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]]
233 // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind, !clang.imprecise_release
234 // CHECK-NEXT: ret void
235 id x;
236 test7_helper(x);
237}
238
239id test8_helper(void) __attribute__((ns_returns_retained));
240void test8() {
241 __unsafe_unretained id x = test8_helper();
242 // CHECK: [[X:%.*]] = alloca i8*
243 // CHECK-NEXT: [[T0:%.*]] = call i8* @test8_helper()
244 // CHECK-NEXT: store i8* [[T0]], i8** [[X]]
245 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind
246 // CHECK-NOT: imprecise_release
247 // CHECK-NEXT: ret void
248}
249
250id test9_helper(void) __attribute__((ns_returns_retained));
251void test9() {
252 id x __attribute__((objc_precise_lifetime)) = test9_helper();
253 x = 0;
254 // CHECK: [[X:%.*]] = alloca i8*
255 // CHECK-NEXT: [[CALL:%.*]] = call i8* @test9_helper()
256 // CHECK-NEXT: store i8* [[CALL]], i8** [[X]]
257
258 // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]]
259 // CHECK-NEXT: store i8* null, i8** [[X]]
260 // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind, !clang.imprecise_release
261
262 // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]]
263 // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind
264 // CHECK-NOT: clang.imprecise_release
265
266 // CHECK-NEXT: ret void
267}
268
269@interface Test10
270@property (retain) Test10 *me;
271@end
272void test10() {
273 Test10 *x;
274 id y = x.me.me;
275
276 // CHECK: define void @test10()
277 // CHECK: [[X:%.*]] = alloca [[TEST10:%.*]]*, align
278 // CHECK-NEXT: [[Y:%.*]] = alloca i8*, align
279 // CHECK-NEXT: store [[TEST10]]* null, [[TEST10]]** [[X]]
280 // CHECK-NEXT: load [[TEST10]]** [[X]], align
281 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_{{[0-9]*}}"
282 // CHECK-NEXT: bitcast
John McCall7e5e5f42011-07-07 06:58:02 +0000283 // CHECK-NEXT: [[T0:%.*]] = call [[TEST10]]* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
284 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8*
285 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]])
286 // CHECK-NEXT: [[V:%.*]] = bitcast i8* [[T2]] to [[TEST10]]*
John McCallf85e1932011-06-15 23:02:42 +0000287 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_{{[0-9]*}}"
288 // CHECK-NEXT: bitcast
289 // CHECK-NEXT: [[T0:%.*]] = call [[TEST10]]* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
290 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8*
291 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]])
292 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST10]]*
293 // CHECK-NEXT: [[T4:%.*]] = bitcast [[TEST10]]* [[T3]] to i8*
294 // CHECK-NEXT: store i8* [[T4]], i8** [[Y]]
John McCall7e5e5f42011-07-07 06:58:02 +0000295 // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST10]]* [[V]] to i8*
296 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
John McCallf85e1932011-06-15 23:02:42 +0000297 // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]]
298 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
299 // CHECK-NEXT: [[T0:%.*]] = load [[TEST10]]** [[X]]
300 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8*
301 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
302 // CHECK-NEXT: ret void
303}
304
305void test11(id (*f)(void) __attribute__((ns_returns_retained))) {
306 // CHECK: define void @test11(
307 // CHECK: [[F:%.*]] = alloca i8* ()*, align
308 // CHECK-NEXT: [[X:%.*]] = alloca i8*, align
309 // CHECK-NEXT: store i8* ()* {{%.*}}, i8* ()** [[F]], align
310 // CHECK-NEXT: [[T0:%.*]] = load i8* ()** [[F]], align
311 // CHECK-NEXT: [[T1:%.*]] = call i8* [[T0]]()
312 // CHECK-NEXT: store i8* [[T1]], i8** [[X]], align
313 // CHECK-NEXT: [[T3:%.*]] = load i8** [[X]]
314 // CHECK-NEXT: call void @objc_release(i8* [[T3]]) nounwind, !clang.imprecise_release
315 // CHECK-NEXT: ret void
316 id x = f();
317}
318
319void test12(void) {
320 extern id test12_helper(void);
321
322 // CHECK: define void @test12()
323 // CHECK: [[X:%.*]] = alloca i8*, align
324 // CHECK-NEXT: [[Y:%.*]] = alloca i8*, align
325
326 __weak id x = test12_helper();
327 // CHECK-NEXT: [[T0:%.*]] = call i8* @test12_helper()
John McCall7e5e5f42011-07-07 06:58:02 +0000328 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
329 // CHECK-NEXT: call i8* @objc_initWeak(i8** [[X]], i8* [[T1]])
330 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +0000331
332 x = test12_helper();
John McCall7e5e5f42011-07-07 06:58:02 +0000333 // CHECK-NEXT: [[T0:%.*]] = call i8* @test12_helper()
334 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
John McCallf85e1932011-06-15 23:02:42 +0000335 // CHECK-NEXT: call i8* @objc_storeWeak(i8** [[X]], i8* [[T1]])
John McCall7e5e5f42011-07-07 06:58:02 +0000336 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +0000337
338 id y = x;
339 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_loadWeakRetained(i8** [[X]])
340 // CHECK-NEXT: store i8* [[T2]], i8** [[Y]], align
341
342 // CHECK-NEXT: [[T4:%.*]] = load i8** [[Y]]
343 // CHECK-NEXT: call void @objc_release(i8* [[T4]]) nounwind, !clang.imprecise_release
344 // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]])
345 // CHECK-NEXT: ret void
346}
347
348// Indirect consuming calls.
349void test13(void) {
350 // CHECK: define void @test13()
351 // CHECK: [[X:%.*]] = alloca i8*, align
352 // CHECK-NEXT: store i8* null, i8** [[X]], align
353 id x;
354
355 typedef void fnty(id __attribute__((ns_consumed)));
356 extern fnty *test13_func;
357 // CHECK-NEXT: [[FN:%.*]] = load void (i8*)** @test13_func, align
358 // CHECK-NEXT: [[X_VAL:%.*]] = load i8** [[X]], align
359 // CHECK-NEXT: [[X_TMP:%.*]] = call i8* @objc_retain(i8* [[X_VAL]]) nounwind
360 // CHECK-NEXT: call void [[FN]](i8* [[X_TMP]])
361 test13_func(x);
362
363 extern fnty ^test13_block;
364 // CHECK-NEXT: [[TMP:%.*]] = load void (i8*)** @test13_block, align
365 // CHECK-NEXT: [[BLOCK:%.*]] = bitcast void (i8*)* [[TMP]] to [[BLOCKTY:%.*]]*
366 // CHECK-NEXT: [[BLOCK_FN_PTR:%.*]] = getelementptr inbounds [[BLOCKTY]]* [[BLOCK]], i32 0, i32 3
367 // CHECK-NEXT: [[BLOCK_OPAQUE:%.*]] = bitcast [[BLOCKTY]]* [[BLOCK]] to i8*
368 // CHECK-NEXT: [[X_VAL:%.*]] = load i8** [[X]], align
369 // CHECK-NEXT: [[X_TMP:%.*]] = call i8* @objc_retain(i8* [[X_VAL]]) nounwind
370 // CHECK-NEXT: [[BLOCK_FN_TMP:%.*]] = load i8** [[BLOCK_FN_PTR]]
371 // CHECK-NEXT: [[BLOCK_FN:%.*]] = bitcast i8* [[BLOCK_FN_TMP]] to void (i8*, i8*)*
372 // CHECK-NEXT: call void [[BLOCK_FN]](i8* [[BLOCK_OPAQUE]], i8* [[X_TMP]])
373 test13_block(x);
374
375 // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]]
376 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind
377 // CHECK-NEXT: ret void
378}
379
380@interface Test16_super @end
381@interface Test16 : Test16_super {
382 id z;
383}
384@property (assign) int x;
385@property (retain) id y;
386- (void) dealloc;
387@end
388@implementation Test16
389@synthesize x;
390@synthesize y;
391- (void) dealloc {
392 // CHECK: define internal void @"\01-[Test16 dealloc]"(
393 // CHECK: [[SELF:%.*]] = alloca [[TEST16:%.*]]*, align
394 // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align
395 // CHECK-NEXT: alloca
396 // CHECK-NEXT: store [[TEST16]]* {{%.*}}, [[TEST16]]** [[SELF]], align
397 // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]]
398 // CHECK-NEXT: [[BASE:%.*]] = load [[TEST16]]** [[SELF]]
399
400 // Call super.
401 // CHECK-NEXT: [[BASE2:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8*
402 // CHECK-NEXT: [[T0:%.*]] = getelementptr
403 // CHECK-NEXT: store i8* [[BASE2]], i8** [[T0]]
404 // CHECK-NEXT: load {{%.*}}** @"\01L_OBJC_CLASSLIST_SUP_REFS_$_
405 // CHECK-NEXT: bitcast
406 // CHECK-NEXT: getelementptr
407 // CHECK-NEXT: store
408 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
409 // CHECK-NEXT: call void bitcast (i8* ({{.*}})* @objc_msgSendSuper2 to void (
410 // CHECK-NEXT: ret void
411}
412
413// .cxx_destruct
414 // CHECK: define internal void @"\01-[Test16 .cxx_destruct]"(
415 // CHECK: [[SELF:%.*]] = alloca [[TEST16:%.*]]*, align
416 // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align
417 // CHECK-NEXT: store [[TEST16]]* {{%.*}}, [[TEST16]]** [[SELF]], align
418 // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]]
419 // CHECK-NEXT: [[BASE:%.*]] = load [[TEST16]]** [[SELF]]
420
421 // Destroy y.
422 // CHECK-NEXT: [[Y_OFF:%.*]] = load i64* @"OBJC_IVAR_$_Test16.y"
423 // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8*
424 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[Y_OFF]]
425 // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8**
426 // CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) nounwind
427
428 // Destroy z.
429 // CHECK-NEXT: [[Z_OFF:%.*]] = load i64* @"OBJC_IVAR_$_Test16.z"
430 // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8*
431 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[Z_OFF]]
432 // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8**
433 // CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) nounwind
434
435 // CHECK-NEXT: ret void
436
437@end
438
439// This shouldn't crash.
440@interface Test17A
441@property (assign) int x;
442@end
443@interface Test17B : Test17A
444@end
445@implementation Test17B
446- (int) x { return super.x + 1; }
447@end
448
John McCallf85e1932011-06-15 23:02:42 +0000449void test19() {
450 // CHECK: define void @test19()
451 // CHECK: [[X:%.*]] = alloca [5 x i8*], align 16
452 // CHECK-NEXT: [[T0:%.*]] = bitcast [5 x i8*]* [[X]] to i8*
453 // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 40, i32 16, i1 false)
454 id x[5];
455
456 extern id test19_helper(void);
457 x[2] = test19_helper();
458
459 // CHECK-NEXT: [[CALL:%.*]] = call i8* @test19_helper()
460 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) nounwind
461 // CHECK-NEXT: [[SLOT:%.*]] = getelementptr inbounds [5 x i8*]* [[X]], i32 0, i64 2
462 // CHECK-NEXT: [[T0:%.*]] = load i8** [[SLOT]]
463 // CHECK-NEXT: store i8* [[T1]], i8** [[SLOT]]
464 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind
465
466 // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [5 x i8*]* [[X]], i32 0, i32 0
467 // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 5
468 // CHECK-NEXT: br label
469
John McCallbdc4d802011-07-09 01:37:26 +0000470 // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ]
471 // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1
472 // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]]
John McCallf85e1932011-06-15 23:02:42 +0000473 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind, !clang.imprecise_release
John McCallbdc4d802011-07-09 01:37:26 +0000474 // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]]
475 // CHECK-NEXT: br i1 [[EQ]],
John McCallf85e1932011-06-15 23:02:42 +0000476
477 // CHECK: ret void
478}
479
480void test20(unsigned n) {
481 // CHECK: define void @test20
482 // CHECK: [[N:%.*]] = alloca i32, align 4
483 // CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca i8*
484 // CHECK-NEXT: store i32 {{%.*}}, i32* [[N]], align 4
485
486 id x[n];
487
488 // Capture the VLA size.
John McCallbc8d40d2011-06-24 21:55:10 +0000489 // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4
490 // CHECK-NEXT: [[DIM:%.*]] = zext i32 [[T0]] to i64
491
492 // Save the stack pointer.
John McCallf85e1932011-06-15 23:02:42 +0000493 // CHECK-NEXT: [[T0:%.*]] = call i8* @llvm.stacksave()
494 // CHECK-NEXT: store i8* [[T0]], i8** [[SAVED_STACK]]
John McCallf85e1932011-06-15 23:02:42 +0000495
496 // Allocate the VLA.
John McCallbc8d40d2011-06-24 21:55:10 +0000497 // CHECK-NEXT: [[VLA:%.*]] = alloca i8*, i64 [[DIM]], align 16
John McCallf85e1932011-06-15 23:02:42 +0000498
499 // Zero-initialize.
500 // CHECK-NEXT: [[T0:%.*]] = bitcast i8** [[VLA]] to i8*
John McCallbc8d40d2011-06-24 21:55:10 +0000501 // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 [[DIM]], 8
502 // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 [[T1]], i32 8, i1 false)
John McCallf85e1932011-06-15 23:02:42 +0000503
504 // Destroy.
John McCallbc8d40d2011-06-24 21:55:10 +0000505 // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[VLA]], i64 [[DIM]]
John McCallfbf780a2011-07-13 08:09:46 +0000506 // CHECK-NEXT: [[EMPTY:%.*]] = icmp eq i8** [[VLA]], [[END]]
507 // CHECK-NEXT: br i1 [[EMPTY]]
John McCallf85e1932011-06-15 23:02:42 +0000508
John McCallbdc4d802011-07-09 01:37:26 +0000509 // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ]
510 // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1
511 // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]]
John McCallf85e1932011-06-15 23:02:42 +0000512 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind, !clang.imprecise_release
John McCallbdc4d802011-07-09 01:37:26 +0000513 // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[VLA]]
514 // CHECK-NEXT: br i1 [[EQ]],
John McCallf85e1932011-06-15 23:02:42 +0000515
516 // CHECK: [[T0:%.*]] = load i8** [[SAVED_STACK]]
517 // CHECK-NEXT: call void @llvm.stackrestore(i8* [[T0]])
518 // CHECK-NEXT: ret void
519}
520
521void test21(unsigned n) {
522 // CHECK: define void @test21
523 // CHECK: [[N:%.*]] = alloca i32, align 4
524 // CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca i8*
525 // CHECK-NEXT: store i32 {{%.*}}, i32* [[N]], align 4
526
527 id x[2][n][3];
528
529 // Capture the VLA size.
John McCallbc8d40d2011-06-24 21:55:10 +0000530 // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4
531 // CHECK-NEXT: [[DIM:%.*]] = zext i32 [[T0]] to i64
532
John McCallf85e1932011-06-15 23:02:42 +0000533 // CHECK-NEXT: [[T0:%.*]] = call i8* @llvm.stacksave()
534 // CHECK-NEXT: store i8* [[T0]], i8** [[SAVED_STACK]]
John McCallbc8d40d2011-06-24 21:55:10 +0000535
John McCallf85e1932011-06-15 23:02:42 +0000536
537 // Allocate the VLA.
John McCallbc8d40d2011-06-24 21:55:10 +0000538 // CHECK-NEXT: [[T0:%.*]] = mul nuw i64 2, [[DIM]]
539 // CHECK-NEXT: [[VLA:%.*]] = alloca [3 x i8*], i64 [[T0]], align 16
John McCallf85e1932011-06-15 23:02:42 +0000540
541 // Zero-initialize.
542 // CHECK-NEXT: [[T0:%.*]] = bitcast [3 x i8*]* [[VLA]] to i8*
John McCallbc8d40d2011-06-24 21:55:10 +0000543 // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 2, [[DIM]]
544 // CHECK-NEXT: [[T2:%.*]] = mul nuw i64 [[T1]], 24
545 // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 [[T2]], i32 8, i1 false)
John McCallf85e1932011-06-15 23:02:42 +0000546
547 // Destroy.
John McCallbc8d40d2011-06-24 21:55:10 +0000548 // CHECK-NEXT: [[T0:%.*]] = mul nuw i64 2, [[DIM]]
John McCallf85e1932011-06-15 23:02:42 +0000549 // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [3 x i8*]* [[VLA]], i32 0, i32 0
John McCallbc8d40d2011-06-24 21:55:10 +0000550 // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 [[T0]], 3
551 // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 [[T1]]
John McCallfbf780a2011-07-13 08:09:46 +0000552 // CHECK-NEXT: [[EMPTY:%.*]] = icmp eq i8** [[BEGIN]], [[END]]
553 // CHECK-NEXT: br i1 [[EMPTY]]
John McCallf85e1932011-06-15 23:02:42 +0000554
John McCallbdc4d802011-07-09 01:37:26 +0000555 // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ]
556 // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1
557 // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]]
John McCallf85e1932011-06-15 23:02:42 +0000558 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind, !clang.imprecise_release
John McCallbdc4d802011-07-09 01:37:26 +0000559 // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]]
560 // CHECK-NEXT: br i1 [[EQ]],
John McCallf85e1932011-06-15 23:02:42 +0000561
562 // CHECK: [[T0:%.*]] = load i8** [[SAVED_STACK]]
563 // CHECK-NEXT: call void @llvm.stackrestore(i8* [[T0]])
564 // CHECK-NEXT: ret void
565}
566
567void test22(_Bool cond) {
568 id test22_helper(void) __attribute__((ns_returns_retained));
569
570 // CHECK: define void @test22(
571 // CHECK: [[COND:%.*]] = alloca i8,
572 // CHECK-NEXT: [[X:%.*]] = alloca i8*,
John McCallf85e1932011-06-15 23:02:42 +0000573 // CHECK-NEXT: [[RELVAL:%.*]] = alloca i8*
John McCallbddfd872011-08-03 22:24:24 +0000574 // CHECK-NEXT: [[RELCOND:%.*]] = alloca i1
John McCallf85e1932011-06-15 23:02:42 +0000575 // CHECK-NEXT: zext
576 // CHECK-NEXT: store
577 // CHECK-NEXT: [[T0:%.*]] = load i8* [[COND]]
578 // CHECK-NEXT: [[T1:%.*]] = trunc i8 [[T0]] to i1
John McCallbddfd872011-08-03 22:24:24 +0000579 // CHECK-NEXT: store i1 false, i1* [[RELCOND]]
John McCallf85e1932011-06-15 23:02:42 +0000580 // CHECK-NEXT: br i1 [[T1]],
581 // CHECK: br label
582 // CHECK: [[CALL:%.*]] = call i8* @test22_helper()
John McCallf85e1932011-06-15 23:02:42 +0000583 // CHECK-NEXT: store i8* [[CALL]], i8** [[RELVAL]]
John McCallbddfd872011-08-03 22:24:24 +0000584 // CHECK-NEXT: store i1 true, i1* [[RELCOND]]
John McCallf85e1932011-06-15 23:02:42 +0000585 // CHECK-NEXT: br label
586 // CHECK: [[T0:%.*]] = phi i8* [ null, {{%.*}} ], [ [[CALL]], {{%.*}} ]
587 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) nounwind
588 // CHECK-NEXT: store i8* [[T1]], i8** [[X]],
589 // CHECK-NEXT: [[REL:%.*]] = load i1* [[RELCOND]]
590 // CHECK-NEXT: br i1 [[REL]],
591 // CHECK: [[T0:%.*]] = load i8** [[RELVAL]]
592 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind
593 // CHECK-NEXT: br label
594 // CHECK: [[T0:%.*]] = load i8** [[X]]
595 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind
596 // CHECK-NEXT: ret void
597 id x = (cond ? 0 : test22_helper());
598}
599
600// rdar://problem/8922540
601// Note that we no longer emit .release_ivars flags.
602// CHECK-GLOBALS: @"\01l_OBJC_CLASS_RO_$_Test23" = internal global [[RO_T:%.*]] { i32 134,
603@interface Test23 { id x; } @end
604@implementation Test23 @end
605
606// CHECK-GLOBALS: @"\01l_OBJC_CLASS_RO_$_Test24" = internal global [[RO_T:%.*]] { i32 130,
607@interface Test24 {} @end
608@implementation Test24 @end
609
John McCallf85e1932011-06-15 23:02:42 +0000610// rdar://problem/8941012
611@interface Test26 { id x[4]; } @end
612@implementation Test26 @end
613// CHECK: define internal void @"\01-[Test26 .cxx_destruct]"(
614// CHECK: [[SELF:%.*]] = load [[TEST26:%.*]]**
615// CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test26.x"
616// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST26]]* [[SELF]] to i8*
617// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[OFFSET]]
618// CHECK-NEXT: [[X:%.*]] = bitcast i8* [[T1]] to [4 x i8*]*
619// CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [4 x i8*]* [[X]], i32 0, i32 0
620// CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 4
621// CHECK-NEXT: br label
John McCall9928c482011-07-12 16:41:08 +0000622// CHECK: [[PAST:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ]
623// CHECK-NEXT: [[CUR]] = getelementptr inbounds i8** [[PAST]], i64 -1
624// CHECK-NEXT: call void @objc_storeStrong(i8** [[CUR]], i8* null)
625// CHECK-NEXT: [[ISDONE:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]]
John McCallf85e1932011-06-15 23:02:42 +0000626// CHECK-NEXT: br i1 [[ISDONE]],
John McCallf85e1932011-06-15 23:02:42 +0000627// CHECK: ret void
628
629// Check that 'init' retains self.
630@interface Test27
631- (id) init;
632@end
633@implementation Test27
634- (id) init { return self; }
635// CHECK: define internal i8* @"\01-[Test27 init]"
John McCallf48f7962012-01-29 02:35:02 +0000636// CHECK: [[SELF:%.*]] = alloca [[TEST27:%.*]]*,
John McCallf85e1932011-06-15 23:02:42 +0000637// CHECK-NEXT: [[CMD:%.*]] = alloca i8*,
638// CHECK-NEXT: [[DEST:%.*]] = alloca i32
639// CHECK-NEXT: store [[TEST27]]* {{%.*}}, [[TEST27]]** [[SELF]]
640// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]]
641// CHECK-NEXT: [[T0:%.*]] = load [[TEST27]]** [[SELF]]
642// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST27]]* [[T0]] to i8*
643// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]])
644// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]]
John McCallf48f7962012-01-29 02:35:02 +0000645// CHECK-NEXT: [[RET:%.*]] = bitcast
John McCallf85e1932011-06-15 23:02:42 +0000646// CHECK-NEXT: store i32 {{[0-9]+}}, i32* [[DEST]]
647// CHECK-NEXT: [[T0:%.*]] = load [[TEST27]]** [[SELF]]
648// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST27]]* [[T0]] to i8*
649// CHECK-NEXT: call void @objc_release(i8* [[T1]])
John McCallf48f7962012-01-29 02:35:02 +0000650// CHECK-NEXT: ret i8* [[RET]]
John McCallf85e1932011-06-15 23:02:42 +0000651
652@end
653
654// rdar://problem/8087194
655@interface Test28
656@property (copy) id prop;
657@end
658@implementation Test28
659@synthesize prop;
660@end
661// CHECK: define internal void @"\01-[Test28 .cxx_destruct]"
662// CHECK: [[SELF:%.*]] = load [[TEST28:%.*]]**
663// CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test28.prop"
664// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST28]]* [[SELF]] to i8*
665// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[OFFSET]]
666// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8**
667// CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null)
668// CHECK-NEXT: ret void
669
670@interface Test29_super
671- (id) initWithAllocator: (id) allocator;
672@end
673@interface Test29 : Test29_super
674- (id) init;
675- (id) initWithAllocator: (id) allocator;
676@end
677@implementation Test29
678static id _test29_allocator = 0;
679- (id) init {
680// CHECK: define internal i8* @"\01-[Test29 init]"([[TEST29:%.*]]* {{%.*}},
John McCallf48f7962012-01-29 02:35:02 +0000681// CHECK: [[SELF:%.*]] = alloca [[TEST29]]*, align 8
John McCallf85e1932011-06-15 23:02:42 +0000682// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align 8
683// CHECK-NEXT: [[CLEANUP:%.*]] = alloca i32
684// CHECK-NEXT: store [[TEST29]]* {{%.*}}, [[TEST29]]** [[SELF]]
685// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]]
686
687// Evaluate arguments. Note that the send argument is evaluated
688// before the zeroing of self.
689// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]], align 8
690// CHECK-NEXT: [[T1:%.*]] = load i8** @_test29_allocator, align 8
691
692// Implicit null of 'self', i.e. direct transfer of ownership.
693// CHECK-NEXT: store [[TEST29]]* null, [[TEST29]]** [[SELF]]
694
695// Actual message send.
696// CHECK-NEXT: [[T2:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
697// CHECK-NEXT: [[T3:%.*]] = bitcast [[TEST29]]* [[T0]] to i8*
698// CHECK-NEXT: [[CALL:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T3]], i8* [[T2]], i8* [[T1]])
699
700// Implicit write of result back into 'self'. This is not supposed to
701// be detectable because we're supposed to ban accesses to the old
702// self value past the delegate init call.
703// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]*
704// CHECK-NEXT: store [[TEST29]]* [[T0]], [[TEST29]]** [[SELF]]
705
706// Return statement.
707// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[CALL]]
708// CHECK-NEXT: [[CALL:%.*]] = bitcast
709// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[CALL]]) nounwind
710// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]]
John McCallf48f7962012-01-29 02:35:02 +0000711// CHECK-NEXT: [[RET:%.*]] = bitcast
John McCallf85e1932011-06-15 23:02:42 +0000712// CHECK-NEXT: store i32 1, i32* [[CLEANUP]]
713
714// Cleanup.
715// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]]
716// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8*
717// CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind, !clang.imprecise_release
718
719// Return.
John McCallf48f7962012-01-29 02:35:02 +0000720// CHECK-NEXT: ret i8* [[RET]]
John McCallf85e1932011-06-15 23:02:42 +0000721 return [self initWithAllocator: _test29_allocator];
722}
723- (id) initWithAllocator: (id) allocator {
724// CHECK: define internal i8* @"\01-[Test29 initWithAllocator:]"(
John McCallf48f7962012-01-29 02:35:02 +0000725// CHECK: [[SELF:%.*]] = alloca [[TEST29]]*, align 8
John McCallf85e1932011-06-15 23:02:42 +0000726// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align 8
727// CHECK-NEXT: [[ALLOCATOR:%.*]] = alloca i8*, align 8
728// CHECK-NEXT: alloca
729// CHECK-NEXT: [[CLEANUP:%.*]] = alloca i32
730// CHECK-NEXT: store [[TEST29]]* {{%.*}}, [[TEST29]]** [[SELF]]
731// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]]
732// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* {{%.*}})
733// CHECK-NEXT: store i8* [[T0]], i8** [[ALLOCATOR]]
734
735// Evaluate arguments. Note that the send argument is evaluated
736// before the zeroing of self.
737// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]]
738// CHECK-NEXT: [[T1:%.*]] = load i8** [[ALLOCATOR]], align 8
739
740// Implicit null of 'self', i.e. direct transfer of ownership.
741// CHECK-NEXT: store [[TEST29]]* null, [[TEST29]]** [[SELF]]
742
743// Actual message send.
744// CHECK: [[CALL:%.*]] = call {{.*}} @objc_msgSendSuper2
745
746// Implicit write of result back into 'self'. This is not supposed to
747// be detectable because we're supposed to ban accesses to the old
748// self value past the delegate init call.
749// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]*
750// CHECK-NEXT: store [[TEST29]]* [[T0]], [[TEST29]]** [[SELF]]
751
752// Assignment.
753// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]*
754// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8*
755// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) nounwind
756// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST29]]*
757// CHECK-NEXT: [[T4:%.*]] = load [[TEST29]]** [[SELF]], align
758// CHECK-NEXT: store [[TEST29]]* [[T3]], [[TEST29]]** [[SELF]], align
759// CHECK-NEXT: [[T5:%.*]] = bitcast [[TEST29]]* [[T4]] to i8*
760// CHECK-NEXT: call void @objc_release(i8* [[T5]])
761
762// Return statement.
763// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]]
764// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8*
765// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) nounwind
766// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]]
John McCallf48f7962012-01-29 02:35:02 +0000767// CHECK-NEXT: [[RET:%.*]] = bitcast
John McCallf85e1932011-06-15 23:02:42 +0000768// CHECK-NEXT: store i32 1, i32* [[CLEANUP]]
769
770// Cleanup.
771// CHECK-NEXT: [[T0:%.*]] = load i8** [[ALLOCATOR]]
772// CHECK-NEXT: call void @objc_release(i8* [[T0]]) nounwind, !clang.imprecise_release
773
774// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]]
775// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8*
776// CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind, !clang.imprecise_release
777
778// Return.
John McCallf48f7962012-01-29 02:35:02 +0000779// CHECK-NEXT: ret i8* [[RET]]
John McCallf85e1932011-06-15 23:02:42 +0000780 self = [super initWithAllocator: allocator];
781 return self;
782}
783@end
784
785typedef struct Test30_helper Test30_helper;
786@interface Test30
787- (id) init;
788- (Test30_helper*) initHelper;
789@end
790@implementation Test30 {
791char *helper;
792}
793- (id) init {
794// CHECK: define internal i8* @"\01-[Test30 init]"([[TEST30:%.*]]* {{%.*}},
John McCallf48f7962012-01-29 02:35:02 +0000795// CHECK: [[RET:%.*]] = alloca [[TEST30]]*
John McCallf85e1932011-06-15 23:02:42 +0000796// CHECK-NEXT: alloca i8*
797// CHECK-NEXT: alloca i32
798// CHECK-NEXT: store [[TEST30]]* {{%.*}}, [[TEST30]]** [[SELF]]
799// CHECK-NEXT: store
800
801// Call.
802// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]]
803// CHECK-NEXT: [[T1:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
804// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST30]]* [[T0]] to i8*
805// CHECK-NEXT: [[CALL:%.*]] = call [[TEST30_HELPER:%.*]]* bitcast {{.*}} @objc_msgSend {{.*}}(i8* [[T2]], i8* [[T1]])
806
807// Assignment.
808// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST30_HELPER]]* [[CALL]] to i8*
809// CHECK-NEXT: [[T1:%.*]] = load [[TEST30]]** [[SELF]]
810// CHECK-NEXT: [[IVAR:%.*]] = load i64* @"OBJC_IVAR_$_Test30.helper"
811// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST30]]* [[T1]] to i8*
812// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[IVAR]]
813// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8**
814// CHECK-NEXT#: [[T5:%.*]] = load i8** [[T4]]
815// CHECK-NEXT#: [[T6:%.*]] = call i8* @objc_retain(i8* [[T0]])
816// CHECK-NEXT#: call void @objc_release(i8* [[T5]])
817// CHECK-NEXT: store i8* [[T0]], i8** [[T4]]
818
819// Return.
820// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]]
821// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST30]]* [[T0]] to i8*
822// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]])
823// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]]
John McCallf48f7962012-01-29 02:35:02 +0000824// CHECK-NEXT: [[RET:%.*]] = bitcast
John McCallf85e1932011-06-15 23:02:42 +0000825// CHECK-NEXT: store i32 1
826
827// Cleanup.
828// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]]
829// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST30]]* [[T0]] to i8*
830// CHECK-NEXT: call void @objc_release(i8* [[T1]])
831
832// Epilogue.
John McCallf48f7962012-01-29 02:35:02 +0000833// CHECK-NEXT: ret i8* [[RET]]
John McCallf85e1932011-06-15 23:02:42 +0000834 self->helper = [self initHelper];
835 return self;
836}
837- (Test30_helper*) initHelper {
838// CHECK: define internal [[TEST30_HELPER]]* @"\01-[Test30 initHelper]"(
839// CHECK: alloca
840// CHECK-NEXT: alloca
841// CHECK-NEXT: store
842// CHECK-NEXT: store
843// CHECK-NEXT: ret [[TEST30_HELPER]]* null
844 return 0;
845}
846
847@end
848
John McCallf85e1932011-06-15 23:02:42 +0000849__attribute__((ns_returns_retained)) id test32(void) {
850// CHECK: define i8* @test32()
851// CHECK: [[CALL:%.*]] = call i8* @test32_helper()
852// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]])
853// CHECK-NEXT: ret i8* [[T0]]
854 extern id test32_helper(void);
855 return test32_helper();
856}
857
858@class Test33_a;
859@interface Test33
860- (void) give: (Test33_a **) x;
861- (void) take: (Test33_a **) x;
862- (void) giveStrong: (out __strong Test33_a **) x;
863- (void) takeStrong: (inout __strong Test33_a **) x;
864- (void) giveOut: (out Test33_a **) x;
865@end
866void test33(Test33 *ptr) {
867 Test33_a *a;
868 [ptr give: &a];
869 [ptr take: &a];
870 [ptr giveStrong: &a];
871 [ptr takeStrong: &a];
872 [ptr giveOut: &a];
873
874 // CHECK: define void @test33([[TEST33:%.*]]*
875 // CHECK: [[PTR:%.*]] = alloca [[TEST33]]*
876 // CHECK-NEXT: [[A:%.*]] = alloca [[A_T:%.*]]*
877 // CHECK-NEXT: [[TEMP0:%.*]] = alloca [[A_T]]*
878 // CHECK-NEXT: [[TEMP1:%.*]] = alloca [[A_T]]*
879 // CHECK-NEXT: [[TEMP2:%.*]] = alloca [[A_T]]*
880 // CHECK-NEXT: bitcast
881 // CHECK-NEXT: objc_retain
882 // CHECK-NEXT: bitcast
883 // CHECK-NEXT: store
884 // CHECK-NEXT: store [[A_T]]* null, [[A_T]]** [[A]]
885
886 // CHECK-NEXT: load [[TEST33]]** [[PTR]]
887 // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[A]]
888 // CHECK-NEXT: store [[A_T]]* [[T0]], [[A_T]]** [[TEMP0]]
889 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
890 // CHECK-NEXT: bitcast
891 // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP0]])
892 // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP0]]
893 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8*
894 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]])
895 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]*
896 // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]]
897 // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]]
898 // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8*
899 // CHECK-NEXT: call void @objc_release(i8* [[T5]])
900
901 // CHECK-NEXT: load [[TEST33]]** [[PTR]]
902 // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[A]]
903 // CHECK-NEXT: store [[A_T]]* [[T0]], [[A_T]]** [[TEMP1]]
904 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
905 // CHECK-NEXT: bitcast
906 // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP1]])
907 // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP1]]
908 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8*
909 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]])
910 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]*
911 // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]]
912 // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]]
913 // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8*
914 // CHECK-NEXT: call void @objc_release(i8* [[T5]])
915
916 // CHECK-NEXT: load [[TEST33]]** [[PTR]]
917 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
918 // CHECK-NEXT: bitcast
919 // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[A]])
920
921 // CHECK-NEXT: load [[TEST33]]** [[PTR]]
922 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
923 // CHECK-NEXT: bitcast
924 // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[A]])
925
926 // 'out'
927 // CHECK-NEXT: load [[TEST33]]** [[PTR]]
928 // CHECK-NEXT: store [[A_T]]* null, [[A_T]]** [[TEMP2]]
929 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
930 // CHECK-NEXT: bitcast
931 // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP2]])
932 // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP2]]
933 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8*
934 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]])
935 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]*
936 // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]]
937 // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]]
938 // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8*
939 // CHECK-NEXT: call void @objc_release(i8* [[T5]])
940
941 // CHECK-NEXT: load
942 // CHECK-NEXT: bitcast
943 // CHECK-NEXT: objc_release
944 // CHECK-NEXT: load
945 // CHECK-NEXT: bitcast
946 // CHECK-NEXT: objc_release
947 // CHECK-NEXT: ret void
948}
949
950void test34(int cond) {
951 __strong id strong;
952 __weak id weak;
953 extern void test34_sink(id *);
954 test34_sink(cond ? &strong : 0);
955 test34_sink(cond ? &weak : 0);
956
957 // CHECK: define void @test34(
958 // CHECK: [[COND:%.*]] = alloca i32
959 // CHECK-NEXT: [[STRONG:%.*]] = alloca i8*
960 // CHECK-NEXT: [[WEAK:%.*]] = alloca i8*
961 // CHECK-NEXT: [[TEMP1:%.*]] = alloca i8*
962 // CHECK-NEXT: [[TEMP2:%.*]] = alloca i8*
963 // CHECK-NEXT: store i32
964 // CHECK-NEXT: store i8* null, i8** [[STRONG]]
965 // CHECK-NEXT: call i8* @objc_initWeak(i8** [[WEAK]], i8* null)
966
967 // CHECK-NEXT: [[T0:%.*]] = load i32* [[COND]]
968 // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 0
969 // CHECK: [[ARG:%.*]] = phi i8**
970 // CHECK-NEXT: [[T0:%.*]] = icmp eq i8** [[ARG]], null
971 // CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i8** null, i8** [[TEMP1]]
972 // CHECK-NEXT: br i1 [[T0]],
973 // CHECK: [[T0:%.*]] = load i8** [[ARG]]
974 // CHECK-NEXT: store i8* [[T0]], i8** [[TEMP1]]
975 // CHECK-NEXT: br label
976 // CHECK: call void @test34_sink(i8** [[T1]])
977 // CHECK-NEXT: [[T0:%.*]] = icmp eq i8** [[ARG]], null
978 // CHECK-NEXT: br i1 [[T0]],
979 // CHECK: [[T0:%.*]] = load i8** [[TEMP1]]
980 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]])
981 // CHECK-NEXT: [[T2:%.*]] = load i8** [[ARG]]
982 // CHECK-NEXT: store i8* [[T1]], i8** [[ARG]]
983 // CHECK-NEXT: call void @objc_release(i8* [[T2]])
984 // CHECK-NEXT: br label
985
986 // CHECK: [[T0:%.*]] = load i32* [[COND]]
987 // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 0
988 // CHECK: [[ARG:%.*]] = phi i8**
989 // CHECK-NEXT: [[T0:%.*]] = icmp eq i8** [[ARG]], null
990 // CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i8** null, i8** [[TEMP2]]
991 // CHECK-NEXT: br i1 [[T0]],
992 // CHECK: [[T0:%.*]] = call i8* @objc_loadWeak(i8** [[ARG]])
993 // CHECK-NEXT: store i8* [[T0]], i8** [[TEMP2]]
994 // CHECK-NEXT: br label
995 // CHECK: call void @test34_sink(i8** [[T1]])
996 // CHECK-NEXT: [[T0:%.*]] = icmp eq i8** [[ARG]], null
997 // CHECK-NEXT: br i1 [[T0]],
998 // CHECK: [[T0:%.*]] = load i8** [[TEMP2]]
999 // CHECK-NEXT: call i8* @objc_storeWeak(i8** [[ARG]], i8* [[T0]])
1000 // CHECK-NEXT: br label
1001
1002 // CHECK: call void @objc_destroyWeak(i8** [[WEAK]])
1003 // CHECK: ret void
1004}
1005
John McCallf85e1932011-06-15 23:02:42 +00001006// CHECK: define void @test36
1007void test36(id x) {
1008 // CHECK: [[X:%.*]] = alloca i8*
1009
1010 // CHECK: call i8* @objc_retain
1011 // CHECK: call i8* @objc_retain
1012 // CHECK: call i8* @objc_retain
1013 id array[3] = { @"A", x, @"y" };
1014
1015 // CHECK: [[T0:%.*]] = load i8** [[X]]
1016 // CHECK-NEXT: store i8* null, i8** [[X]]
1017 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
1018 x = 0;
1019
1020 // CHECK: br label
1021 // CHECK: call void @objc_release
John McCallbdc4d802011-07-09 01:37:26 +00001022 // CHECK: br i1
John McCallf85e1932011-06-15 23:02:42 +00001023
1024 // CHECK: call void @objc_release
1025 // CHECK-NEXT: ret void
1026}
1027
1028@class Test37;
1029void test37(void) {
1030 extern void test37_helper(id *);
1031 Test37 *var;
1032 test37_helper(&var);
1033
1034 // CHECK: define void @test37()
1035 // CHECK: [[VAR:%.*]] = alloca [[TEST37:%.*]]*,
1036 // CHECK-NEXT: [[TEMP:%.*]] = alloca i8*
1037 // CHECK-NEXT: store [[TEST37]]* null, [[TEST37]]** [[VAR]]
1038
1039 // CHECK-NEXT: [[T0:%.*]] = load [[TEST37]]** [[VAR]]
1040 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST37]]* [[T0]] to i8*
1041 // CHECK-NEXT: store i8* [[T1]], i8** [[TEMP]]
1042 // CHECK-NEXT: call void @test37_helper(i8** [[TEMP]])
1043 // CHECK-NEXT: [[T0:%.*]] = load i8** [[TEMP]]
1044 // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[TEST37]]*
1045 // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST37]]* [[T1]] to i8*
1046 // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retain(i8* [[T2]])
1047 // CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to [[TEST37]]*
1048 // CHECK-NEXT: [[T5:%.*]] = load [[TEST37]]** [[VAR]]
1049 // CHECK-NEXT: store [[TEST37]]* [[T4]], [[TEST37]]** [[VAR]]
1050 // CHECK-NEXT: [[T6:%.*]] = bitcast [[TEST37]]* [[T5]] to i8*
1051 // CHECK-NEXT: call void @objc_release(i8* [[T6]])
1052
1053 // CHECK-NEXT: [[T0:%.*]] = load [[TEST37]]** [[VAR]]
1054 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST37]]* [[T0]] to i8*
1055 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
1056 // CHECK-NEXT: ret void
1057}
1058
John McCallf85e1932011-06-15 23:02:42 +00001059@interface Test43 @end
1060@implementation Test43
1061- (id) test __attribute__((ns_returns_retained)) {
1062 extern id test43_produce(void);
1063 return test43_produce();
1064 // CHECK: call i8* @test43_produce()
1065 // CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue(
1066 // CHECK-NEXT: ret
1067}
1068@end
1069
John McCallf85e1932011-06-15 23:02:42 +00001070@interface Test45
1071@property (retain) id x;
1072@end
1073@implementation Test45
1074@synthesize x;
1075@end
1076// CHECK: define internal i8* @"\01-[Test45 x]"(
1077// CHECK: [[CALL:%.*]] = call i8* @objc_getProperty(
1078// CHECK-NEXT: ret i8* [[CALL]]
1079
1080// rdar://problem/9315552
1081void test46(__weak id *wp, __weak volatile id *wvp) {
1082 extern id test46_helper(void);
1083
1084 // TODO: this is sub-optimal, we should retain at the actual call site.
1085
1086 // CHECK: [[T0:%.*]] = call i8* @test46_helper()
John McCall7e5e5f42011-07-07 06:58:02 +00001087 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1088 // CHECK-NEXT: [[T2:%.*]] = load i8*** {{%.*}}, align 8
1089 // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]])
1090 // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retain(i8* [[T3]])
1091 // CHECK-NEXT: store i8* [[T4]], i8**
1092 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +00001093 id x = *wp = test46_helper();
1094
1095 // CHECK: [[T0:%.*]] = call i8* @test46_helper()
John McCall7e5e5f42011-07-07 06:58:02 +00001096 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1097 // CHECK-NEXT: [[T2:%.*]] = load i8*** {{%.*}}, align 8
1098 // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]])
1099 // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retain(i8* [[T3]])
1100 // CHECK-NEXT: store i8* [[T4]], i8**
1101 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +00001102 id y = *wvp = test46_helper();
1103}
1104
1105// rdar://problem/9378887
1106void test47(void) {
1107 extern id test47_helper(void);
1108 id x = x = test47_helper();
1109
1110 // CHECK: define void @test47()
1111 // CHECK: [[X:%.*]] = alloca i8*
1112 // CHECK-NEXT: store i8* null, i8** [[X]]
1113 // CHECK-NEXT: [[CALL:%.*]] = call i8* @test47_helper()
1114 // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]])
1115 // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]]
1116 // CHECK-NEXT: store i8* [[T0]], i8** [[X]]
1117 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
1118 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T0]])
1119 // CHECK-NEXT: [[T3:%.*]] = load i8** [[X]]
1120 // CHECK-NEXT: store i8* [[T2]], i8** [[X]]
1121 // CHECK-NEXT: call void @objc_release(i8* [[T3]])
1122 // CHECK-NEXT: [[T4:%.*]] = load i8** [[X]]
1123 // CHECK-NEXT: call void @objc_release(i8* [[T4]])
1124 // CHECK-NEXT: ret void
1125}
1126
1127void test48(void) {
1128 extern id test48_helper(void);
1129 __weak id x = x = test48_helper();
1130 // CHECK: define void @test48()
1131 // CHECK: [[X:%.*]] = alloca i8*
1132 // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_initWeak(i8** [[X]], i8* null)
1133 // CHECK-NEXT: [[T1:%.*]] = call i8* @test48_helper()
John McCall7e5e5f42011-07-07 06:58:02 +00001134 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +00001135 // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[X]], i8* [[T2]])
John McCall7e5e5f42011-07-07 06:58:02 +00001136 // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_storeWeak(i8** [[X]], i8* [[T3]])
1137 // CHECK-NEXT: call void @objc_release(i8* [[T2]])
John McCallf85e1932011-06-15 23:02:42 +00001138 // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]])
1139 // CHECK-NEXT: ret void
1140}
1141
1142void test49(void) {
1143 extern id test49_helper(void);
1144 __autoreleasing id x = x = test49_helper();
1145 // CHECK: define void @test49()
1146 // CHECK: [[X:%.*]] = alloca i8*
1147 // CHECK-NEXT: store i8* null, i8** [[X]]
1148 // CHECK-NEXT: [[CALL:%.*]] = call i8* @test49_helper()
1149 // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]])
1150 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_autorelease(i8* [[T0]])
1151 // CHECK-NEXT: store i8* [[T2]], i8** [[X]]
1152 // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retainAutorelease(i8* [[T1]])
1153 // CHECK-NEXT: store i8* [[T3]], i8** [[X]]
1154 // CHECK-NEXT: ret void
1155}
1156
1157// rdar://9380136
1158id x();
1159void test50(id y) {
1160 ({x();});
1161// CHECK: [[T0:%.*]] = call i8* @objc_retain
1162// CHECK: call void @objc_release
1163}
1164
1165
1166// rdar://9400762
1167struct CGPoint {
1168 float x;
1169 float y;
1170};
1171typedef struct CGPoint CGPoint;
1172
1173@interface Foo
1174@property (assign) CGPoint point;
1175@end
1176
1177@implementation Foo
1178@synthesize point;
1179@end
1180
1181// rdar://problem/9400398
1182id test52(void) {
1183 id test52_helper(int) __attribute__((ns_returns_retained));
1184 return ({ int x = 5; test52_helper(x); });
1185
1186// CHECK: define i8* @test52()
1187// CHECK: [[X:%.*]] = alloca i32
1188// CHECK-NEXT: store i32 5, i32* [[X]],
1189// CHECK-NEXT: [[T0:%.*]] = load i32* [[X]],
1190// CHECK-NEXT: [[T1:%.*]] = call i8* @test52_helper(i32 [[T0]])
1191// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_autoreleaseReturnValue(i8* [[T1]])
1192// CHECK-NEXT: ret i8* [[T2]]
1193}
1194
1195// rdar://problem/9400644
1196void test53(void) {
1197 id test53_helper(void);
1198 id x = ({ id y = test53_helper(); y; });
1199 (void) x;
1200// CHECK: define void @test53()
1201// CHECK: [[X:%.*]] = alloca i8*,
1202// CHECK-NEXT: [[Y:%.*]] = alloca i8*,
1203// CHECK-NEXT: [[T0:%.*]] = call i8* @test53_helper()
1204// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1205// CHECK-NEXT: store i8* [[T1]], i8** [[Y]],
1206// CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]],
1207// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]])
1208// CHECK-NEXT: [[T2:%.*]] = load i8** [[Y]]
1209// CHECK-NEXT: call void @objc_release(i8* [[T2]])
1210// CHECK-NEXT: store i8* [[T1]], i8** [[X]],
1211// CHECK-NEXT: load i8** [[X]],
1212// CHECK-NEXT: [[T0:%.*]] = load i8** [[X]]
1213// CHECK-NEXT: call void @objc_release(i8* [[T0]])
1214// CHECK-NEXT: ret void
1215}
Douglas Gregorf96e9042011-07-12 17:28:52 +00001216
1217// <rdar://problem/9758798>
1218// CHECK: define void @test54(i32 %first, ...)
1219void test54(int first, ...) {
1220 __builtin_va_list arglist;
1221 // CHECK: call void @llvm.va_start
1222 __builtin_va_start(arglist, first);
1223 // CHECK: call i8* @objc_retain
1224 id obj = __builtin_va_arg(arglist, id);
1225 // CHECK: call void @llvm.va_end
1226 __builtin_va_end(arglist);
1227 // CHECK: call void @objc_release
1228 // CHECK: ret void
1229}
John McCall799d34e2011-07-13 18:26:47 +00001230
1231// PR10228
1232@interface Test55Base @end
1233@interface Test55 : Test55Base @end
1234@implementation Test55 (Category)
1235- (void) dealloc {}
1236@end
1237// CHECK: define internal void @"\01-[Test55(Category) dealloc]"(
1238// CHECK-NOT: ret
1239// CHECK: call void bitcast (i8* ({{%.*}}*, i8*, ...)* @objc_msgSendSuper2 to void ({{%.*}}*, i8*)*)(
John McCall6c2c2502011-07-22 02:45:48 +00001240
1241// rdar://problem/8024350
1242@protocol Test56Protocol
1243+ (id) make __attribute__((ns_returns_retained));
1244@end
1245@interface Test56<Test56Protocol> @end
1246@implementation Test56
1247// CHECK: define internal i8* @"\01+[Test56 make]"(
1248+ (id) make {
1249 extern id test56_helper(void);
1250 // CHECK: [[T0:%.*]] = call i8* @test56_helper()
1251 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1252 // CHECK-NEXT: ret i8* [[T1]]
1253 return test56_helper();
1254}
1255@end
1256void test56_test(void) {
1257 id x = [Test56 make];
1258 // CHECK: define void @test56_test()
1259 // CHECK: [[X:%.*]] = alloca i8*, align 8
1260 // CHECK: [[T0:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*)*)(
1261 // CHECK-NEXT: store i8* [[T0]], i8** [[X]]
1262 // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]]
1263 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
1264 // CHECK-NEXT: ret void
1265}
John McCallba3dd902011-07-22 05:23:13 +00001266
1267// rdar://problem/9784964
1268@interface Test57
1269@property (nonatomic, strong) id strong;
1270@property (nonatomic, weak) id weak;
1271@property (nonatomic, unsafe_unretained) id unsafe;
1272@end
1273@implementation Test57
1274@synthesize strong, weak, unsafe;
1275@end
1276// CHECK: define internal i8* @"\01-[Test57 strong]"(
1277// CHECK: [[T0:%.*]] = load [[TEST57:%.*]]** {{%.*}}
1278// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_Test57.strong"
1279// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST57]]* [[T0]] to i8*
1280// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]]
1281// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8**
1282// CHECK-NEXT: [[T5:%.*]] = load i8** [[T4]]
1283// CHECK-NEXT: ret i8* [[T5]]
1284
1285// CHECK: define internal i8* @"\01-[Test57 weak]"(
1286// CHECK: [[T0:%.*]] = load [[TEST57]]** {{%.*}}
1287// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_Test57.weak"
1288// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST57]]* [[T0]] to i8*
1289// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]]
1290// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8**
1291// CHECK-NEXT: [[T5:%.*]] = call i8* @objc_loadWeakRetained(i8** [[T4]])
1292// CHECK-NEXT: [[T6:%.*]] = call i8* @objc_autoreleaseReturnValue(i8* [[T5]])
1293// CHECK-NEXT: ret i8* [[T6]]
1294
1295// CHECK: define internal i8* @"\01-[Test57 unsafe]"(
1296// CHECK: [[T0:%.*]] = load [[TEST57]]** {{%.*}}
1297// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_Test57.unsafe"
1298// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST57]]* [[T0]] to i8*
1299// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]]
1300// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8**
1301// CHECK-NEXT: [[T5:%.*]] = load i8** [[T4]]
1302// CHECK-NEXT: ret i8* [[T5]]
1303
John McCalldc7c5ad2011-07-22 08:53:00 +00001304// rdar://problem/9821110
1305@interface Test58
1306- (char*) interior __attribute__((objc_returns_inner_pointer));
1307// Should we allow this on properties?
1308@end
1309extern Test58 *test58_helper(void);
1310
1311// CHECK: define void @test58a()
1312void test58a(void) {
1313 // CHECK: [[T0:%.*]] = call [[TEST58:%.*]]* @test58_helper()
1314 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST58]]* [[T0]] to i8*
1315 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]])
1316 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST58]]*
1317 // CHECK-NEXT: store [[TEST58]]* [[T3]]
1318 // CHECK-NEXT: [[T0:%.*]] = load [[TEST58]]**
1319 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST58]]* [[T0]] to i8*
1320 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutorelease(i8* [[T1]])
1321 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST58]]*
1322 // CHECK-NEXT: [[T4:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
1323 // CHECK-NEXT: [[T5:%.*]] = bitcast [[TEST58]]* [[T3]] to i8*
1324 // CHECK-NEXT: [[T6:%.*]] = call i8* bitcast
1325 // CHECK-NEXT: store i8* [[T6]], i8**
1326 // CHECK-NEXT: [[T0:%.*]] = load [[TEST58]]**
1327 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST58]]* [[T0]] to i8*
1328 // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind, !clang.imprecise_release
1329 // CHECK-NEXT: ret void
1330 Test58 *ptr = test58_helper();
1331 char *c = [(ptr) interior];
1332}
1333
1334// CHECK: define void @test58b()
1335void test58b(void) {
1336 // CHECK: [[T0:%.*]] = call [[TEST58:%.*]]* @test58_helper()
1337 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST58]]* [[T0]] to i8*
1338 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]])
1339 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST58]]*
1340 // CHECK-NEXT: store [[TEST58]]* [[T3]]
1341 // CHECK-NEXT: [[T0:%.*]] = load [[TEST58]]**
1342 // CHECK-NEXT: [[T1:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
1343 // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST58]]* [[T0]] to i8*
1344 // CHECK-NEXT: [[T3:%.*]] = call i8* bitcast
1345 // CHECK-NEXT: store i8* [[T3]], i8**
1346 // CHECK-NEXT: [[T0:%.*]] = load [[TEST58]]**
1347 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST58]]* [[T0]] to i8*
1348 // CHECK-NEXT: call void @objc_release(i8* [[T1]]) nounwind
1349 // CHECK-NOT: clang.imprecise_release
1350 // CHECK-NEXT: ret void
1351 __attribute__((objc_precise_lifetime)) Test58 *ptr = test58_helper();
1352 char *c = [ptr interior];
1353}
John McCall07524032011-07-27 21:50:02 +00001354
1355// rdar://problem/9842343
1356void test59(void) {
1357 extern id test59_getlock(void);
1358 extern void test59_body(void);
1359 @synchronized (test59_getlock()) {
1360 test59_body();
1361 }
1362
1363 // CHECK: define void @test59()
1364 // CHECK: [[T0:%.*]] = call i8* @test59_getlock()
1365 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1366 // CHECK-NEXT: call void @objc_sync_enter(i8* [[T1]])
1367 // CHECK-NEXT: call void @test59_body()
1368 // CHECK-NEXT: call void @objc_sync_exit(i8* [[T1]])
1369 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
1370 // CHECK-NEXT: ret void
1371}
John McCallfb720812011-07-28 07:23:35 +00001372
John McCallfc4b1912011-08-03 07:02:44 +00001373// Verify that we don't try to reclaim the result of performSelector.
1374// rdar://problem/9887545
1375@interface Test61
1376- (id) performSelector: (SEL) selector;
1377- (void) test61_void;
1378- (id) test61_id;
1379@end
1380void test61(void) {
1381 // CHECK: define void @test61()
1382 // CHECK: [[Y:%.*]] = alloca i8*, align 8
1383
1384 extern id test61_make(void);
1385
1386 // CHECK-NEXT: [[T0:%.*]] = call i8* @test61_make()
1387 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1388 // CHECK-NEXT: [[T2:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
1389 // CHECK-NEXT: [[T3:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
1390 // CHECK-NEXT: [[T4:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T1]], i8* [[T3]], i8* [[T2]])
1391 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
1392 [test61_make() performSelector: @selector(test61_void)];
1393
1394 // CHECK-NEXT: [[T0:%.*]] = call i8* @test61_make()
1395 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1396 // CHECK-NEXT: [[T2:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
1397 // CHECK-NEXT: [[T3:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
1398 // CHECK-NEXT: [[T4:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T1]], i8* [[T3]], i8* [[T2]])
1399 // CHECK-NEXT: [[T5:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T4]])
1400 // CHECK-NEXT: store i8* [[T5]], i8** [[Y]]
1401 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
1402 id y = [test61_make() performSelector: @selector(test61_id)];
1403
1404 // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]]
1405 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
1406 // CHECK-NEXT: ret void
1407}
John McCallbddfd872011-08-03 22:24:24 +00001408
1409// rdar://problem/9891815
1410void test62(void) {
1411 // CHECK: define void @test62()
1412 // CHECK: [[I:%.*]] = alloca i32, align 4
1413 // CHECK-NEXT: [[CLEANUP_VALUE:%.*]] = alloca i8*
1414 // CHECK-NEXT: [[CLEANUP_REQUIRED:%.*]] = alloca i1
1415 extern id test62_make(void);
1416 extern void test62_body(void);
1417
1418 // CHECK-NEXT: store i32 0, i32* [[I]], align 4
1419 // CHECK-NEXT: br label
1420
1421 // CHECK: [[T0:%.*]] = load i32* [[I]], align 4
1422 // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 20
1423 // CHECK-NEXT: br i1 [[T1]],
1424
1425 for (unsigned i = 0; i != 20; ++i) {
1426 // CHECK: [[T0:%.*]] = load i32* [[I]], align 4
1427 // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 0
1428 // CHECK-NEXT: store i1 false, i1* [[CLEANUP_REQUIRED]]
1429 // CHECK-NEXT: br i1 [[T1]],
1430 // CHECK: [[T0:%.*]] = call i8* @test62_make()
1431 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1432 // CHECK-NEXT: store i8* [[T1]], i8** [[CLEANUP_VALUE]]
1433 // CHECK-NEXT: store i1 true, i1* [[CLEANUP_REQUIRED]]
1434 // CHECK-NEXT: [[T2:%.*]] = icmp ne i8* [[T1]], null
1435 // CHECK-NEXT: br label
1436 // CHECK: [[COND:%.*]] = phi i1 [ false, {{%.*}} ], [ [[T2]], {{%.*}} ]
1437 // CHECK-NEXT: [[T0:%.*]] = load i1* [[CLEANUP_REQUIRED]]
1438 // CHECK-NEXT: br i1 [[T0]],
1439 // CHECK: [[T0:%.*]] = load i8** [[CLEANUP_VALUE]]
1440 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
1441 // CHECK-NEXT: br label
1442 // CHECK: br i1 [[COND]]
1443 // CHECK: call void @test62_body()
1444 // CHECK-NEXT: br label
1445 // CHECK: br label
1446 if (i != 0 && test62_make() != 0)
1447 test62_body();
1448 }
1449
1450 // CHECK: [[T0:%.*]] = load i32* [[I]], align 4
1451 // CHECK-NEXT: [[T1:%.*]] = add i32 [[T0]], 1
1452 // CHECK-NEXT: store i32 [[T1]], i32* [[I]]
1453 // CHECK-NEXT: br label
1454
1455 // CHECK: ret void
1456}
Fariborz Jahanianbc03aea2011-08-19 19:28:44 +00001457
1458// rdar://9971982
1459@class NSString;
1460
1461@interface Person {
1462 NSString *name;
1463}
1464@property NSString *address;
1465@end
1466
1467@implementation Person
1468@synthesize address;
1469@end
1470// CHECK: call i8* @objc_getProperty
1471// CHECK: call void @objc_setProperty
1472
John McCallcdda47f2011-10-01 09:56:14 +00001473// Verify that we successfully parse and preserve this attribute in
1474// this position.
1475@interface Test66
1476- (void) consume: (id __attribute__((ns_consumed))) ptr;
1477@end
1478void test66(void) {
1479 extern Test66 *test66_receiver(void);
1480 extern id test66_arg(void);
1481 [test66_receiver() consume: test66_arg()];
1482}
1483// CHECK: define void @test66()
1484// CHECK: [[T0:%.*]] = call [[TEST66:%.*]]* @test66_receiver()
1485// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST66]]* [[T0]] to i8*
1486// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]])
1487// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST66]]*
Fariborz Jahanian4e1524b2012-01-29 20:27:13 +00001488// CHECK-NEXT: [[T4:%.*]] = call i8* @test66_arg()
John McCallcdda47f2011-10-01 09:56:14 +00001489// CHECK-NEXT: [[T5:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T4]])
1490// CHECK-NEXT: [[T6:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES
1491// CHECK-NEXT: [[T7:%.*]] = bitcast [[TEST66]]* [[T3]] to i8*
Fariborz Jahanian3c267e62012-01-30 21:40:37 +00001492// CHECK-NEXT: [[SIX:%.*]] = icmp eq i8* [[T7]], null
1493// CHECK-NEXT: br i1 [[SIX]], label [[NULINIT:%.*]], label [[CALL:%.*]]
1494// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i8*)*)(i8* [[T7]], i8* [[T6]], i8* [[T5]])
1495// CHECK-NEXT: br label [[CONT:%.*]]
1496// CHECK: call void @objc_release(i8* [[T5]]) nounwind
1497// CHECK-NEXT: br label [[CONT:%.*]]
1498// CHECK: [[T8:%.*]] = bitcast [[TEST66]]* [[T3]] to i8*
John McCallcdda47f2011-10-01 09:56:14 +00001499// CHECK-NEXT: call void @objc_release(i8* [[T8]])
1500// CHECK-NEXT: ret void
John McCall567c5862011-11-14 19:53:16 +00001501
1502// rdar://problem/9953540
1503Class test67_helper(void);
1504void test67(void) {
1505 Class cl = test67_helper();
1506}
1507// CHECK: define void @test67()
1508// CHECK: [[CL:%.*]] = alloca i8*, align 8
1509// CHECK-NEXT: [[T0:%.*]] = call i8* @test67_helper()
1510// CHECK-NEXT: store i8* [[T0]], i8** [[CL]], align 8
1511// CHECK-NEXT: ret void
1512
1513Class test68_helper(void);
1514void test68(void) {
1515 __strong Class cl = test67_helper();
1516}
1517// CHECK: define void @test68()
1518// CHECK: [[CL:%.*]] = alloca i8*, align 8
1519// CHECK-NEXT: [[T0:%.*]] = call i8* @test67_helper()
1520// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1521// CHECK-NEXT: store i8* [[T1]], i8** [[CL]], align 8
1522// CHECK-NEXT: [[T2:%.*]] = load i8** [[CL]]
1523// CHECK-NEXT: call void @objc_release(i8* [[T2]])
1524// CHECK-NEXT: ret void
John McCall77fe6cd2012-01-29 07:46:59 +00001525
1526// rdar://problem/10564852
1527@interface Test69 @end
1528@implementation Test69
1529- (id) foo { return self; }
1530@end
1531// CHECK: define internal i8* @"\01-[Test69 foo]"(
1532// CHECK: [[SELF:%.*]] = alloca [[TEST69:%.*]]*, align 8
1533// CHECK: [[T0:%.*]] = load [[TEST69]]** [[SELF]], align 8
1534// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST69]]* [[T0]] to i8*
1535// CHECK-NEXT: ret i8* [[T1]]
Eli Friedmanb1e3f322012-02-22 05:38:59 +00001536
1537// rdar://problem/10907547
1538void test70(id i) {
1539 // CHECK: define void @test70
1540 // CHECK: store i8* null, i8**
1541 // CHECK: store i8* null, i8**
1542 // CHECK: [[ID:%.*]] = call i8* @objc_retain(i8*
1543 // CHECK: store i8* [[ID]], i8**
1544 id x[3] = {
1545 [2] = i
1546 };
1547}