blob: 21ff43128cc9880a124a42d5a09d39ee27c48dfc [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
Michael Gottesman554b07d2013-02-02 00:57:44 +00004// rdar://13129783. Check both native/non-native arc platforms. Here we check
5// that they treat nonlazybind differently.
6// RUN: %clang_cc1 -fobjc-runtime=macosx-10.6.0 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=ARC-ALIEN %s
7// RUN: %clang_cc1 -fobjc-runtime=macosx-10.7.0 -triple x86_64-apple-darwin11 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=ARC-NATIVE %s
8
Michael Gottesman554b07d2013-02-02 00:57:44 +00009// ARC-ALIEN: declare extern_weak void @objc_storeStrong(i8**, i8*)
Fariborz Jahanian41a6a3e2013-02-21 00:40:10 +000010// ARC-ALIEN: declare extern_weak i8* @objc_retain(i8*)
Michael Gottesman554b07d2013-02-02 00:57:44 +000011// ARC-ALIEN: declare extern_weak i8* @objc_autoreleaseReturnValue(i8*)
Bill Wendling89924572013-02-27 00:06:04 +000012// ARC-ALIEN: declare i8* @objc_msgSend(i8*, i8*, ...) [[NLB:#[0-9]+]]
Michael Gottesman554b07d2013-02-02 00:57:44 +000013// ARC-ALIEN: declare extern_weak void @objc_release(i8*)
14// ARC-ALIEN: declare extern_weak i8* @objc_retainAutoreleasedReturnValue(i8*)
15// ARC-ALIEN: declare extern_weak i8* @objc_initWeak(i8**, i8*)
16// ARC-ALIEN: declare extern_weak i8* @objc_storeWeak(i8**, i8*)
17// ARC-ALIEN: declare extern_weak i8* @objc_loadWeakRetained(i8**)
18// ARC-ALIEN: declare extern_weak void @objc_destroyWeak(i8**)
19// ARC-ALIEN: declare extern_weak i8* @objc_autorelease(i8*)
20// ARC-ALIEN: declare extern_weak i8* @objc_retainAutorelease(i8*)
21
Michael Gottesman554b07d2013-02-02 00:57:44 +000022// ARC-NATIVE: declare void @objc_storeStrong(i8**, i8*)
Bill Wendling89924572013-02-27 00:06:04 +000023// ARC-NATIVE: declare i8* @objc_retain(i8*) [[NLB:#[0-9]+]]
Michael Gottesman554b07d2013-02-02 00:57:44 +000024// ARC-NATIVE: declare i8* @objc_autoreleaseReturnValue(i8*)
Bill Wendling89924572013-02-27 00:06:04 +000025// ARC-NATIVE: declare i8* @objc_msgSend(i8*, i8*, ...) [[NLB]]
26// ARC-NATIVE: declare void @objc_release(i8*) [[NLB]]
Michael Gottesman554b07d2013-02-02 00:57:44 +000027// ARC-NATIVE: declare i8* @objc_retainAutoreleasedReturnValue(i8*)
28// ARC-NATIVE: declare i8* @objc_initWeak(i8**, i8*)
29// ARC-NATIVE: declare i8* @objc_storeWeak(i8**, i8*)
30// ARC-NATIVE: declare i8* @objc_loadWeakRetained(i8**)
31// ARC-NATIVE: declare void @objc_destroyWeak(i8**)
32// ARC-NATIVE: declare i8* @objc_autorelease(i8*)
33// ARC-NATIVE: declare i8* @objc_retainAutorelease(i8*)
34
John McCallf85e1932011-06-15 23:02:42 +000035// CHECK: define void @test0
36void test0(id x) {
37 // CHECK: [[X:%.*]] = alloca i8*
38 // CHECK-NEXT: [[PARM:%.*]] = call i8* @objc_retain(i8* {{.*}})
39 // CHECK-NEXT: store i8* [[PARM]], i8** [[X]]
40 // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]]
41 // CHECK-NEXT: call void @objc_release(i8* [[TMP]])
42 // CHECK-NEXT: ret void
43}
44
45// CHECK: define i8* @test1(i8*
46id test1(id x) {
John McCallf48f7962012-01-29 02:35:02 +000047 // CHECK: [[X:%.*]] = alloca i8*
John McCallf85e1932011-06-15 23:02:42 +000048 // CHECK-NEXT: [[Y:%.*]] = alloca i8*
49 // CHECK-NEXT: alloca i32
50 // CHECK-NEXT: [[PARM:%.*]] = call i8* @objc_retain(i8* {{%.*}})
51 // CHECK-NEXT: store i8* [[PARM]], i8** [[X]]
52 // CHECK-NEXT: store i8* null, i8** [[Y]]
53 // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]]
John McCallf48f7962012-01-29 02:35:02 +000054 // CHECK-NEXT: [[RET:%.*]] = call i8* @objc_retain(i8* [[T0]])
John McCallf85e1932011-06-15 23:02:42 +000055 // CHECK-NEXT: store i32
56 // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]]
57 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
58 // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]]
59 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
Chad Rosierdf76f1e2012-12-12 17:52:21 +000060 // CHECK-NEXT: [[T1:%.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* [[RET]])
John McCallf85e1932011-06-15 23:02:42 +000061 // CHECK-NEXT: ret i8* [[T1]]
62 id y;
63 return y;
64}
65
66@interface Test2
67+ (void) class_method;
68- (void) inst_method;
69@end
70@implementation Test2
71
72// The self pointer of a class method is not retained.
73// CHECK: define internal void @"\01+[Test2 class_method]"
74// CHECK: alloca
75// CHECK-NEXT: alloca
76// CHECK-NEXT: store
77// CHECK-NEXT: store
78// CHECK-NEXT: ret void
79+ (void) class_method {}
80
81// The self pointer of an instance method is not retained.
82// CHECK: define internal void @"\01-[Test2 inst_method]"
83// CHECK: alloca
84// CHECK-NEXT: alloca
85// CHECK-NEXT: store
86// CHECK-NEXT: store
87// CHECK-NEXT: ret void
88- (void) inst_method {}
89@end
90
91@interface Test3
92+ (id) alloc;
93- (id) initWith: (int) x;
94- (id) copy;
95@end
96
97// CHECK: define void @test3_unelided()
98void test3_unelided() {
99 extern void test3_helper(void);
100
101 // CHECK: [[X:%.*]] = alloca [[TEST3:%.*]]*
102 // CHECK-NEXT: store [[TEST3]]* null, [[TEST3]]** [[X]], align
103 Test3 *x;
104
105 // Call to +alloc.
106 // CHECK-NEXT: load {{.*}}* @"\01L_OBJC_CLASSLIST_REFERENCES_
107 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
108 // CHECK-NEXT: bitcast
109 // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
110 // CHECK-NEXT: bitcast
111 // CHECK-NEXT: bitcast
112 // CHECK-NEXT: call void @objc_release(i8*
113 [Test3 alloc];
114
115 // CHECK-NEXT: [[T0:%.*]] = load [[TEST3]]** [[X]]
116 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
117 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST3]]* [[T0]] to i8*
118 // CHECK-NEXT: [[COPY:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend {{.*}})(i8* [[T1]],
Bill Wendling4e1125f2013-02-22 09:10:20 +0000119 // CHECK-NEXT: call void @objc_release(i8* [[COPY]]) [[NUW:#[0-9]+]]
John McCallf85e1932011-06-15 23:02:42 +0000120 [x copy];
121
122 // CHECK-NEXT: [[T0:%.*]] = load [[TEST3]]** [[X]]
123 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST3]]* [[T0]] to i8*
Bill Wendling4e1125f2013-02-22 09:10:20 +0000124 // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000125 // CHECK-NEXT: ret void
126}
127
128// CHECK: define void @test3()
129void test3() {
130 // CHECK: [[X:%.*]] = alloca i8*
131
132 id x = [[Test3 alloc] initWith: 5];
133
134 // Call to +alloc.
135 // CHECK-NEXT: load {{.*}}* @"\01L_OBJC_CLASSLIST_REFERENCES_
136 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
137 // CHECK-NEXT: bitcast
138 // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
139 // CHECK-NEXT: bitcast
140
141 // Call to -initWith: with elided retain of consumed argument.
142 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
143 // CHECK-NEXT: bitcast
144 // CHECK-NEXT: [[INIT:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i32)*)(i8*
145 // CHECK-NEXT: bitcast
146 // CHECK-NEXT: [[INIT:%.*]] = bitcast
147 // Assignment for initialization, retention elided.
148 // CHECK-NEXT: store i8* [[INIT]], i8** [[X]]
149
150 // Call to -copy.
151 // CHECK-NEXT: [[V:%.*]] = load i8** [[X]]
152 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
153 // CHECK-NEXT: [[COPY:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend {{.*}})(i8* [[V]],
154
155 // Assignment to x.
156 // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]]
157 // CHECK-NEXT: store i8* [[COPY]], i8** [[X]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000158 // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000159
160 x = [x copy];
161
162 // Cleanup for x.
163 // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000164 // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000165
166 // CHECK-NEXT: ret void
167}
168
169// CHECK: define i8* @test4()
170id test4() {
171 // Call to +alloc.
172 // CHECK: load {{.*}}* @"\01L_OBJC_CLASSLIST_REFERENCES_
173 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
174 // CHECK-NEXT: bitcast
175 // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
176 // CHECK-NEXT: [[ALLOC:%.*]] = bitcast
177
178 // Call to -initWith: with elided retain of consumed argument.
179 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
180 // CHECK-NEXT: [[ALLOC:%.*]] = bitcast
181 // CHECK-NEXT: [[INIT:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i32)*)(i8* [[ALLOC]],
182
183 // Initialization of return value, occuring within full-expression.
184 // Retain/release elided.
185 // CHECK-NEXT: bitcast
186 // CHECK-NEXT: [[INIT:%.*]] = bitcast
Chad Rosierdf76f1e2012-12-12 17:52:21 +0000187 // CHECK-NEXT: [[RET:%.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* [[INIT]])
John McCallf85e1932011-06-15 23:02:42 +0000188
189 // CHECK-NEXT: ret i8* [[RET]]
190
191 return [[Test3 alloc] initWith: 6];
192}
193
194@interface Test5 {
195@public
196 id var;
197}
198@end
199
200// CHECK: define void @test5
201void test5(Test5 *x, id y) {
202 // Prologue.
203 // CHECK: [[X:%.*]] = alloca [[TEST5:%.*]]*,
204 // CHECK-NEXT: [[Y:%.*]] = alloca i8*
205 // CHECK-NEXT: bitcast [[TEST5]]* {{%.*}} to i8*
206 // CHECK-NEXT: call i8* @objc_retain
207 // CHECK-NEXT: [[PARMX:%.*]] = bitcast i8* {{%.*}} to [[TEST5]]*
208 // CHECK-NEXT: store [[TEST5]]* [[PARMX]], [[TEST5]]** [[X]]
209 // CHECK-NEXT: call i8* @objc_retain
210 // CHECK-NEXT: store
211
212 // CHECK-NEXT: load [[TEST5]]** [[X]]
213 // CHECK-NEXT: load i64* @"OBJC_IVAR_$_Test5.var"
214 // CHECK-NEXT: bitcast
215 // CHECK-NEXT: getelementptr
216 // CHECK-NEXT: [[VAR:%.*]] = bitcast
217 // CHECK-NEXT: [[TMP:%.*]] = load i8** [[VAR]]
218 // CHECK-NEXT: store i8* null, i8** [[VAR]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000219 // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000220 x->var = 0;
221
222 // CHECK-NEXT: [[YVAL:%.*]] = load i8** [[Y]]
223 // CHECK-NEXT: load [[TEST5]]** [[X]]
224 // CHECK-NEXT: load i64* @"OBJC_IVAR_$_Test5.var"
225 // CHECK-NEXT: bitcast
226 // CHECK-NEXT: getelementptr
227 // CHECK-NEXT: [[VAR:%.*]] = bitcast
Bill Wendling4e1125f2013-02-22 09:10:20 +0000228 // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* [[YVAL]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000229 // CHECK-NEXT: [[TMP:%.*]] = load i8** [[VAR]]
230 // CHECK-NEXT: store i8* [[T0]], i8** [[VAR]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000231 // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000232 x->var = y;
233
234 // Epilogue.
235 // CHECK-NEXT: [[TMP:%.*]] = load i8** [[Y]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000236 // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000237 // CHECK-NEXT: [[T0:%.*]] = load [[TEST5]]** [[X]]
238 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST5]]* [[T0]] to i8*
Bill Wendling4e1125f2013-02-22 09:10:20 +0000239 // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000240 // CHECK-NEXT: ret void
241}
242
243id test6_helper(void) __attribute__((ns_returns_retained));
244// CHECK: define void @test6()
245void test6() {
246 // CHECK: [[X:%.*]] = alloca i8*
247 // CHECK-NEXT: [[CALL:%.*]] = call i8* @test6_helper()
248 // CHECK-NEXT: store i8* [[CALL]], i8** [[X]]
249 // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000250 // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release
John McCallf85e1932011-06-15 23:02:42 +0000251 // CHECK-NEXT: ret void
252 id x = test6_helper();
253}
254
255void test7_helper(id __attribute__((ns_consumed)));
256// CHECK: define void @test7()
257void test7() {
258 // CHECK: [[X:%.*]] = alloca i8*
259 // CHECK-NEXT: store i8* null, i8** [[X]]
260 // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000261 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000262 // CHECK-NEXT: call void @test7_helper(i8* [[T1]])
263 // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000264 // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release
John McCallf85e1932011-06-15 23:02:42 +0000265 // CHECK-NEXT: ret void
266 id x;
267 test7_helper(x);
268}
269
270id test8_helper(void) __attribute__((ns_returns_retained));
271void test8() {
272 __unsafe_unretained id x = test8_helper();
273 // CHECK: [[X:%.*]] = alloca i8*
274 // CHECK-NEXT: [[T0:%.*]] = call i8* @test8_helper()
275 // CHECK-NEXT: store i8* [[T0]], i8** [[X]]
John McCall5b07e802013-03-13 03:10:54 +0000276 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release
John McCallf85e1932011-06-15 23:02:42 +0000277 // CHECK-NEXT: ret void
278}
279
280@interface Test10
281@property (retain) Test10 *me;
282@end
283void test10() {
284 Test10 *x;
285 id y = x.me.me;
286
287 // CHECK: define void @test10()
288 // CHECK: [[X:%.*]] = alloca [[TEST10:%.*]]*, align
289 // CHECK-NEXT: [[Y:%.*]] = alloca i8*, align
290 // CHECK-NEXT: store [[TEST10]]* null, [[TEST10]]** [[X]]
291 // CHECK-NEXT: load [[TEST10]]** [[X]], align
292 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_{{[0-9]*}}"
293 // CHECK-NEXT: bitcast
John McCall7e5e5f42011-07-07 06:58:02 +0000294 // CHECK-NEXT: [[T0:%.*]] = call [[TEST10]]* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
295 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8*
296 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]])
297 // CHECK-NEXT: [[V:%.*]] = bitcast i8* [[T2]] to [[TEST10]]*
John McCallf85e1932011-06-15 23:02:42 +0000298 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_{{[0-9]*}}"
299 // CHECK-NEXT: bitcast
300 // CHECK-NEXT: [[T0:%.*]] = call [[TEST10]]* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
301 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8*
302 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]])
303 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST10]]*
304 // CHECK-NEXT: [[T4:%.*]] = bitcast [[TEST10]]* [[T3]] to i8*
305 // CHECK-NEXT: store i8* [[T4]], i8** [[Y]]
John McCall7e5e5f42011-07-07 06:58:02 +0000306 // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST10]]* [[V]] to i8*
307 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
John McCallf85e1932011-06-15 23:02:42 +0000308 // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]]
309 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
310 // CHECK-NEXT: [[T0:%.*]] = load [[TEST10]]** [[X]]
311 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8*
312 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
313 // CHECK-NEXT: ret void
314}
315
316void test11(id (*f)(void) __attribute__((ns_returns_retained))) {
317 // CHECK: define void @test11(
318 // CHECK: [[F:%.*]] = alloca i8* ()*, align
319 // CHECK-NEXT: [[X:%.*]] = alloca i8*, align
320 // CHECK-NEXT: store i8* ()* {{%.*}}, i8* ()** [[F]], align
321 // CHECK-NEXT: [[T0:%.*]] = load i8* ()** [[F]], align
322 // CHECK-NEXT: [[T1:%.*]] = call i8* [[T0]]()
323 // CHECK-NEXT: store i8* [[T1]], i8** [[X]], align
324 // CHECK-NEXT: [[T3:%.*]] = load i8** [[X]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000325 // CHECK-NEXT: call void @objc_release(i8* [[T3]]) [[NUW]], !clang.imprecise_release
John McCallf85e1932011-06-15 23:02:42 +0000326 // CHECK-NEXT: ret void
327 id x = f();
328}
329
330void test12(void) {
331 extern id test12_helper(void);
332
333 // CHECK: define void @test12()
334 // CHECK: [[X:%.*]] = alloca i8*, align
335 // CHECK-NEXT: [[Y:%.*]] = alloca i8*, align
336
337 __weak id x = test12_helper();
338 // CHECK-NEXT: [[T0:%.*]] = call i8* @test12_helper()
John McCall7e5e5f42011-07-07 06:58:02 +0000339 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
340 // CHECK-NEXT: call i8* @objc_initWeak(i8** [[X]], i8* [[T1]])
341 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +0000342
343 x = test12_helper();
John McCall7e5e5f42011-07-07 06:58:02 +0000344 // CHECK-NEXT: [[T0:%.*]] = call i8* @test12_helper()
345 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
John McCallf85e1932011-06-15 23:02:42 +0000346 // CHECK-NEXT: call i8* @objc_storeWeak(i8** [[X]], i8* [[T1]])
John McCall7e5e5f42011-07-07 06:58:02 +0000347 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +0000348
349 id y = x;
350 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_loadWeakRetained(i8** [[X]])
351 // CHECK-NEXT: store i8* [[T2]], i8** [[Y]], align
352
353 // CHECK-NEXT: [[T4:%.*]] = load i8** [[Y]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000354 // CHECK-NEXT: call void @objc_release(i8* [[T4]]) [[NUW]], !clang.imprecise_release
John McCallf85e1932011-06-15 23:02:42 +0000355 // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]])
Nadav Rotem495cfa42013-03-23 06:43:35 +0000356 // CHECK: ret void
John McCallf85e1932011-06-15 23:02:42 +0000357}
358
359// Indirect consuming calls.
360void test13(void) {
361 // CHECK: define void @test13()
362 // CHECK: [[X:%.*]] = alloca i8*, align
363 // CHECK-NEXT: store i8* null, i8** [[X]], align
364 id x;
365
366 typedef void fnty(id __attribute__((ns_consumed)));
367 extern fnty *test13_func;
368 // CHECK-NEXT: [[FN:%.*]] = load void (i8*)** @test13_func, align
369 // CHECK-NEXT: [[X_VAL:%.*]] = load i8** [[X]], align
Bill Wendling4e1125f2013-02-22 09:10:20 +0000370 // CHECK-NEXT: [[X_TMP:%.*]] = call i8* @objc_retain(i8* [[X_VAL]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000371 // CHECK-NEXT: call void [[FN]](i8* [[X_TMP]])
372 test13_func(x);
373
374 extern fnty ^test13_block;
375 // CHECK-NEXT: [[TMP:%.*]] = load void (i8*)** @test13_block, align
376 // CHECK-NEXT: [[BLOCK:%.*]] = bitcast void (i8*)* [[TMP]] to [[BLOCKTY:%.*]]*
377 // CHECK-NEXT: [[BLOCK_FN_PTR:%.*]] = getelementptr inbounds [[BLOCKTY]]* [[BLOCK]], i32 0, i32 3
378 // CHECK-NEXT: [[BLOCK_OPAQUE:%.*]] = bitcast [[BLOCKTY]]* [[BLOCK]] to i8*
379 // CHECK-NEXT: [[X_VAL:%.*]] = load i8** [[X]], align
Bill Wendling4e1125f2013-02-22 09:10:20 +0000380 // CHECK-NEXT: [[X_TMP:%.*]] = call i8* @objc_retain(i8* [[X_VAL]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000381 // CHECK-NEXT: [[BLOCK_FN_TMP:%.*]] = load i8** [[BLOCK_FN_PTR]]
382 // CHECK-NEXT: [[BLOCK_FN:%.*]] = bitcast i8* [[BLOCK_FN_TMP]] to void (i8*, i8*)*
383 // CHECK-NEXT: call void [[BLOCK_FN]](i8* [[BLOCK_OPAQUE]], i8* [[X_TMP]])
384 test13_block(x);
385
386 // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000387 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000388 // CHECK-NEXT: ret void
389}
390
391@interface Test16_super @end
392@interface Test16 : Test16_super {
393 id z;
394}
395@property (assign) int x;
396@property (retain) id y;
397- (void) dealloc;
398@end
399@implementation Test16
400@synthesize x;
401@synthesize y;
402- (void) dealloc {
403 // CHECK: define internal void @"\01-[Test16 dealloc]"(
404 // CHECK: [[SELF:%.*]] = alloca [[TEST16:%.*]]*, align
405 // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align
406 // CHECK-NEXT: alloca
407 // CHECK-NEXT: store [[TEST16]]* {{%.*}}, [[TEST16]]** [[SELF]], align
408 // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]]
409 // CHECK-NEXT: [[BASE:%.*]] = load [[TEST16]]** [[SELF]]
410
411 // Call super.
412 // CHECK-NEXT: [[BASE2:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8*
413 // CHECK-NEXT: [[T0:%.*]] = getelementptr
414 // CHECK-NEXT: store i8* [[BASE2]], i8** [[T0]]
415 // CHECK-NEXT: load {{%.*}}** @"\01L_OBJC_CLASSLIST_SUP_REFS_$_
416 // CHECK-NEXT: bitcast
417 // CHECK-NEXT: getelementptr
418 // CHECK-NEXT: store
419 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
420 // CHECK-NEXT: call void bitcast (i8* ({{.*}})* @objc_msgSendSuper2 to void (
421 // CHECK-NEXT: ret void
422}
423
424// .cxx_destruct
425 // CHECK: define internal void @"\01-[Test16 .cxx_destruct]"(
426 // CHECK: [[SELF:%.*]] = alloca [[TEST16:%.*]]*, align
427 // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align
428 // CHECK-NEXT: store [[TEST16]]* {{%.*}}, [[TEST16]]** [[SELF]], align
429 // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]]
430 // CHECK-NEXT: [[BASE:%.*]] = load [[TEST16]]** [[SELF]]
431
432 // Destroy y.
433 // CHECK-NEXT: [[Y_OFF:%.*]] = load i64* @"OBJC_IVAR_$_Test16.y"
434 // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8*
435 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[Y_OFF]]
436 // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8**
Bill Wendling4e1125f2013-02-22 09:10:20 +0000437 // CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000438
439 // Destroy z.
440 // CHECK-NEXT: [[Z_OFF:%.*]] = load i64* @"OBJC_IVAR_$_Test16.z"
441 // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8*
442 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[Z_OFF]]
443 // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8**
Bill Wendling4e1125f2013-02-22 09:10:20 +0000444 // CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000445
446 // CHECK-NEXT: ret void
447
448@end
449
450// This shouldn't crash.
451@interface Test17A
452@property (assign) int x;
453@end
454@interface Test17B : Test17A
455@end
456@implementation Test17B
457- (int) x { return super.x + 1; }
458@end
459
John McCallf85e1932011-06-15 23:02:42 +0000460void test19() {
461 // CHECK: define void @test19()
462 // CHECK: [[X:%.*]] = alloca [5 x i8*], align 16
Nadav Rotem495cfa42013-03-23 06:43:35 +0000463 // CHECK: call void @llvm.lifetime.start
John McCallf85e1932011-06-15 23:02:42 +0000464 // CHECK-NEXT: [[T0:%.*]] = bitcast [5 x i8*]* [[X]] to i8*
Nadav Rotem495cfa42013-03-23 06:43:35 +0000465 // CHECK: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 40, i32 16, i1 false)
John McCallf85e1932011-06-15 23:02:42 +0000466 id x[5];
467
468 extern id test19_helper(void);
469 x[2] = test19_helper();
470
471 // CHECK-NEXT: [[CALL:%.*]] = call i8* @test19_helper()
Bill Wendling4e1125f2013-02-22 09:10:20 +0000472 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000473 // CHECK-NEXT: [[SLOT:%.*]] = getelementptr inbounds [5 x i8*]* [[X]], i32 0, i64 2
474 // CHECK-NEXT: [[T0:%.*]] = load i8** [[SLOT]]
475 // CHECK-NEXT: store i8* [[T1]], i8** [[SLOT]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000476 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000477
478 // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [5 x i8*]* [[X]], i32 0, i32 0
479 // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 5
480 // CHECK-NEXT: br label
481
John McCallbdc4d802011-07-09 01:37:26 +0000482 // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ]
483 // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1
484 // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000485 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release
John McCallbdc4d802011-07-09 01:37:26 +0000486 // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]]
487 // CHECK-NEXT: br i1 [[EQ]],
John McCallf85e1932011-06-15 23:02:42 +0000488
489 // CHECK: ret void
490}
491
492void test20(unsigned n) {
493 // CHECK: define void @test20
494 // CHECK: [[N:%.*]] = alloca i32, align 4
495 // CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca i8*
496 // CHECK-NEXT: store i32 {{%.*}}, i32* [[N]], align 4
497
498 id x[n];
499
500 // Capture the VLA size.
John McCallbc8d40d2011-06-24 21:55:10 +0000501 // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4
502 // CHECK-NEXT: [[DIM:%.*]] = zext i32 [[T0]] to i64
503
504 // Save the stack pointer.
John McCallf85e1932011-06-15 23:02:42 +0000505 // CHECK-NEXT: [[T0:%.*]] = call i8* @llvm.stacksave()
506 // CHECK-NEXT: store i8* [[T0]], i8** [[SAVED_STACK]]
John McCallf85e1932011-06-15 23:02:42 +0000507
508 // Allocate the VLA.
John McCallbc8d40d2011-06-24 21:55:10 +0000509 // CHECK-NEXT: [[VLA:%.*]] = alloca i8*, i64 [[DIM]], align 16
John McCallf85e1932011-06-15 23:02:42 +0000510
511 // Zero-initialize.
512 // CHECK-NEXT: [[T0:%.*]] = bitcast i8** [[VLA]] to i8*
John McCallbc8d40d2011-06-24 21:55:10 +0000513 // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 [[DIM]], 8
514 // 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 +0000515
516 // Destroy.
John McCallbc8d40d2011-06-24 21:55:10 +0000517 // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[VLA]], i64 [[DIM]]
John McCallfbf780a2011-07-13 08:09:46 +0000518 // CHECK-NEXT: [[EMPTY:%.*]] = icmp eq i8** [[VLA]], [[END]]
519 // CHECK-NEXT: br i1 [[EMPTY]]
John McCallf85e1932011-06-15 23:02:42 +0000520
John McCallbdc4d802011-07-09 01:37:26 +0000521 // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ]
522 // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1
523 // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000524 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release
John McCallbdc4d802011-07-09 01:37:26 +0000525 // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[VLA]]
526 // CHECK-NEXT: br i1 [[EQ]],
John McCallf85e1932011-06-15 23:02:42 +0000527
528 // CHECK: [[T0:%.*]] = load i8** [[SAVED_STACK]]
529 // CHECK-NEXT: call void @llvm.stackrestore(i8* [[T0]])
530 // CHECK-NEXT: ret void
531}
532
533void test21(unsigned n) {
534 // CHECK: define void @test21
535 // CHECK: [[N:%.*]] = alloca i32, align 4
536 // CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca i8*
537 // CHECK-NEXT: store i32 {{%.*}}, i32* [[N]], align 4
538
539 id x[2][n][3];
540
541 // Capture the VLA size.
John McCallbc8d40d2011-06-24 21:55:10 +0000542 // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4
543 // CHECK-NEXT: [[DIM:%.*]] = zext i32 [[T0]] to i64
544
John McCallf85e1932011-06-15 23:02:42 +0000545 // CHECK-NEXT: [[T0:%.*]] = call i8* @llvm.stacksave()
546 // CHECK-NEXT: store i8* [[T0]], i8** [[SAVED_STACK]]
John McCallbc8d40d2011-06-24 21:55:10 +0000547
John McCallf85e1932011-06-15 23:02:42 +0000548
549 // Allocate the VLA.
John McCallbc8d40d2011-06-24 21:55:10 +0000550 // CHECK-NEXT: [[T0:%.*]] = mul nuw i64 2, [[DIM]]
551 // CHECK-NEXT: [[VLA:%.*]] = alloca [3 x i8*], i64 [[T0]], align 16
John McCallf85e1932011-06-15 23:02:42 +0000552
553 // Zero-initialize.
554 // CHECK-NEXT: [[T0:%.*]] = bitcast [3 x i8*]* [[VLA]] to i8*
John McCallbc8d40d2011-06-24 21:55:10 +0000555 // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 2, [[DIM]]
556 // CHECK-NEXT: [[T2:%.*]] = mul nuw i64 [[T1]], 24
557 // 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 +0000558
559 // Destroy.
John McCallbc8d40d2011-06-24 21:55:10 +0000560 // CHECK-NEXT: [[T0:%.*]] = mul nuw i64 2, [[DIM]]
John McCallf85e1932011-06-15 23:02:42 +0000561 // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [3 x i8*]* [[VLA]], i32 0, i32 0
John McCallbc8d40d2011-06-24 21:55:10 +0000562 // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 [[T0]], 3
563 // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 [[T1]]
John McCallfbf780a2011-07-13 08:09:46 +0000564 // CHECK-NEXT: [[EMPTY:%.*]] = icmp eq i8** [[BEGIN]], [[END]]
565 // CHECK-NEXT: br i1 [[EMPTY]]
John McCallf85e1932011-06-15 23:02:42 +0000566
John McCallbdc4d802011-07-09 01:37:26 +0000567 // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ]
568 // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1
569 // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000570 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release
John McCallbdc4d802011-07-09 01:37:26 +0000571 // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]]
572 // CHECK-NEXT: br i1 [[EQ]],
John McCallf85e1932011-06-15 23:02:42 +0000573
574 // CHECK: [[T0:%.*]] = load i8** [[SAVED_STACK]]
575 // CHECK-NEXT: call void @llvm.stackrestore(i8* [[T0]])
576 // CHECK-NEXT: ret void
577}
578
John McCallf85e1932011-06-15 23:02:42 +0000579// rdar://problem/8922540
580// Note that we no longer emit .release_ivars flags.
John McCallb03527a2012-10-17 04:53:31 +0000581// rdar://problem/12492434
582// Note that we set the flag saying that we need destruction *and*
583// the flag saying that we don't also need construction.
584// CHECK-GLOBALS: @"\01l_OBJC_CLASS_RO_$_Test23" = internal global [[RO_T:%.*]] { i32 390,
John McCallf85e1932011-06-15 23:02:42 +0000585@interface Test23 { id x; } @end
586@implementation Test23 @end
587
588// CHECK-GLOBALS: @"\01l_OBJC_CLASS_RO_$_Test24" = internal global [[RO_T:%.*]] { i32 130,
589@interface Test24 {} @end
590@implementation Test24 @end
591
John McCallf85e1932011-06-15 23:02:42 +0000592// rdar://problem/8941012
593@interface Test26 { id x[4]; } @end
594@implementation Test26 @end
595// CHECK: define internal void @"\01-[Test26 .cxx_destruct]"(
596// CHECK: [[SELF:%.*]] = load [[TEST26:%.*]]**
597// CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test26.x"
598// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST26]]* [[SELF]] to i8*
599// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[OFFSET]]
600// CHECK-NEXT: [[X:%.*]] = bitcast i8* [[T1]] to [4 x i8*]*
601// CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [4 x i8*]* [[X]], i32 0, i32 0
602// CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 4
603// CHECK-NEXT: br label
John McCall9928c482011-07-12 16:41:08 +0000604// CHECK: [[PAST:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ]
605// CHECK-NEXT: [[CUR]] = getelementptr inbounds i8** [[PAST]], i64 -1
606// CHECK-NEXT: call void @objc_storeStrong(i8** [[CUR]], i8* null)
607// CHECK-NEXT: [[ISDONE:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]]
John McCallf85e1932011-06-15 23:02:42 +0000608// CHECK-NEXT: br i1 [[ISDONE]],
John McCallf85e1932011-06-15 23:02:42 +0000609// CHECK: ret void
610
611// Check that 'init' retains self.
612@interface Test27
613- (id) init;
614@end
615@implementation Test27
616- (id) init { return self; }
617// CHECK: define internal i8* @"\01-[Test27 init]"
John McCallf48f7962012-01-29 02:35:02 +0000618// CHECK: [[SELF:%.*]] = alloca [[TEST27:%.*]]*,
John McCallf85e1932011-06-15 23:02:42 +0000619// CHECK-NEXT: [[CMD:%.*]] = alloca i8*,
620// CHECK-NEXT: [[DEST:%.*]] = alloca i32
621// CHECK-NEXT: store [[TEST27]]* {{%.*}}, [[TEST27]]** [[SELF]]
622// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]]
623// CHECK-NEXT: [[T0:%.*]] = load [[TEST27]]** [[SELF]]
624// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST27]]* [[T0]] to i8*
John McCall7cca8212013-03-19 07:04:25 +0000625// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]])
626// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST27]]*
627// CHECK-NEXT: [[RET:%.*]] = bitcast [[TEST27]]* [[T3]] to i8*
John McCallf85e1932011-06-15 23:02:42 +0000628// CHECK-NEXT: store i32 {{[0-9]+}}, i32* [[DEST]]
629// CHECK-NEXT: [[T0:%.*]] = load [[TEST27]]** [[SELF]]
630// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST27]]* [[T0]] to i8*
631// CHECK-NEXT: call void @objc_release(i8* [[T1]])
John McCallf48f7962012-01-29 02:35:02 +0000632// CHECK-NEXT: ret i8* [[RET]]
John McCallf85e1932011-06-15 23:02:42 +0000633
634@end
635
636// rdar://problem/8087194
637@interface Test28
638@property (copy) id prop;
639@end
640@implementation Test28
641@synthesize prop;
642@end
643// CHECK: define internal void @"\01-[Test28 .cxx_destruct]"
644// CHECK: [[SELF:%.*]] = load [[TEST28:%.*]]**
645// CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test28.prop"
646// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST28]]* [[SELF]] to i8*
647// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[OFFSET]]
648// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8**
649// CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null)
650// CHECK-NEXT: ret void
651
652@interface Test29_super
653- (id) initWithAllocator: (id) allocator;
654@end
655@interface Test29 : Test29_super
656- (id) init;
657- (id) initWithAllocator: (id) allocator;
658@end
659@implementation Test29
660static id _test29_allocator = 0;
661- (id) init {
Bill Wendlingc0dcc2d2013-02-15 21:30:01 +0000662// CHECK: define internal i8* @"\01-[Test29 init]"([[TEST29:%[^*]*]]* {{%.*}},
John McCallf48f7962012-01-29 02:35:02 +0000663// CHECK: [[SELF:%.*]] = alloca [[TEST29]]*, align 8
John McCallf85e1932011-06-15 23:02:42 +0000664// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align 8
665// CHECK-NEXT: [[CLEANUP:%.*]] = alloca i32
666// CHECK-NEXT: store [[TEST29]]* {{%.*}}, [[TEST29]]** [[SELF]]
667// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]]
668
669// Evaluate arguments. Note that the send argument is evaluated
670// before the zeroing of self.
671// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]], align 8
672// CHECK-NEXT: [[T1:%.*]] = load i8** @_test29_allocator, align 8
673
674// Implicit null of 'self', i.e. direct transfer of ownership.
675// CHECK-NEXT: store [[TEST29]]* null, [[TEST29]]** [[SELF]]
676
677// Actual message send.
678// CHECK-NEXT: [[T2:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
679// CHECK-NEXT: [[T3:%.*]] = bitcast [[TEST29]]* [[T0]] to i8*
680// CHECK-NEXT: [[CALL:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T3]], i8* [[T2]], i8* [[T1]])
681
682// Implicit write of result back into 'self'. This is not supposed to
683// be detectable because we're supposed to ban accesses to the old
684// self value past the delegate init call.
685// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]*
686// CHECK-NEXT: store [[TEST29]]* [[T0]], [[TEST29]]** [[SELF]]
687
688// Return statement.
689// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[CALL]]
690// CHECK-NEXT: [[CALL:%.*]] = bitcast
John McCall7cca8212013-03-19 07:04:25 +0000691// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* [[CALL]]) [[NUW]]
692// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[TEST29]]*
693// CHECK-NEXT: [[RET:%.*]] = bitcast [[TEST29]]* [[T1]] to i8*
John McCallf85e1932011-06-15 23:02:42 +0000694// CHECK-NEXT: store i32 1, i32* [[CLEANUP]]
695
696// Cleanup.
697// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]]
698// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8*
Bill Wendling4e1125f2013-02-22 09:10:20 +0000699// CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release
John McCallf85e1932011-06-15 23:02:42 +0000700
701// Return.
John McCallf48f7962012-01-29 02:35:02 +0000702// CHECK-NEXT: ret i8* [[RET]]
John McCallf85e1932011-06-15 23:02:42 +0000703 return [self initWithAllocator: _test29_allocator];
704}
705- (id) initWithAllocator: (id) allocator {
706// CHECK: define internal i8* @"\01-[Test29 initWithAllocator:]"(
John McCallf48f7962012-01-29 02:35:02 +0000707// CHECK: [[SELF:%.*]] = alloca [[TEST29]]*, align 8
John McCallf85e1932011-06-15 23:02:42 +0000708// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align 8
709// CHECK-NEXT: [[ALLOCATOR:%.*]] = alloca i8*, align 8
710// CHECK-NEXT: alloca
711// CHECK-NEXT: [[CLEANUP:%.*]] = alloca i32
712// CHECK-NEXT: store [[TEST29]]* {{%.*}}, [[TEST29]]** [[SELF]]
713// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]]
714// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* {{%.*}})
715// CHECK-NEXT: store i8* [[T0]], i8** [[ALLOCATOR]]
716
717// Evaluate arguments. Note that the send argument is evaluated
718// before the zeroing of self.
719// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]]
720// CHECK-NEXT: [[T1:%.*]] = load i8** [[ALLOCATOR]], align 8
721
722// Implicit null of 'self', i.e. direct transfer of ownership.
723// CHECK-NEXT: store [[TEST29]]* null, [[TEST29]]** [[SELF]]
724
725// Actual message send.
726// CHECK: [[CALL:%.*]] = call {{.*}} @objc_msgSendSuper2
727
728// Implicit write of result back into 'self'. This is not supposed to
729// be detectable because we're supposed to ban accesses to the old
730// self value past the delegate init call.
731// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]*
732// CHECK-NEXT: store [[TEST29]]* [[T0]], [[TEST29]]** [[SELF]]
733
734// Assignment.
735// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]*
736// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8*
Bill Wendling4e1125f2013-02-22 09:10:20 +0000737// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000738// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST29]]*
739// CHECK-NEXT: [[T4:%.*]] = load [[TEST29]]** [[SELF]], align
740// CHECK-NEXT: store [[TEST29]]* [[T3]], [[TEST29]]** [[SELF]], align
741// CHECK-NEXT: [[T5:%.*]] = bitcast [[TEST29]]* [[T4]] to i8*
742// CHECK-NEXT: call void @objc_release(i8* [[T5]])
743
744// Return statement.
745// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]]
746// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8*
John McCall7cca8212013-03-19 07:04:25 +0000747// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* [[T1]]) [[NUW]]
748// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[TEST29]]*
749// CHECK-NEXT: [[RET:%.*]] = bitcast [[TEST29]]* [[T1]] to i8*
John McCallf85e1932011-06-15 23:02:42 +0000750// CHECK-NEXT: store i32 1, i32* [[CLEANUP]]
751
752// Cleanup.
753// CHECK-NEXT: [[T0:%.*]] = load i8** [[ALLOCATOR]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000754// CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release
John McCallf85e1932011-06-15 23:02:42 +0000755
756// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]]
757// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8*
Bill Wendling4e1125f2013-02-22 09:10:20 +0000758// CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release
John McCallf85e1932011-06-15 23:02:42 +0000759
760// Return.
John McCallf48f7962012-01-29 02:35:02 +0000761// CHECK-NEXT: ret i8* [[RET]]
John McCallf85e1932011-06-15 23:02:42 +0000762 self = [super initWithAllocator: allocator];
763 return self;
764}
765@end
766
767typedef struct Test30_helper Test30_helper;
768@interface Test30
769- (id) init;
770- (Test30_helper*) initHelper;
771@end
772@implementation Test30 {
773char *helper;
774}
775- (id) init {
Bill Wendlingc0dcc2d2013-02-15 21:30:01 +0000776// CHECK: define internal i8* @"\01-[Test30 init]"([[TEST30:%[^*]*]]* {{%.*}},
John McCallf48f7962012-01-29 02:35:02 +0000777// CHECK: [[RET:%.*]] = alloca [[TEST30]]*
John McCallf85e1932011-06-15 23:02:42 +0000778// CHECK-NEXT: alloca i8*
779// CHECK-NEXT: alloca i32
780// CHECK-NEXT: store [[TEST30]]* {{%.*}}, [[TEST30]]** [[SELF]]
781// CHECK-NEXT: store
782
783// Call.
784// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]]
785// CHECK-NEXT: [[T1:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
786// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST30]]* [[T0]] to i8*
787// CHECK-NEXT: [[CALL:%.*]] = call [[TEST30_HELPER:%.*]]* bitcast {{.*}} @objc_msgSend {{.*}}(i8* [[T2]], i8* [[T1]])
788
789// Assignment.
790// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST30_HELPER]]* [[CALL]] to i8*
791// CHECK-NEXT: [[T1:%.*]] = load [[TEST30]]** [[SELF]]
792// CHECK-NEXT: [[IVAR:%.*]] = load i64* @"OBJC_IVAR_$_Test30.helper"
793// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST30]]* [[T1]] to i8*
794// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[IVAR]]
795// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8**
796// CHECK-NEXT#: [[T5:%.*]] = load i8** [[T4]]
797// CHECK-NEXT#: [[T6:%.*]] = call i8* @objc_retain(i8* [[T0]])
798// CHECK-NEXT#: call void @objc_release(i8* [[T5]])
799// CHECK-NEXT: store i8* [[T0]], i8** [[T4]]
800
801// Return.
802// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]]
803// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST30]]* [[T0]] to i8*
John McCall7cca8212013-03-19 07:04:25 +0000804// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* [[T1]])
805// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[TEST30]]*
806// CHECK-NEXT: [[RET:%.*]] = bitcast [[TEST30]]* [[T1]] to i8*
John McCallf85e1932011-06-15 23:02:42 +0000807// CHECK-NEXT: store i32 1
808
809// Cleanup.
810// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]]
811// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST30]]* [[T0]] to i8*
812// CHECK-NEXT: call void @objc_release(i8* [[T1]])
813
814// Epilogue.
John McCallf48f7962012-01-29 02:35:02 +0000815// CHECK-NEXT: ret i8* [[RET]]
John McCallf85e1932011-06-15 23:02:42 +0000816 self->helper = [self initHelper];
817 return self;
818}
819- (Test30_helper*) initHelper {
820// CHECK: define internal [[TEST30_HELPER]]* @"\01-[Test30 initHelper]"(
821// CHECK: alloca
822// CHECK-NEXT: alloca
823// CHECK-NEXT: store
824// CHECK-NEXT: store
825// CHECK-NEXT: ret [[TEST30_HELPER]]* null
826 return 0;
827}
828
829@end
830
John McCallf85e1932011-06-15 23:02:42 +0000831__attribute__((ns_returns_retained)) id test32(void) {
832// CHECK: define i8* @test32()
833// CHECK: [[CALL:%.*]] = call i8* @test32_helper()
834// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]])
835// CHECK-NEXT: ret i8* [[T0]]
836 extern id test32_helper(void);
837 return test32_helper();
838}
839
840@class Test33_a;
841@interface Test33
842- (void) give: (Test33_a **) x;
843- (void) take: (Test33_a **) x;
844- (void) giveStrong: (out __strong Test33_a **) x;
845- (void) takeStrong: (inout __strong Test33_a **) x;
846- (void) giveOut: (out Test33_a **) x;
847@end
848void test33(Test33 *ptr) {
849 Test33_a *a;
850 [ptr give: &a];
851 [ptr take: &a];
852 [ptr giveStrong: &a];
853 [ptr takeStrong: &a];
854 [ptr giveOut: &a];
855
856 // CHECK: define void @test33([[TEST33:%.*]]*
857 // CHECK: [[PTR:%.*]] = alloca [[TEST33]]*
858 // CHECK-NEXT: [[A:%.*]] = alloca [[A_T:%.*]]*
859 // CHECK-NEXT: [[TEMP0:%.*]] = alloca [[A_T]]*
860 // CHECK-NEXT: [[TEMP1:%.*]] = alloca [[A_T]]*
861 // CHECK-NEXT: [[TEMP2:%.*]] = alloca [[A_T]]*
862 // CHECK-NEXT: bitcast
863 // CHECK-NEXT: objc_retain
864 // CHECK-NEXT: bitcast
865 // CHECK-NEXT: store
866 // CHECK-NEXT: store [[A_T]]* null, [[A_T]]** [[A]]
867
868 // CHECK-NEXT: load [[TEST33]]** [[PTR]]
John McCallb6a60792013-03-23 02:35:54 +0000869 // CHECK-NEXT: [[W0:%.*]] = load [[A_T]]** [[A]]
870 // CHECK-NEXT: store [[A_T]]* [[W0]], [[A_T]]** [[TEMP0]]
John McCallf85e1932011-06-15 23:02:42 +0000871 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
872 // CHECK-NEXT: bitcast
873 // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP0]])
874 // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP0]]
875 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8*
876 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]])
877 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]*
John McCallb6a60792013-03-23 02:35:54 +0000878 // CHECK-NEXT: call void (...)* @clang.arc.use([[A_T]]* [[W0]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000879 // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]]
880 // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]]
881 // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8*
882 // CHECK-NEXT: call void @objc_release(i8* [[T5]])
883
884 // CHECK-NEXT: load [[TEST33]]** [[PTR]]
John McCallb6a60792013-03-23 02:35:54 +0000885 // CHECK-NEXT: [[W0:%.*]] = load [[A_T]]** [[A]]
886 // CHECK-NEXT: store [[A_T]]* [[W0]], [[A_T]]** [[TEMP1]]
John McCallf85e1932011-06-15 23:02:42 +0000887 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
888 // CHECK-NEXT: bitcast
889 // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP1]])
890 // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP1]]
891 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8*
892 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]])
893 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]*
John McCallb6a60792013-03-23 02:35:54 +0000894 // CHECK-NEXT: call void (...)* @clang.arc.use([[A_T]]* [[W0]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000895 // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]]
896 // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]]
897 // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8*
898 // CHECK-NEXT: call void @objc_release(i8* [[T5]])
899
900 // CHECK-NEXT: load [[TEST33]]** [[PTR]]
901 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
902 // CHECK-NEXT: bitcast
903 // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[A]])
904
905 // CHECK-NEXT: load [[TEST33]]** [[PTR]]
906 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
907 // CHECK-NEXT: bitcast
908 // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[A]])
909
910 // 'out'
911 // CHECK-NEXT: load [[TEST33]]** [[PTR]]
912 // CHECK-NEXT: store [[A_T]]* null, [[A_T]]** [[TEMP2]]
913 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
914 // CHECK-NEXT: bitcast
915 // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP2]])
916 // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP2]]
917 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8*
918 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]])
919 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]*
920 // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]]
921 // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]]
922 // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8*
923 // CHECK-NEXT: call void @objc_release(i8* [[T5]])
924
925 // CHECK-NEXT: load
926 // CHECK-NEXT: bitcast
927 // CHECK-NEXT: objc_release
928 // CHECK-NEXT: load
929 // CHECK-NEXT: bitcast
930 // CHECK-NEXT: objc_release
931 // CHECK-NEXT: ret void
932}
933
John McCallf85e1932011-06-15 23:02:42 +0000934
John McCallf85e1932011-06-15 23:02:42 +0000935// CHECK: define void @test36
936void test36(id x) {
937 // CHECK: [[X:%.*]] = alloca i8*
938
939 // CHECK: call i8* @objc_retain
940 // CHECK: call i8* @objc_retain
941 // CHECK: call i8* @objc_retain
942 id array[3] = { @"A", x, @"y" };
943
944 // CHECK: [[T0:%.*]] = load i8** [[X]]
945 // CHECK-NEXT: store i8* null, i8** [[X]]
946 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
947 x = 0;
948
949 // CHECK: br label
950 // CHECK: call void @objc_release
John McCallbdc4d802011-07-09 01:37:26 +0000951 // CHECK: br i1
John McCallf85e1932011-06-15 23:02:42 +0000952
953 // CHECK: call void @objc_release
954 // CHECK-NEXT: ret void
955}
956
957@class Test37;
958void test37(void) {
959 extern void test37_helper(id *);
960 Test37 *var;
961 test37_helper(&var);
962
963 // CHECK: define void @test37()
964 // CHECK: [[VAR:%.*]] = alloca [[TEST37:%.*]]*,
965 // CHECK-NEXT: [[TEMP:%.*]] = alloca i8*
966 // CHECK-NEXT: store [[TEST37]]* null, [[TEST37]]** [[VAR]]
967
John McCallb6a60792013-03-23 02:35:54 +0000968 // CHECK-NEXT: [[W0:%.*]] = load [[TEST37]]** [[VAR]]
969 // CHECK-NEXT: [[W1:%.*]] = bitcast [[TEST37]]* [[W0]] to i8*
970 // CHECK-NEXT: store i8* [[W1]], i8** [[TEMP]]
John McCallf85e1932011-06-15 23:02:42 +0000971 // CHECK-NEXT: call void @test37_helper(i8** [[TEMP]])
972 // CHECK-NEXT: [[T0:%.*]] = load i8** [[TEMP]]
973 // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[TEST37]]*
974 // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST37]]* [[T1]] to i8*
975 // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retain(i8* [[T2]])
976 // CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to [[TEST37]]*
John McCallb6a60792013-03-23 02:35:54 +0000977 // CHECK-NEXT: call void (...)* @clang.arc.use(i8* [[W1]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000978 // CHECK-NEXT: [[T5:%.*]] = load [[TEST37]]** [[VAR]]
979 // CHECK-NEXT: store [[TEST37]]* [[T4]], [[TEST37]]** [[VAR]]
980 // CHECK-NEXT: [[T6:%.*]] = bitcast [[TEST37]]* [[T5]] to i8*
981 // CHECK-NEXT: call void @objc_release(i8* [[T6]])
982
983 // CHECK-NEXT: [[T0:%.*]] = load [[TEST37]]** [[VAR]]
984 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST37]]* [[T0]] to i8*
985 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
986 // CHECK-NEXT: ret void
987}
988
John McCallf85e1932011-06-15 23:02:42 +0000989@interface Test43 @end
990@implementation Test43
991- (id) test __attribute__((ns_returns_retained)) {
992 extern id test43_produce(void);
993 return test43_produce();
994 // CHECK: call i8* @test43_produce()
995 // CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue(
996 // CHECK-NEXT: ret
997}
998@end
999
John McCallf85e1932011-06-15 23:02:42 +00001000@interface Test45
1001@property (retain) id x;
1002@end
1003@implementation Test45
1004@synthesize x;
1005@end
1006// CHECK: define internal i8* @"\01-[Test45 x]"(
1007// CHECK: [[CALL:%.*]] = call i8* @objc_getProperty(
1008// CHECK-NEXT: ret i8* [[CALL]]
1009
1010// rdar://problem/9315552
1011void test46(__weak id *wp, __weak volatile id *wvp) {
1012 extern id test46_helper(void);
1013
1014 // TODO: this is sub-optimal, we should retain at the actual call site.
1015
1016 // CHECK: [[T0:%.*]] = call i8* @test46_helper()
John McCall7e5e5f42011-07-07 06:58:02 +00001017 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1018 // CHECK-NEXT: [[T2:%.*]] = load i8*** {{%.*}}, align 8
1019 // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]])
1020 // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retain(i8* [[T3]])
1021 // CHECK-NEXT: store i8* [[T4]], i8**
1022 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +00001023 id x = *wp = test46_helper();
1024
1025 // CHECK: [[T0:%.*]] = call i8* @test46_helper()
John McCall7e5e5f42011-07-07 06:58:02 +00001026 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1027 // CHECK-NEXT: [[T2:%.*]] = load i8*** {{%.*}}, align 8
1028 // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]])
1029 // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retain(i8* [[T3]])
1030 // CHECK-NEXT: store i8* [[T4]], i8**
1031 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +00001032 id y = *wvp = test46_helper();
1033}
1034
1035// rdar://problem/9378887
1036void test47(void) {
1037 extern id test47_helper(void);
1038 id x = x = test47_helper();
1039
1040 // CHECK: define void @test47()
1041 // CHECK: [[X:%.*]] = alloca i8*
1042 // CHECK-NEXT: store i8* null, i8** [[X]]
1043 // CHECK-NEXT: [[CALL:%.*]] = call i8* @test47_helper()
1044 // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]])
1045 // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]]
1046 // CHECK-NEXT: store i8* [[T0]], i8** [[X]]
1047 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
1048 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T0]])
1049 // CHECK-NEXT: [[T3:%.*]] = load i8** [[X]]
1050 // CHECK-NEXT: store i8* [[T2]], i8** [[X]]
1051 // CHECK-NEXT: call void @objc_release(i8* [[T3]])
1052 // CHECK-NEXT: [[T4:%.*]] = load i8** [[X]]
1053 // CHECK-NEXT: call void @objc_release(i8* [[T4]])
1054 // CHECK-NEXT: ret void
1055}
1056
1057void test48(void) {
1058 extern id test48_helper(void);
1059 __weak id x = x = test48_helper();
1060 // CHECK: define void @test48()
1061 // CHECK: [[X:%.*]] = alloca i8*
1062 // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_initWeak(i8** [[X]], i8* null)
1063 // CHECK-NEXT: [[T1:%.*]] = call i8* @test48_helper()
John McCall7e5e5f42011-07-07 06:58:02 +00001064 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +00001065 // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[X]], i8* [[T2]])
John McCall7e5e5f42011-07-07 06:58:02 +00001066 // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_storeWeak(i8** [[X]], i8* [[T3]])
1067 // CHECK-NEXT: call void @objc_release(i8* [[T2]])
John McCallf85e1932011-06-15 23:02:42 +00001068 // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]])
1069 // CHECK-NEXT: ret void
1070}
1071
1072void test49(void) {
1073 extern id test49_helper(void);
1074 __autoreleasing id x = x = test49_helper();
1075 // CHECK: define void @test49()
1076 // CHECK: [[X:%.*]] = alloca i8*
1077 // CHECK-NEXT: store i8* null, i8** [[X]]
1078 // CHECK-NEXT: [[CALL:%.*]] = call i8* @test49_helper()
1079 // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]])
1080 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_autorelease(i8* [[T0]])
1081 // CHECK-NEXT: store i8* [[T2]], i8** [[X]]
1082 // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retainAutorelease(i8* [[T1]])
1083 // CHECK-NEXT: store i8* [[T3]], i8** [[X]]
1084 // CHECK-NEXT: ret void
1085}
1086
1087// rdar://9380136
1088id x();
1089void test50(id y) {
1090 ({x();});
1091// CHECK: [[T0:%.*]] = call i8* @objc_retain
1092// CHECK: call void @objc_release
1093}
1094
1095
1096// rdar://9400762
1097struct CGPoint {
1098 float x;
1099 float y;
1100};
1101typedef struct CGPoint CGPoint;
1102
1103@interface Foo
1104@property (assign) CGPoint point;
1105@end
1106
1107@implementation Foo
1108@synthesize point;
1109@end
1110
1111// rdar://problem/9400398
1112id test52(void) {
1113 id test52_helper(int) __attribute__((ns_returns_retained));
1114 return ({ int x = 5; test52_helper(x); });
1115
1116// CHECK: define i8* @test52()
1117// CHECK: [[X:%.*]] = alloca i32
Eli Friedman2ac2fa72013-06-10 22:04:49 +00001118// CHECK-NEXT: [[TMPALLOCA:%.*]] = alloca i8*
John McCallf85e1932011-06-15 23:02:42 +00001119// CHECK-NEXT: store i32 5, i32* [[X]],
1120// CHECK-NEXT: [[T0:%.*]] = load i32* [[X]],
1121// CHECK-NEXT: [[T1:%.*]] = call i8* @test52_helper(i32 [[T0]])
Eli Friedman2ac2fa72013-06-10 22:04:49 +00001122// CHECK-NEXT: store i8* [[T1]], i8** [[TMPALLOCA]]
1123// CHECK-NEXT: [[T2:%.*]] = load i8** [[TMPALLOCA]]
1124// CHECK-NEXT: [[T3:%.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* [[T2]])
1125// CHECK-NEXT: ret i8* [[T3]]
John McCallf85e1932011-06-15 23:02:42 +00001126}
1127
1128// rdar://problem/9400644
1129void test53(void) {
1130 id test53_helper(void);
1131 id x = ({ id y = test53_helper(); y; });
1132 (void) x;
1133// CHECK: define void @test53()
1134// CHECK: [[X:%.*]] = alloca i8*,
1135// CHECK-NEXT: [[Y:%.*]] = alloca i8*,
Eli Friedman2ac2fa72013-06-10 22:04:49 +00001136// CHECK-NEXT: [[TMPALLOCA:%.*]] = alloca i8*,
John McCallf85e1932011-06-15 23:02:42 +00001137// CHECK-NEXT: [[T0:%.*]] = call i8* @test53_helper()
1138// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1139// CHECK-NEXT: store i8* [[T1]], i8** [[Y]],
1140// CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]],
1141// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]])
Eli Friedman2ac2fa72013-06-10 22:04:49 +00001142// CHECK-NEXT: store i8* [[T1]], i8** [[TMPALLOCA]]
John McCallf85e1932011-06-15 23:02:42 +00001143// CHECK-NEXT: [[T2:%.*]] = load i8** [[Y]]
1144// CHECK-NEXT: call void @objc_release(i8* [[T2]])
Eli Friedman2ac2fa72013-06-10 22:04:49 +00001145// CHECK-NEXT: [[T3:%.*]] = load i8** [[TMPALLOCA]]
1146// CHECK-NEXT: store i8* [[T3]], i8** [[X]],
John McCallf85e1932011-06-15 23:02:42 +00001147// CHECK-NEXT: load i8** [[X]],
1148// CHECK-NEXT: [[T0:%.*]] = load i8** [[X]]
1149// CHECK-NEXT: call void @objc_release(i8* [[T0]])
1150// CHECK-NEXT: ret void
1151}
Douglas Gregorf96e9042011-07-12 17:28:52 +00001152
1153// <rdar://problem/9758798>
1154// CHECK: define void @test54(i32 %first, ...)
1155void test54(int first, ...) {
1156 __builtin_va_list arglist;
1157 // CHECK: call void @llvm.va_start
1158 __builtin_va_start(arglist, first);
1159 // CHECK: call i8* @objc_retain
1160 id obj = __builtin_va_arg(arglist, id);
1161 // CHECK: call void @llvm.va_end
1162 __builtin_va_end(arglist);
1163 // CHECK: call void @objc_release
1164 // CHECK: ret void
1165}
John McCall799d34e2011-07-13 18:26:47 +00001166
1167// PR10228
1168@interface Test55Base @end
1169@interface Test55 : Test55Base @end
1170@implementation Test55 (Category)
1171- (void) dealloc {}
1172@end
1173// CHECK: define internal void @"\01-[Test55(Category) dealloc]"(
1174// CHECK-NOT: ret
1175// CHECK: call void bitcast (i8* ({{%.*}}*, i8*, ...)* @objc_msgSendSuper2 to void ({{%.*}}*, i8*)*)(
John McCall6c2c2502011-07-22 02:45:48 +00001176
1177// rdar://problem/8024350
1178@protocol Test56Protocol
1179+ (id) make __attribute__((ns_returns_retained));
1180@end
1181@interface Test56<Test56Protocol> @end
1182@implementation Test56
1183// CHECK: define internal i8* @"\01+[Test56 make]"(
1184+ (id) make {
1185 extern id test56_helper(void);
1186 // CHECK: [[T0:%.*]] = call i8* @test56_helper()
1187 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1188 // CHECK-NEXT: ret i8* [[T1]]
1189 return test56_helper();
1190}
1191@end
1192void test56_test(void) {
1193 id x = [Test56 make];
1194 // CHECK: define void @test56_test()
1195 // CHECK: [[X:%.*]] = alloca i8*, align 8
1196 // CHECK: [[T0:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*)*)(
1197 // CHECK-NEXT: store i8* [[T0]], i8** [[X]]
1198 // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]]
1199 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
1200 // CHECK-NEXT: ret void
1201}
John McCallba3dd902011-07-22 05:23:13 +00001202
1203// rdar://problem/9784964
1204@interface Test57
1205@property (nonatomic, strong) id strong;
1206@property (nonatomic, weak) id weak;
1207@property (nonatomic, unsafe_unretained) id unsafe;
1208@end
1209@implementation Test57
1210@synthesize strong, weak, unsafe;
1211@end
1212// CHECK: define internal i8* @"\01-[Test57 strong]"(
1213// CHECK: [[T0:%.*]] = load [[TEST57:%.*]]** {{%.*}}
1214// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_Test57.strong"
1215// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST57]]* [[T0]] to i8*
1216// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]]
1217// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8**
1218// CHECK-NEXT: [[T5:%.*]] = load i8** [[T4]]
1219// CHECK-NEXT: ret i8* [[T5]]
1220
1221// CHECK: define internal i8* @"\01-[Test57 weak]"(
1222// CHECK: [[T0:%.*]] = load [[TEST57]]** {{%.*}}
1223// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_Test57.weak"
1224// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST57]]* [[T0]] to i8*
1225// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]]
1226// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8**
1227// CHECK-NEXT: [[T5:%.*]] = call i8* @objc_loadWeakRetained(i8** [[T4]])
Chad Rosierdf76f1e2012-12-12 17:52:21 +00001228// CHECK-NEXT: [[T6:%.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* [[T5]])
John McCallba3dd902011-07-22 05:23:13 +00001229// CHECK-NEXT: ret i8* [[T6]]
1230
1231// CHECK: define internal i8* @"\01-[Test57 unsafe]"(
1232// CHECK: [[T0:%.*]] = load [[TEST57]]** {{%.*}}
1233// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_Test57.unsafe"
1234// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST57]]* [[T0]] to i8*
1235// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]]
1236// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8**
1237// CHECK-NEXT: [[T5:%.*]] = load i8** [[T4]]
1238// CHECK-NEXT: ret i8* [[T5]]
1239
John McCall07524032011-07-27 21:50:02 +00001240// rdar://problem/9842343
1241void test59(void) {
1242 extern id test59_getlock(void);
1243 extern void test59_body(void);
1244 @synchronized (test59_getlock()) {
1245 test59_body();
1246 }
1247
1248 // CHECK: define void @test59()
1249 // CHECK: [[T0:%.*]] = call i8* @test59_getlock()
1250 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
Aaron Ballman2d234d732012-09-06 16:44:16 +00001251 // CHECK-NEXT: call i32 @objc_sync_enter(i8* [[T1]])
John McCall07524032011-07-27 21:50:02 +00001252 // CHECK-NEXT: call void @test59_body()
Aaron Ballman2d234d732012-09-06 16:44:16 +00001253 // CHECK-NEXT: call i32 @objc_sync_exit(i8* [[T1]])
John McCall07524032011-07-27 21:50:02 +00001254 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
1255 // CHECK-NEXT: ret void
1256}
John McCallfb720812011-07-28 07:23:35 +00001257
John McCallfc4b1912011-08-03 07:02:44 +00001258// Verify that we don't try to reclaim the result of performSelector.
1259// rdar://problem/9887545
1260@interface Test61
1261- (id) performSelector: (SEL) selector;
1262- (void) test61_void;
1263- (id) test61_id;
1264@end
1265void test61(void) {
1266 // CHECK: define void @test61()
1267 // CHECK: [[Y:%.*]] = alloca i8*, align 8
1268
1269 extern id test61_make(void);
1270
1271 // CHECK-NEXT: [[T0:%.*]] = call i8* @test61_make()
1272 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1273 // CHECK-NEXT: [[T2:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
1274 // CHECK-NEXT: [[T3:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
1275 // CHECK-NEXT: [[T4:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T1]], i8* [[T3]], i8* [[T2]])
1276 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
1277 [test61_make() performSelector: @selector(test61_void)];
1278
1279 // CHECK-NEXT: [[T0:%.*]] = call i8* @test61_make()
1280 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1281 // CHECK-NEXT: [[T2:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
1282 // CHECK-NEXT: [[T3:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
1283 // CHECK-NEXT: [[T4:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T1]], i8* [[T3]], i8* [[T2]])
1284 // CHECK-NEXT: [[T5:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T4]])
1285 // CHECK-NEXT: store i8* [[T5]], i8** [[Y]]
1286 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
1287 id y = [test61_make() performSelector: @selector(test61_id)];
1288
1289 // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]]
1290 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
1291 // CHECK-NEXT: ret void
1292}
John McCallbddfd872011-08-03 22:24:24 +00001293
1294// rdar://problem/9891815
1295void test62(void) {
1296 // CHECK: define void @test62()
1297 // CHECK: [[I:%.*]] = alloca i32, align 4
1298 // CHECK-NEXT: [[CLEANUP_VALUE:%.*]] = alloca i8*
1299 // CHECK-NEXT: [[CLEANUP_REQUIRED:%.*]] = alloca i1
1300 extern id test62_make(void);
1301 extern void test62_body(void);
1302
1303 // CHECK-NEXT: store i32 0, i32* [[I]], align 4
1304 // CHECK-NEXT: br label
1305
1306 // CHECK: [[T0:%.*]] = load i32* [[I]], align 4
1307 // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 20
1308 // CHECK-NEXT: br i1 [[T1]],
1309
1310 for (unsigned i = 0; i != 20; ++i) {
1311 // CHECK: [[T0:%.*]] = load i32* [[I]], align 4
1312 // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 0
1313 // CHECK-NEXT: store i1 false, i1* [[CLEANUP_REQUIRED]]
1314 // CHECK-NEXT: br i1 [[T1]],
1315 // CHECK: [[T0:%.*]] = call i8* @test62_make()
1316 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1317 // CHECK-NEXT: store i8* [[T1]], i8** [[CLEANUP_VALUE]]
1318 // CHECK-NEXT: store i1 true, i1* [[CLEANUP_REQUIRED]]
1319 // CHECK-NEXT: [[T2:%.*]] = icmp ne i8* [[T1]], null
1320 // CHECK-NEXT: br label
1321 // CHECK: [[COND:%.*]] = phi i1 [ false, {{%.*}} ], [ [[T2]], {{%.*}} ]
1322 // CHECK-NEXT: [[T0:%.*]] = load i1* [[CLEANUP_REQUIRED]]
1323 // CHECK-NEXT: br i1 [[T0]],
1324 // CHECK: [[T0:%.*]] = load i8** [[CLEANUP_VALUE]]
1325 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
1326 // CHECK-NEXT: br label
1327 // CHECK: br i1 [[COND]]
1328 // CHECK: call void @test62_body()
1329 // CHECK-NEXT: br label
1330 // CHECK: br label
1331 if (i != 0 && test62_make() != 0)
1332 test62_body();
1333 }
1334
1335 // CHECK: [[T0:%.*]] = load i32* [[I]], align 4
1336 // CHECK-NEXT: [[T1:%.*]] = add i32 [[T0]], 1
1337 // CHECK-NEXT: store i32 [[T1]], i32* [[I]]
1338 // CHECK-NEXT: br label
1339
1340 // CHECK: ret void
1341}
Fariborz Jahanianbc03aea2011-08-19 19:28:44 +00001342
1343// rdar://9971982
1344@class NSString;
1345
1346@interface Person {
1347 NSString *name;
1348}
1349@property NSString *address;
1350@end
1351
1352@implementation Person
1353@synthesize address;
1354@end
1355// CHECK: call i8* @objc_getProperty
1356// CHECK: call void @objc_setProperty
1357
John McCallcdda47f2011-10-01 09:56:14 +00001358// Verify that we successfully parse and preserve this attribute in
1359// this position.
1360@interface Test66
1361- (void) consume: (id __attribute__((ns_consumed))) ptr;
1362@end
1363void test66(void) {
1364 extern Test66 *test66_receiver(void);
1365 extern id test66_arg(void);
1366 [test66_receiver() consume: test66_arg()];
1367}
1368// CHECK: define void @test66()
1369// CHECK: [[T0:%.*]] = call [[TEST66:%.*]]* @test66_receiver()
1370// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST66]]* [[T0]] to i8*
1371// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]])
1372// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST66]]*
Fariborz Jahanian4e1524b2012-01-29 20:27:13 +00001373// CHECK-NEXT: [[T4:%.*]] = call i8* @test66_arg()
John McCallcdda47f2011-10-01 09:56:14 +00001374// CHECK-NEXT: [[T5:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T4]])
1375// CHECK-NEXT: [[T6:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES
1376// CHECK-NEXT: [[T7:%.*]] = bitcast [[TEST66]]* [[T3]] to i8*
Fariborz Jahanian3c267e62012-01-30 21:40:37 +00001377// CHECK-NEXT: [[SIX:%.*]] = icmp eq i8* [[T7]], null
1378// CHECK-NEXT: br i1 [[SIX]], label [[NULINIT:%.*]], label [[CALL:%.*]]
1379// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i8*)*)(i8* [[T7]], i8* [[T6]], i8* [[T5]])
1380// CHECK-NEXT: br label [[CONT:%.*]]
Bill Wendling4e1125f2013-02-22 09:10:20 +00001381// CHECK: call void @objc_release(i8* [[T5]]) [[NUW]]
Fariborz Jahanian3c267e62012-01-30 21:40:37 +00001382// CHECK-NEXT: br label [[CONT:%.*]]
1383// CHECK: [[T8:%.*]] = bitcast [[TEST66]]* [[T3]] to i8*
John McCallcdda47f2011-10-01 09:56:14 +00001384// CHECK-NEXT: call void @objc_release(i8* [[T8]])
1385// CHECK-NEXT: ret void
John McCall567c5862011-11-14 19:53:16 +00001386
1387// rdar://problem/9953540
1388Class test67_helper(void);
1389void test67(void) {
1390 Class cl = test67_helper();
1391}
1392// CHECK: define void @test67()
1393// CHECK: [[CL:%.*]] = alloca i8*, align 8
1394// CHECK-NEXT: [[T0:%.*]] = call i8* @test67_helper()
1395// CHECK-NEXT: store i8* [[T0]], i8** [[CL]], align 8
1396// CHECK-NEXT: ret void
1397
1398Class test68_helper(void);
1399void test68(void) {
1400 __strong Class cl = test67_helper();
1401}
1402// CHECK: define void @test68()
1403// CHECK: [[CL:%.*]] = alloca i8*, align 8
1404// CHECK-NEXT: [[T0:%.*]] = call i8* @test67_helper()
1405// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1406// CHECK-NEXT: store i8* [[T1]], i8** [[CL]], align 8
1407// CHECK-NEXT: [[T2:%.*]] = load i8** [[CL]]
1408// CHECK-NEXT: call void @objc_release(i8* [[T2]])
1409// CHECK-NEXT: ret void
John McCall77fe6cd2012-01-29 07:46:59 +00001410
1411// rdar://problem/10564852
1412@interface Test69 @end
1413@implementation Test69
1414- (id) foo { return self; }
1415@end
1416// CHECK: define internal i8* @"\01-[Test69 foo]"(
1417// CHECK: [[SELF:%.*]] = alloca [[TEST69:%.*]]*, align 8
1418// CHECK: [[T0:%.*]] = load [[TEST69]]** [[SELF]], align 8
1419// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST69]]* [[T0]] to i8*
1420// CHECK-NEXT: ret i8* [[T1]]
Eli Friedmanb1e3f322012-02-22 05:38:59 +00001421
1422// rdar://problem/10907547
1423void test70(id i) {
1424 // CHECK: define void @test70
1425 // CHECK: store i8* null, i8**
1426 // CHECK: store i8* null, i8**
1427 // CHECK: [[ID:%.*]] = call i8* @objc_retain(i8*
1428 // CHECK: store i8* [[ID]], i8**
1429 id x[3] = {
1430 [2] = i
1431 };
1432}
Bill Wendlingf7a9da02013-02-20 07:22:19 +00001433
Bill Wendling89924572013-02-27 00:06:04 +00001434// ARC-ALIEN: attributes [[NLB]] = { nonlazybind }
1435// ARC-NATIVE: attributes [[NLB]] = { nonlazybind }
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +00001436// CHECK: attributes [[NUW]] = { nounwind }