blob: 48f012a42be9b6bedc8c18044412f70914284399 [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]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000276 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000277 // CHECK-NOT: imprecise_release
278 // CHECK-NEXT: ret void
279}
280
281id test9_helper(void) __attribute__((ns_returns_retained));
282void test9() {
283 id x __attribute__((objc_precise_lifetime)) = test9_helper();
284 x = 0;
285 // CHECK: [[X:%.*]] = alloca i8*
286 // CHECK-NEXT: [[CALL:%.*]] = call i8* @test9_helper()
287 // CHECK-NEXT: store i8* [[CALL]], i8** [[X]]
288
289 // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]]
290 // CHECK-NEXT: store i8* null, i8** [[X]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000291 // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release
John McCallf85e1932011-06-15 23:02:42 +0000292
293 // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000294 // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000295 // CHECK-NOT: clang.imprecise_release
296
297 // CHECK-NEXT: ret void
298}
299
300@interface Test10
301@property (retain) Test10 *me;
302@end
303void test10() {
304 Test10 *x;
305 id y = x.me.me;
306
307 // CHECK: define void @test10()
308 // CHECK: [[X:%.*]] = alloca [[TEST10:%.*]]*, align
309 // CHECK-NEXT: [[Y:%.*]] = alloca i8*, align
310 // CHECK-NEXT: store [[TEST10]]* null, [[TEST10]]** [[X]]
311 // CHECK-NEXT: load [[TEST10]]** [[X]], align
312 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_{{[0-9]*}}"
313 // CHECK-NEXT: bitcast
John McCall7e5e5f42011-07-07 06:58:02 +0000314 // CHECK-NEXT: [[T0:%.*]] = call [[TEST10]]* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
315 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8*
316 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]])
317 // CHECK-NEXT: [[V:%.*]] = bitcast i8* [[T2]] to [[TEST10]]*
John McCallf85e1932011-06-15 23:02:42 +0000318 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_{{[0-9]*}}"
319 // CHECK-NEXT: bitcast
320 // CHECK-NEXT: [[T0:%.*]] = call [[TEST10]]* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
321 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8*
322 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]])
323 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST10]]*
324 // CHECK-NEXT: [[T4:%.*]] = bitcast [[TEST10]]* [[T3]] to i8*
325 // CHECK-NEXT: store i8* [[T4]], i8** [[Y]]
John McCall7e5e5f42011-07-07 06:58:02 +0000326 // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST10]]* [[V]] to i8*
327 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
John McCallf85e1932011-06-15 23:02:42 +0000328 // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]]
329 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
330 // CHECK-NEXT: [[T0:%.*]] = load [[TEST10]]** [[X]]
331 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8*
332 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
333 // CHECK-NEXT: ret void
334}
335
336void test11(id (*f)(void) __attribute__((ns_returns_retained))) {
337 // CHECK: define void @test11(
338 // CHECK: [[F:%.*]] = alloca i8* ()*, align
339 // CHECK-NEXT: [[X:%.*]] = alloca i8*, align
340 // CHECK-NEXT: store i8* ()* {{%.*}}, i8* ()** [[F]], align
341 // CHECK-NEXT: [[T0:%.*]] = load i8* ()** [[F]], align
342 // CHECK-NEXT: [[T1:%.*]] = call i8* [[T0]]()
343 // CHECK-NEXT: store i8* [[T1]], i8** [[X]], align
344 // CHECK-NEXT: [[T3:%.*]] = load i8** [[X]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000345 // CHECK-NEXT: call void @objc_release(i8* [[T3]]) [[NUW]], !clang.imprecise_release
John McCallf85e1932011-06-15 23:02:42 +0000346 // CHECK-NEXT: ret void
347 id x = f();
348}
349
350void test12(void) {
351 extern id test12_helper(void);
352
353 // CHECK: define void @test12()
354 // CHECK: [[X:%.*]] = alloca i8*, align
355 // CHECK-NEXT: [[Y:%.*]] = alloca i8*, align
356
357 __weak id x = test12_helper();
358 // CHECK-NEXT: [[T0:%.*]] = call i8* @test12_helper()
John McCall7e5e5f42011-07-07 06:58:02 +0000359 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
360 // CHECK-NEXT: call i8* @objc_initWeak(i8** [[X]], i8* [[T1]])
361 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +0000362
363 x = test12_helper();
John McCall7e5e5f42011-07-07 06:58:02 +0000364 // CHECK-NEXT: [[T0:%.*]] = call i8* @test12_helper()
365 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
John McCallf85e1932011-06-15 23:02:42 +0000366 // CHECK-NEXT: call i8* @objc_storeWeak(i8** [[X]], i8* [[T1]])
John McCall7e5e5f42011-07-07 06:58:02 +0000367 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +0000368
369 id y = x;
370 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_loadWeakRetained(i8** [[X]])
371 // CHECK-NEXT: store i8* [[T2]], i8** [[Y]], align
372
373 // CHECK-NEXT: [[T4:%.*]] = load i8** [[Y]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000374 // CHECK-NEXT: call void @objc_release(i8* [[T4]]) [[NUW]], !clang.imprecise_release
John McCallf85e1932011-06-15 23:02:42 +0000375 // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]])
376 // CHECK-NEXT: ret void
377}
378
379// Indirect consuming calls.
380void test13(void) {
381 // CHECK: define void @test13()
382 // CHECK: [[X:%.*]] = alloca i8*, align
383 // CHECK-NEXT: store i8* null, i8** [[X]], align
384 id x;
385
386 typedef void fnty(id __attribute__((ns_consumed)));
387 extern fnty *test13_func;
388 // CHECK-NEXT: [[FN:%.*]] = load void (i8*)** @test13_func, align
389 // CHECK-NEXT: [[X_VAL:%.*]] = load i8** [[X]], align
Bill Wendling4e1125f2013-02-22 09:10:20 +0000390 // CHECK-NEXT: [[X_TMP:%.*]] = call i8* @objc_retain(i8* [[X_VAL]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000391 // CHECK-NEXT: call void [[FN]](i8* [[X_TMP]])
392 test13_func(x);
393
394 extern fnty ^test13_block;
395 // CHECK-NEXT: [[TMP:%.*]] = load void (i8*)** @test13_block, align
396 // CHECK-NEXT: [[BLOCK:%.*]] = bitcast void (i8*)* [[TMP]] to [[BLOCKTY:%.*]]*
397 // CHECK-NEXT: [[BLOCK_FN_PTR:%.*]] = getelementptr inbounds [[BLOCKTY]]* [[BLOCK]], i32 0, i32 3
398 // CHECK-NEXT: [[BLOCK_OPAQUE:%.*]] = bitcast [[BLOCKTY]]* [[BLOCK]] to i8*
399 // CHECK-NEXT: [[X_VAL:%.*]] = load i8** [[X]], align
Bill Wendling4e1125f2013-02-22 09:10:20 +0000400 // CHECK-NEXT: [[X_TMP:%.*]] = call i8* @objc_retain(i8* [[X_VAL]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000401 // CHECK-NEXT: [[BLOCK_FN_TMP:%.*]] = load i8** [[BLOCK_FN_PTR]]
402 // CHECK-NEXT: [[BLOCK_FN:%.*]] = bitcast i8* [[BLOCK_FN_TMP]] to void (i8*, i8*)*
403 // CHECK-NEXT: call void [[BLOCK_FN]](i8* [[BLOCK_OPAQUE]], i8* [[X_TMP]])
404 test13_block(x);
405
406 // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000407 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000408 // CHECK-NEXT: ret void
409}
410
411@interface Test16_super @end
412@interface Test16 : Test16_super {
413 id z;
414}
415@property (assign) int x;
416@property (retain) id y;
417- (void) dealloc;
418@end
419@implementation Test16
420@synthesize x;
421@synthesize y;
422- (void) dealloc {
423 // CHECK: define internal void @"\01-[Test16 dealloc]"(
424 // CHECK: [[SELF:%.*]] = alloca [[TEST16:%.*]]*, align
425 // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align
426 // CHECK-NEXT: alloca
427 // CHECK-NEXT: store [[TEST16]]* {{%.*}}, [[TEST16]]** [[SELF]], align
428 // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]]
429 // CHECK-NEXT: [[BASE:%.*]] = load [[TEST16]]** [[SELF]]
430
431 // Call super.
432 // CHECK-NEXT: [[BASE2:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8*
433 // CHECK-NEXT: [[T0:%.*]] = getelementptr
434 // CHECK-NEXT: store i8* [[BASE2]], i8** [[T0]]
435 // CHECK-NEXT: load {{%.*}}** @"\01L_OBJC_CLASSLIST_SUP_REFS_$_
436 // CHECK-NEXT: bitcast
437 // CHECK-NEXT: getelementptr
438 // CHECK-NEXT: store
439 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
440 // CHECK-NEXT: call void bitcast (i8* ({{.*}})* @objc_msgSendSuper2 to void (
441 // CHECK-NEXT: ret void
442}
443
444// .cxx_destruct
445 // CHECK: define internal void @"\01-[Test16 .cxx_destruct]"(
446 // CHECK: [[SELF:%.*]] = alloca [[TEST16:%.*]]*, align
447 // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align
448 // CHECK-NEXT: store [[TEST16]]* {{%.*}}, [[TEST16]]** [[SELF]], align
449 // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]]
450 // CHECK-NEXT: [[BASE:%.*]] = load [[TEST16]]** [[SELF]]
451
452 // Destroy y.
453 // CHECK-NEXT: [[Y_OFF:%.*]] = load i64* @"OBJC_IVAR_$_Test16.y"
454 // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8*
455 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[Y_OFF]]
456 // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8**
Bill Wendling4e1125f2013-02-22 09:10:20 +0000457 // CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000458
459 // Destroy z.
460 // CHECK-NEXT: [[Z_OFF:%.*]] = load i64* @"OBJC_IVAR_$_Test16.z"
461 // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8*
462 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[Z_OFF]]
463 // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8**
Bill Wendling4e1125f2013-02-22 09:10:20 +0000464 // CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000465
466 // CHECK-NEXT: ret void
467
468@end
469
470// This shouldn't crash.
471@interface Test17A
472@property (assign) int x;
473@end
474@interface Test17B : Test17A
475@end
476@implementation Test17B
477- (int) x { return super.x + 1; }
478@end
479
John McCallf85e1932011-06-15 23:02:42 +0000480void test19() {
481 // CHECK: define void @test19()
482 // CHECK: [[X:%.*]] = alloca [5 x i8*], align 16
483 // CHECK-NEXT: [[T0:%.*]] = bitcast [5 x i8*]* [[X]] to i8*
484 // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 40, i32 16, i1 false)
485 id x[5];
486
487 extern id test19_helper(void);
488 x[2] = test19_helper();
489
490 // CHECK-NEXT: [[CALL:%.*]] = call i8* @test19_helper()
Bill Wendling4e1125f2013-02-22 09:10:20 +0000491 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000492 // CHECK-NEXT: [[SLOT:%.*]] = getelementptr inbounds [5 x i8*]* [[X]], i32 0, i64 2
493 // CHECK-NEXT: [[T0:%.*]] = load i8** [[SLOT]]
494 // CHECK-NEXT: store i8* [[T1]], i8** [[SLOT]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000495 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000496
497 // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [5 x i8*]* [[X]], i32 0, i32 0
498 // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 5
499 // CHECK-NEXT: br label
500
John McCallbdc4d802011-07-09 01:37:26 +0000501 // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ]
502 // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1
503 // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000504 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release
John McCallbdc4d802011-07-09 01:37:26 +0000505 // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]]
506 // CHECK-NEXT: br i1 [[EQ]],
John McCallf85e1932011-06-15 23:02:42 +0000507
508 // CHECK: ret void
509}
510
511void test20(unsigned n) {
512 // CHECK: define void @test20
513 // CHECK: [[N:%.*]] = alloca i32, align 4
514 // CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca i8*
515 // CHECK-NEXT: store i32 {{%.*}}, i32* [[N]], align 4
516
517 id x[n];
518
519 // Capture the VLA size.
John McCallbc8d40d2011-06-24 21:55:10 +0000520 // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4
521 // CHECK-NEXT: [[DIM:%.*]] = zext i32 [[T0]] to i64
522
523 // Save the stack pointer.
John McCallf85e1932011-06-15 23:02:42 +0000524 // CHECK-NEXT: [[T0:%.*]] = call i8* @llvm.stacksave()
525 // CHECK-NEXT: store i8* [[T0]], i8** [[SAVED_STACK]]
John McCallf85e1932011-06-15 23:02:42 +0000526
527 // Allocate the VLA.
John McCallbc8d40d2011-06-24 21:55:10 +0000528 // CHECK-NEXT: [[VLA:%.*]] = alloca i8*, i64 [[DIM]], align 16
John McCallf85e1932011-06-15 23:02:42 +0000529
530 // Zero-initialize.
531 // CHECK-NEXT: [[T0:%.*]] = bitcast i8** [[VLA]] to i8*
John McCallbc8d40d2011-06-24 21:55:10 +0000532 // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 [[DIM]], 8
533 // 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 +0000534
535 // Destroy.
John McCallbc8d40d2011-06-24 21:55:10 +0000536 // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[VLA]], i64 [[DIM]]
John McCallfbf780a2011-07-13 08:09:46 +0000537 // CHECK-NEXT: [[EMPTY:%.*]] = icmp eq i8** [[VLA]], [[END]]
538 // CHECK-NEXT: br i1 [[EMPTY]]
John McCallf85e1932011-06-15 23:02:42 +0000539
John McCallbdc4d802011-07-09 01:37:26 +0000540 // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ]
541 // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1
542 // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000543 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release
John McCallbdc4d802011-07-09 01:37:26 +0000544 // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[VLA]]
545 // CHECK-NEXT: br i1 [[EQ]],
John McCallf85e1932011-06-15 23:02:42 +0000546
547 // CHECK: [[T0:%.*]] = load i8** [[SAVED_STACK]]
548 // CHECK-NEXT: call void @llvm.stackrestore(i8* [[T0]])
549 // CHECK-NEXT: ret void
550}
551
552void test21(unsigned n) {
553 // CHECK: define void @test21
554 // CHECK: [[N:%.*]] = alloca i32, align 4
555 // CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca i8*
556 // CHECK-NEXT: store i32 {{%.*}}, i32* [[N]], align 4
557
558 id x[2][n][3];
559
560 // Capture the VLA size.
John McCallbc8d40d2011-06-24 21:55:10 +0000561 // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4
562 // CHECK-NEXT: [[DIM:%.*]] = zext i32 [[T0]] to i64
563
John McCallf85e1932011-06-15 23:02:42 +0000564 // CHECK-NEXT: [[T0:%.*]] = call i8* @llvm.stacksave()
565 // CHECK-NEXT: store i8* [[T0]], i8** [[SAVED_STACK]]
John McCallbc8d40d2011-06-24 21:55:10 +0000566
John McCallf85e1932011-06-15 23:02:42 +0000567
568 // Allocate the VLA.
John McCallbc8d40d2011-06-24 21:55:10 +0000569 // CHECK-NEXT: [[T0:%.*]] = mul nuw i64 2, [[DIM]]
570 // CHECK-NEXT: [[VLA:%.*]] = alloca [3 x i8*], i64 [[T0]], align 16
John McCallf85e1932011-06-15 23:02:42 +0000571
572 // Zero-initialize.
573 // CHECK-NEXT: [[T0:%.*]] = bitcast [3 x i8*]* [[VLA]] to i8*
John McCallbc8d40d2011-06-24 21:55:10 +0000574 // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 2, [[DIM]]
575 // CHECK-NEXT: [[T2:%.*]] = mul nuw i64 [[T1]], 24
576 // 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 +0000577
578 // Destroy.
John McCallbc8d40d2011-06-24 21:55:10 +0000579 // CHECK-NEXT: [[T0:%.*]] = mul nuw i64 2, [[DIM]]
John McCallf85e1932011-06-15 23:02:42 +0000580 // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [3 x i8*]* [[VLA]], i32 0, i32 0
John McCallbc8d40d2011-06-24 21:55:10 +0000581 // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 [[T0]], 3
582 // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 [[T1]]
John McCallfbf780a2011-07-13 08:09:46 +0000583 // CHECK-NEXT: [[EMPTY:%.*]] = icmp eq i8** [[BEGIN]], [[END]]
584 // CHECK-NEXT: br i1 [[EMPTY]]
John McCallf85e1932011-06-15 23:02:42 +0000585
John McCallbdc4d802011-07-09 01:37:26 +0000586 // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ]
587 // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1
588 // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000589 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release
John McCallbdc4d802011-07-09 01:37:26 +0000590 // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]]
591 // CHECK-NEXT: br i1 [[EQ]],
John McCallf85e1932011-06-15 23:02:42 +0000592
593 // CHECK: [[T0:%.*]] = load i8** [[SAVED_STACK]]
594 // CHECK-NEXT: call void @llvm.stackrestore(i8* [[T0]])
595 // CHECK-NEXT: ret void
596}
597
John McCallf85e1932011-06-15 23:02:42 +0000598// rdar://problem/8922540
599// Note that we no longer emit .release_ivars flags.
John McCallb03527a2012-10-17 04:53:31 +0000600// rdar://problem/12492434
601// Note that we set the flag saying that we need destruction *and*
602// the flag saying that we don't also need construction.
603// CHECK-GLOBALS: @"\01l_OBJC_CLASS_RO_$_Test23" = internal global [[RO_T:%.*]] { i32 390,
John McCallf85e1932011-06-15 23:02:42 +0000604@interface Test23 { id x; } @end
605@implementation Test23 @end
606
607// CHECK-GLOBALS: @"\01l_OBJC_CLASS_RO_$_Test24" = internal global [[RO_T:%.*]] { i32 130,
608@interface Test24 {} @end
609@implementation Test24 @end
610
John McCallf85e1932011-06-15 23:02:42 +0000611// rdar://problem/8941012
612@interface Test26 { id x[4]; } @end
613@implementation Test26 @end
614// CHECK: define internal void @"\01-[Test26 .cxx_destruct]"(
615// CHECK: [[SELF:%.*]] = load [[TEST26:%.*]]**
616// CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test26.x"
617// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST26]]* [[SELF]] to i8*
618// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[OFFSET]]
619// CHECK-NEXT: [[X:%.*]] = bitcast i8* [[T1]] to [4 x i8*]*
620// CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [4 x i8*]* [[X]], i32 0, i32 0
621// CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 4
622// CHECK-NEXT: br label
John McCall9928c482011-07-12 16:41:08 +0000623// CHECK: [[PAST:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ]
624// CHECK-NEXT: [[CUR]] = getelementptr inbounds i8** [[PAST]], i64 -1
625// CHECK-NEXT: call void @objc_storeStrong(i8** [[CUR]], i8* null)
626// CHECK-NEXT: [[ISDONE:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]]
John McCallf85e1932011-06-15 23:02:42 +0000627// CHECK-NEXT: br i1 [[ISDONE]],
John McCallf85e1932011-06-15 23:02:42 +0000628// CHECK: ret void
629
630// Check that 'init' retains self.
631@interface Test27
632- (id) init;
633@end
634@implementation Test27
635- (id) init { return self; }
636// CHECK: define internal i8* @"\01-[Test27 init]"
John McCallf48f7962012-01-29 02:35:02 +0000637// CHECK: [[SELF:%.*]] = alloca [[TEST27:%.*]]*,
John McCallf85e1932011-06-15 23:02:42 +0000638// CHECK-NEXT: [[CMD:%.*]] = alloca i8*,
639// CHECK-NEXT: [[DEST:%.*]] = alloca i32
640// CHECK-NEXT: store [[TEST27]]* {{%.*}}, [[TEST27]]** [[SELF]]
641// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]]
642// CHECK-NEXT: [[T0:%.*]] = load [[TEST27]]** [[SELF]]
643// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST27]]* [[T0]] to i8*
Eli Friedman38ac2432012-03-30 01:13:43 +0000644// CHECK-NEXT: [[RET:%.*]] = call i8* @objc_retain(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +0000645// CHECK-NEXT: store i32 {{[0-9]+}}, i32* [[DEST]]
646// CHECK-NEXT: [[T0:%.*]] = load [[TEST27]]** [[SELF]]
647// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST27]]* [[T0]] to i8*
648// CHECK-NEXT: call void @objc_release(i8* [[T1]])
John McCallf48f7962012-01-29 02:35:02 +0000649// CHECK-NEXT: ret i8* [[RET]]
John McCallf85e1932011-06-15 23:02:42 +0000650
651@end
652
653// rdar://problem/8087194
654@interface Test28
655@property (copy) id prop;
656@end
657@implementation Test28
658@synthesize prop;
659@end
660// CHECK: define internal void @"\01-[Test28 .cxx_destruct]"
661// CHECK: [[SELF:%.*]] = load [[TEST28:%.*]]**
662// CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test28.prop"
663// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST28]]* [[SELF]] to i8*
664// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[OFFSET]]
665// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8**
666// CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null)
667// CHECK-NEXT: ret void
668
669@interface Test29_super
670- (id) initWithAllocator: (id) allocator;
671@end
672@interface Test29 : Test29_super
673- (id) init;
674- (id) initWithAllocator: (id) allocator;
675@end
676@implementation Test29
677static id _test29_allocator = 0;
678- (id) init {
Bill Wendlingc0dcc2d2013-02-15 21:30:01 +0000679// CHECK: define internal i8* @"\01-[Test29 init]"([[TEST29:%[^*]*]]* {{%.*}},
John McCallf48f7962012-01-29 02:35:02 +0000680// CHECK: [[SELF:%.*]] = alloca [[TEST29]]*, align 8
John McCallf85e1932011-06-15 23:02:42 +0000681// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align 8
682// CHECK-NEXT: [[CLEANUP:%.*]] = alloca i32
683// CHECK-NEXT: store [[TEST29]]* {{%.*}}, [[TEST29]]** [[SELF]]
684// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]]
685
686// Evaluate arguments. Note that the send argument is evaluated
687// before the zeroing of self.
688// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]], align 8
689// CHECK-NEXT: [[T1:%.*]] = load i8** @_test29_allocator, align 8
690
691// Implicit null of 'self', i.e. direct transfer of ownership.
692// CHECK-NEXT: store [[TEST29]]* null, [[TEST29]]** [[SELF]]
693
694// Actual message send.
695// CHECK-NEXT: [[T2:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
696// CHECK-NEXT: [[T3:%.*]] = bitcast [[TEST29]]* [[T0]] to i8*
697// CHECK-NEXT: [[CALL:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T3]], i8* [[T2]], i8* [[T1]])
698
699// Implicit write of result back into 'self'. This is not supposed to
700// be detectable because we're supposed to ban accesses to the old
701// self value past the delegate init call.
702// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]*
703// CHECK-NEXT: store [[TEST29]]* [[T0]], [[TEST29]]** [[SELF]]
704
705// Return statement.
706// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[CALL]]
707// CHECK-NEXT: [[CALL:%.*]] = bitcast
Bill Wendling4e1125f2013-02-22 09:10:20 +0000708// CHECK-NEXT: [[RET:%.*]] = call i8* @objc_retain(i8* [[CALL]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000709// CHECK-NEXT: store i32 1, i32* [[CLEANUP]]
710
711// Cleanup.
712// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]]
713// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8*
Bill Wendling4e1125f2013-02-22 09:10:20 +0000714// CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release
John McCallf85e1932011-06-15 23:02:42 +0000715
716// Return.
John McCallf48f7962012-01-29 02:35:02 +0000717// CHECK-NEXT: ret i8* [[RET]]
John McCallf85e1932011-06-15 23:02:42 +0000718 return [self initWithAllocator: _test29_allocator];
719}
720- (id) initWithAllocator: (id) allocator {
721// CHECK: define internal i8* @"\01-[Test29 initWithAllocator:]"(
John McCallf48f7962012-01-29 02:35:02 +0000722// CHECK: [[SELF:%.*]] = alloca [[TEST29]]*, align 8
John McCallf85e1932011-06-15 23:02:42 +0000723// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align 8
724// CHECK-NEXT: [[ALLOCATOR:%.*]] = alloca i8*, align 8
725// CHECK-NEXT: alloca
726// CHECK-NEXT: [[CLEANUP:%.*]] = alloca i32
727// CHECK-NEXT: store [[TEST29]]* {{%.*}}, [[TEST29]]** [[SELF]]
728// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]]
729// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* {{%.*}})
730// CHECK-NEXT: store i8* [[T0]], i8** [[ALLOCATOR]]
731
732// Evaluate arguments. Note that the send argument is evaluated
733// before the zeroing of self.
734// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]]
735// CHECK-NEXT: [[T1:%.*]] = load i8** [[ALLOCATOR]], align 8
736
737// Implicit null of 'self', i.e. direct transfer of ownership.
738// CHECK-NEXT: store [[TEST29]]* null, [[TEST29]]** [[SELF]]
739
740// Actual message send.
741// CHECK: [[CALL:%.*]] = call {{.*}} @objc_msgSendSuper2
742
743// Implicit write of result back into 'self'. This is not supposed to
744// be detectable because we're supposed to ban accesses to the old
745// self value past the delegate init call.
746// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]*
747// CHECK-NEXT: store [[TEST29]]* [[T0]], [[TEST29]]** [[SELF]]
748
749// Assignment.
750// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]*
751// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8*
Bill Wendling4e1125f2013-02-22 09:10:20 +0000752// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000753// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST29]]*
754// CHECK-NEXT: [[T4:%.*]] = load [[TEST29]]** [[SELF]], align
755// CHECK-NEXT: store [[TEST29]]* [[T3]], [[TEST29]]** [[SELF]], align
756// CHECK-NEXT: [[T5:%.*]] = bitcast [[TEST29]]* [[T4]] to i8*
757// CHECK-NEXT: call void @objc_release(i8* [[T5]])
758
759// Return statement.
760// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]]
761// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8*
Bill Wendling4e1125f2013-02-22 09:10:20 +0000762// CHECK-NEXT: [[RET:%.*]] = call i8* @objc_retain(i8* [[T1]]) [[NUW]]
John McCallf85e1932011-06-15 23:02:42 +0000763// CHECK-NEXT: store i32 1, i32* [[CLEANUP]]
764
765// Cleanup.
766// CHECK-NEXT: [[T0:%.*]] = load i8** [[ALLOCATOR]]
Bill Wendling4e1125f2013-02-22 09:10:20 +0000767// CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release
John McCallf85e1932011-06-15 23:02:42 +0000768
769// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]]
770// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8*
Bill Wendling4e1125f2013-02-22 09:10:20 +0000771// CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release
John McCallf85e1932011-06-15 23:02:42 +0000772
773// Return.
John McCallf48f7962012-01-29 02:35:02 +0000774// CHECK-NEXT: ret i8* [[RET]]
John McCallf85e1932011-06-15 23:02:42 +0000775 self = [super initWithAllocator: allocator];
776 return self;
777}
778@end
779
780typedef struct Test30_helper Test30_helper;
781@interface Test30
782- (id) init;
783- (Test30_helper*) initHelper;
784@end
785@implementation Test30 {
786char *helper;
787}
788- (id) init {
Bill Wendlingc0dcc2d2013-02-15 21:30:01 +0000789// CHECK: define internal i8* @"\01-[Test30 init]"([[TEST30:%[^*]*]]* {{%.*}},
John McCallf48f7962012-01-29 02:35:02 +0000790// CHECK: [[RET:%.*]] = alloca [[TEST30]]*
John McCallf85e1932011-06-15 23:02:42 +0000791// CHECK-NEXT: alloca i8*
792// CHECK-NEXT: alloca i32
793// CHECK-NEXT: store [[TEST30]]* {{%.*}}, [[TEST30]]** [[SELF]]
794// CHECK-NEXT: store
795
796// Call.
797// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]]
798// CHECK-NEXT: [[T1:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
799// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST30]]* [[T0]] to i8*
800// CHECK-NEXT: [[CALL:%.*]] = call [[TEST30_HELPER:%.*]]* bitcast {{.*}} @objc_msgSend {{.*}}(i8* [[T2]], i8* [[T1]])
801
802// Assignment.
803// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST30_HELPER]]* [[CALL]] to i8*
804// CHECK-NEXT: [[T1:%.*]] = load [[TEST30]]** [[SELF]]
805// CHECK-NEXT: [[IVAR:%.*]] = load i64* @"OBJC_IVAR_$_Test30.helper"
806// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST30]]* [[T1]] to i8*
807// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[IVAR]]
808// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8**
809// CHECK-NEXT#: [[T5:%.*]] = load i8** [[T4]]
810// CHECK-NEXT#: [[T6:%.*]] = call i8* @objc_retain(i8* [[T0]])
811// CHECK-NEXT#: call void @objc_release(i8* [[T5]])
812// CHECK-NEXT: store i8* [[T0]], i8** [[T4]]
813
814// Return.
815// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]]
816// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST30]]* [[T0]] to i8*
Eli Friedman38ac2432012-03-30 01:13:43 +0000817// CHECK-NEXT: [[RET:%.*]] = call i8* @objc_retain(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +0000818// CHECK-NEXT: store i32 1
819
820// Cleanup.
821// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]]
822// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST30]]* [[T0]] to i8*
823// CHECK-NEXT: call void @objc_release(i8* [[T1]])
824
825// Epilogue.
John McCallf48f7962012-01-29 02:35:02 +0000826// CHECK-NEXT: ret i8* [[RET]]
John McCallf85e1932011-06-15 23:02:42 +0000827 self->helper = [self initHelper];
828 return self;
829}
830- (Test30_helper*) initHelper {
831// CHECK: define internal [[TEST30_HELPER]]* @"\01-[Test30 initHelper]"(
832// CHECK: alloca
833// CHECK-NEXT: alloca
834// CHECK-NEXT: store
835// CHECK-NEXT: store
836// CHECK-NEXT: ret [[TEST30_HELPER]]* null
837 return 0;
838}
839
840@end
841
John McCallf85e1932011-06-15 23:02:42 +0000842__attribute__((ns_returns_retained)) id test32(void) {
843// CHECK: define i8* @test32()
844// CHECK: [[CALL:%.*]] = call i8* @test32_helper()
845// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]])
846// CHECK-NEXT: ret i8* [[T0]]
847 extern id test32_helper(void);
848 return test32_helper();
849}
850
851@class Test33_a;
852@interface Test33
853- (void) give: (Test33_a **) x;
854- (void) take: (Test33_a **) x;
855- (void) giveStrong: (out __strong Test33_a **) x;
856- (void) takeStrong: (inout __strong Test33_a **) x;
857- (void) giveOut: (out Test33_a **) x;
858@end
859void test33(Test33 *ptr) {
860 Test33_a *a;
861 [ptr give: &a];
862 [ptr take: &a];
863 [ptr giveStrong: &a];
864 [ptr takeStrong: &a];
865 [ptr giveOut: &a];
866
867 // CHECK: define void @test33([[TEST33:%.*]]*
868 // CHECK: [[PTR:%.*]] = alloca [[TEST33]]*
869 // CHECK-NEXT: [[A:%.*]] = alloca [[A_T:%.*]]*
870 // CHECK-NEXT: [[TEMP0:%.*]] = alloca [[A_T]]*
871 // CHECK-NEXT: [[TEMP1:%.*]] = alloca [[A_T]]*
872 // CHECK-NEXT: [[TEMP2:%.*]] = alloca [[A_T]]*
873 // CHECK-NEXT: bitcast
874 // CHECK-NEXT: objc_retain
875 // CHECK-NEXT: bitcast
876 // CHECK-NEXT: store
877 // CHECK-NEXT: store [[A_T]]* null, [[A_T]]** [[A]]
878
879 // CHECK-NEXT: load [[TEST33]]** [[PTR]]
880 // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[A]]
881 // CHECK-NEXT: store [[A_T]]* [[T0]], [[A_T]]** [[TEMP0]]
882 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
883 // CHECK-NEXT: bitcast
884 // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP0]])
885 // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP0]]
886 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8*
887 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]])
888 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]*
889 // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]]
890 // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]]
891 // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8*
892 // CHECK-NEXT: call void @objc_release(i8* [[T5]])
893
894 // CHECK-NEXT: load [[TEST33]]** [[PTR]]
895 // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[A]]
896 // CHECK-NEXT: store [[A_T]]* [[T0]], [[A_T]]** [[TEMP1]]
897 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
898 // CHECK-NEXT: bitcast
899 // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP1]])
900 // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP1]]
901 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8*
902 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]])
903 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]*
904 // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]]
905 // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]]
906 // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8*
907 // CHECK-NEXT: call void @objc_release(i8* [[T5]])
908
909 // CHECK-NEXT: load [[TEST33]]** [[PTR]]
910 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
911 // CHECK-NEXT: bitcast
912 // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[A]])
913
914 // CHECK-NEXT: load [[TEST33]]** [[PTR]]
915 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
916 // CHECK-NEXT: bitcast
917 // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[A]])
918
919 // 'out'
920 // CHECK-NEXT: load [[TEST33]]** [[PTR]]
921 // CHECK-NEXT: store [[A_T]]* null, [[A_T]]** [[TEMP2]]
922 // CHECK-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
923 // CHECK-NEXT: bitcast
924 // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP2]])
925 // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP2]]
926 // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8*
927 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]])
928 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]*
929 // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]]
930 // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]]
931 // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8*
932 // CHECK-NEXT: call void @objc_release(i8* [[T5]])
933
934 // CHECK-NEXT: load
935 // CHECK-NEXT: bitcast
936 // CHECK-NEXT: objc_release
937 // CHECK-NEXT: load
938 // CHECK-NEXT: bitcast
939 // CHECK-NEXT: objc_release
940 // CHECK-NEXT: ret void
941}
942
John McCallf85e1932011-06-15 23:02:42 +0000943
John McCallf85e1932011-06-15 23:02:42 +0000944// CHECK: define void @test36
945void test36(id x) {
946 // CHECK: [[X:%.*]] = alloca i8*
947
948 // CHECK: call i8* @objc_retain
949 // CHECK: call i8* @objc_retain
950 // CHECK: call i8* @objc_retain
951 id array[3] = { @"A", x, @"y" };
952
953 // CHECK: [[T0:%.*]] = load i8** [[X]]
954 // CHECK-NEXT: store i8* null, i8** [[X]]
955 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
956 x = 0;
957
958 // CHECK: br label
959 // CHECK: call void @objc_release
John McCallbdc4d802011-07-09 01:37:26 +0000960 // CHECK: br i1
John McCallf85e1932011-06-15 23:02:42 +0000961
962 // CHECK: call void @objc_release
963 // CHECK-NEXT: ret void
964}
965
966@class Test37;
967void test37(void) {
968 extern void test37_helper(id *);
969 Test37 *var;
970 test37_helper(&var);
971
972 // CHECK: define void @test37()
973 // CHECK: [[VAR:%.*]] = alloca [[TEST37:%.*]]*,
974 // CHECK-NEXT: [[TEMP:%.*]] = alloca i8*
975 // CHECK-NEXT: store [[TEST37]]* null, [[TEST37]]** [[VAR]]
976
977 // CHECK-NEXT: [[T0:%.*]] = load [[TEST37]]** [[VAR]]
978 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST37]]* [[T0]] to i8*
979 // CHECK-NEXT: store i8* [[T1]], i8** [[TEMP]]
980 // CHECK-NEXT: call void @test37_helper(i8** [[TEMP]])
981 // CHECK-NEXT: [[T0:%.*]] = load i8** [[TEMP]]
982 // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[TEST37]]*
983 // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST37]]* [[T1]] to i8*
984 // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retain(i8* [[T2]])
985 // CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to [[TEST37]]*
986 // CHECK-NEXT: [[T5:%.*]] = load [[TEST37]]** [[VAR]]
987 // CHECK-NEXT: store [[TEST37]]* [[T4]], [[TEST37]]** [[VAR]]
988 // CHECK-NEXT: [[T6:%.*]] = bitcast [[TEST37]]* [[T5]] to i8*
989 // CHECK-NEXT: call void @objc_release(i8* [[T6]])
990
991 // CHECK-NEXT: [[T0:%.*]] = load [[TEST37]]** [[VAR]]
992 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST37]]* [[T0]] to i8*
993 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
994 // CHECK-NEXT: ret void
995}
996
John McCallf85e1932011-06-15 23:02:42 +0000997@interface Test43 @end
998@implementation Test43
999- (id) test __attribute__((ns_returns_retained)) {
1000 extern id test43_produce(void);
1001 return test43_produce();
1002 // CHECK: call i8* @test43_produce()
1003 // CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue(
1004 // CHECK-NEXT: ret
1005}
1006@end
1007
John McCallf85e1932011-06-15 23:02:42 +00001008@interface Test45
1009@property (retain) id x;
1010@end
1011@implementation Test45
1012@synthesize x;
1013@end
1014// CHECK: define internal i8* @"\01-[Test45 x]"(
1015// CHECK: [[CALL:%.*]] = call i8* @objc_getProperty(
1016// CHECK-NEXT: ret i8* [[CALL]]
1017
1018// rdar://problem/9315552
1019void test46(__weak id *wp, __weak volatile id *wvp) {
1020 extern id test46_helper(void);
1021
1022 // TODO: this is sub-optimal, we should retain at the actual call site.
1023
1024 // CHECK: [[T0:%.*]] = call i8* @test46_helper()
John McCall7e5e5f42011-07-07 06:58:02 +00001025 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1026 // CHECK-NEXT: [[T2:%.*]] = load i8*** {{%.*}}, align 8
1027 // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]])
1028 // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retain(i8* [[T3]])
1029 // CHECK-NEXT: store i8* [[T4]], i8**
1030 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +00001031 id x = *wp = test46_helper();
1032
1033 // CHECK: [[T0:%.*]] = call i8* @test46_helper()
John McCall7e5e5f42011-07-07 06:58:02 +00001034 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1035 // CHECK-NEXT: [[T2:%.*]] = load i8*** {{%.*}}, align 8
1036 // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]])
1037 // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retain(i8* [[T3]])
1038 // CHECK-NEXT: store i8* [[T4]], i8**
1039 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +00001040 id y = *wvp = test46_helper();
1041}
1042
1043// rdar://problem/9378887
1044void test47(void) {
1045 extern id test47_helper(void);
1046 id x = x = test47_helper();
1047
1048 // CHECK: define void @test47()
1049 // CHECK: [[X:%.*]] = alloca i8*
1050 // CHECK-NEXT: store i8* null, i8** [[X]]
1051 // CHECK-NEXT: [[CALL:%.*]] = call i8* @test47_helper()
1052 // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]])
1053 // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]]
1054 // CHECK-NEXT: store i8* [[T0]], i8** [[X]]
1055 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
1056 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T0]])
1057 // CHECK-NEXT: [[T3:%.*]] = load i8** [[X]]
1058 // CHECK-NEXT: store i8* [[T2]], i8** [[X]]
1059 // CHECK-NEXT: call void @objc_release(i8* [[T3]])
1060 // CHECK-NEXT: [[T4:%.*]] = load i8** [[X]]
1061 // CHECK-NEXT: call void @objc_release(i8* [[T4]])
1062 // CHECK-NEXT: ret void
1063}
1064
1065void test48(void) {
1066 extern id test48_helper(void);
1067 __weak id x = x = test48_helper();
1068 // CHECK: define void @test48()
1069 // CHECK: [[X:%.*]] = alloca i8*
1070 // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_initWeak(i8** [[X]], i8* null)
1071 // CHECK-NEXT: [[T1:%.*]] = call i8* @test48_helper()
John McCall7e5e5f42011-07-07 06:58:02 +00001072 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +00001073 // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[X]], i8* [[T2]])
John McCall7e5e5f42011-07-07 06:58:02 +00001074 // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_storeWeak(i8** [[X]], i8* [[T3]])
1075 // CHECK-NEXT: call void @objc_release(i8* [[T2]])
John McCallf85e1932011-06-15 23:02:42 +00001076 // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]])
1077 // CHECK-NEXT: ret void
1078}
1079
1080void test49(void) {
1081 extern id test49_helper(void);
1082 __autoreleasing id x = x = test49_helper();
1083 // CHECK: define void @test49()
1084 // CHECK: [[X:%.*]] = alloca i8*
1085 // CHECK-NEXT: store i8* null, i8** [[X]]
1086 // CHECK-NEXT: [[CALL:%.*]] = call i8* @test49_helper()
1087 // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]])
1088 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_autorelease(i8* [[T0]])
1089 // CHECK-NEXT: store i8* [[T2]], i8** [[X]]
1090 // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retainAutorelease(i8* [[T1]])
1091 // CHECK-NEXT: store i8* [[T3]], i8** [[X]]
1092 // CHECK-NEXT: ret void
1093}
1094
1095// rdar://9380136
1096id x();
1097void test50(id y) {
1098 ({x();});
1099// CHECK: [[T0:%.*]] = call i8* @objc_retain
1100// CHECK: call void @objc_release
1101}
1102
1103
1104// rdar://9400762
1105struct CGPoint {
1106 float x;
1107 float y;
1108};
1109typedef struct CGPoint CGPoint;
1110
1111@interface Foo
1112@property (assign) CGPoint point;
1113@end
1114
1115@implementation Foo
1116@synthesize point;
1117@end
1118
1119// rdar://problem/9400398
1120id test52(void) {
1121 id test52_helper(int) __attribute__((ns_returns_retained));
1122 return ({ int x = 5; test52_helper(x); });
1123
1124// CHECK: define i8* @test52()
1125// CHECK: [[X:%.*]] = alloca i32
1126// CHECK-NEXT: store i32 5, i32* [[X]],
1127// CHECK-NEXT: [[T0:%.*]] = load i32* [[X]],
1128// CHECK-NEXT: [[T1:%.*]] = call i8* @test52_helper(i32 [[T0]])
Chad Rosierdf76f1e2012-12-12 17:52:21 +00001129// CHECK-NEXT: [[T2:%.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* [[T1]])
John McCallf85e1932011-06-15 23:02:42 +00001130// CHECK-NEXT: ret i8* [[T2]]
1131}
1132
1133// rdar://problem/9400644
1134void test53(void) {
1135 id test53_helper(void);
1136 id x = ({ id y = test53_helper(); y; });
1137 (void) x;
1138// CHECK: define void @test53()
1139// CHECK: [[X:%.*]] = alloca i8*,
1140// CHECK-NEXT: [[Y:%.*]] = alloca i8*,
1141// CHECK-NEXT: [[T0:%.*]] = call i8* @test53_helper()
1142// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1143// CHECK-NEXT: store i8* [[T1]], i8** [[Y]],
1144// CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]],
1145// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]])
1146// CHECK-NEXT: [[T2:%.*]] = load i8** [[Y]]
1147// CHECK-NEXT: call void @objc_release(i8* [[T2]])
1148// CHECK-NEXT: store i8* [[T1]], i8** [[X]],
1149// CHECK-NEXT: load i8** [[X]],
1150// CHECK-NEXT: [[T0:%.*]] = load i8** [[X]]
1151// CHECK-NEXT: call void @objc_release(i8* [[T0]])
1152// CHECK-NEXT: ret void
1153}
Douglas Gregorf96e9042011-07-12 17:28:52 +00001154
1155// <rdar://problem/9758798>
1156// CHECK: define void @test54(i32 %first, ...)
1157void test54(int first, ...) {
1158 __builtin_va_list arglist;
1159 // CHECK: call void @llvm.va_start
1160 __builtin_va_start(arglist, first);
1161 // CHECK: call i8* @objc_retain
1162 id obj = __builtin_va_arg(arglist, id);
1163 // CHECK: call void @llvm.va_end
1164 __builtin_va_end(arglist);
1165 // CHECK: call void @objc_release
1166 // CHECK: ret void
1167}
John McCall799d34e2011-07-13 18:26:47 +00001168
1169// PR10228
1170@interface Test55Base @end
1171@interface Test55 : Test55Base @end
1172@implementation Test55 (Category)
1173- (void) dealloc {}
1174@end
1175// CHECK: define internal void @"\01-[Test55(Category) dealloc]"(
1176// CHECK-NOT: ret
1177// CHECK: call void bitcast (i8* ({{%.*}}*, i8*, ...)* @objc_msgSendSuper2 to void ({{%.*}}*, i8*)*)(
John McCall6c2c2502011-07-22 02:45:48 +00001178
1179// rdar://problem/8024350
1180@protocol Test56Protocol
1181+ (id) make __attribute__((ns_returns_retained));
1182@end
1183@interface Test56<Test56Protocol> @end
1184@implementation Test56
1185// CHECK: define internal i8* @"\01+[Test56 make]"(
1186+ (id) make {
1187 extern id test56_helper(void);
1188 // CHECK: [[T0:%.*]] = call i8* @test56_helper()
1189 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1190 // CHECK-NEXT: ret i8* [[T1]]
1191 return test56_helper();
1192}
1193@end
1194void test56_test(void) {
1195 id x = [Test56 make];
1196 // CHECK: define void @test56_test()
1197 // CHECK: [[X:%.*]] = alloca i8*, align 8
1198 // CHECK: [[T0:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*)*)(
1199 // CHECK-NEXT: store i8* [[T0]], i8** [[X]]
1200 // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]]
1201 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
1202 // CHECK-NEXT: ret void
1203}
John McCallba3dd902011-07-22 05:23:13 +00001204
1205// rdar://problem/9784964
1206@interface Test57
1207@property (nonatomic, strong) id strong;
1208@property (nonatomic, weak) id weak;
1209@property (nonatomic, unsafe_unretained) id unsafe;
1210@end
1211@implementation Test57
1212@synthesize strong, weak, unsafe;
1213@end
1214// CHECK: define internal i8* @"\01-[Test57 strong]"(
1215// CHECK: [[T0:%.*]] = load [[TEST57:%.*]]** {{%.*}}
1216// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_Test57.strong"
1217// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST57]]* [[T0]] to i8*
1218// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]]
1219// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8**
1220// CHECK-NEXT: [[T5:%.*]] = load i8** [[T4]]
1221// CHECK-NEXT: ret i8* [[T5]]
1222
1223// CHECK: define internal i8* @"\01-[Test57 weak]"(
1224// CHECK: [[T0:%.*]] = load [[TEST57]]** {{%.*}}
1225// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_Test57.weak"
1226// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST57]]* [[T0]] to i8*
1227// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]]
1228// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8**
1229// CHECK-NEXT: [[T5:%.*]] = call i8* @objc_loadWeakRetained(i8** [[T4]])
Chad Rosierdf76f1e2012-12-12 17:52:21 +00001230// CHECK-NEXT: [[T6:%.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* [[T5]])
John McCallba3dd902011-07-22 05:23:13 +00001231// CHECK-NEXT: ret i8* [[T6]]
1232
1233// CHECK: define internal i8* @"\01-[Test57 unsafe]"(
1234// CHECK: [[T0:%.*]] = load [[TEST57]]** {{%.*}}
1235// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_Test57.unsafe"
1236// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST57]]* [[T0]] to i8*
1237// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]]
1238// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8**
1239// CHECK-NEXT: [[T5:%.*]] = load i8** [[T4]]
1240// CHECK-NEXT: ret i8* [[T5]]
1241
John McCalldc7c5ad2011-07-22 08:53:00 +00001242// rdar://problem/9821110
1243@interface Test58
1244- (char*) interior __attribute__((objc_returns_inner_pointer));
1245// Should we allow this on properties?
1246@end
1247extern Test58 *test58_helper(void);
1248
1249// CHECK: define void @test58a()
1250void test58a(void) {
1251 // CHECK: [[T0:%.*]] = call [[TEST58:%.*]]* @test58_helper()
1252 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST58]]* [[T0]] to i8*
1253 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]])
1254 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST58]]*
1255 // CHECK-NEXT: store [[TEST58]]* [[T3]]
1256 // CHECK-NEXT: [[T0:%.*]] = load [[TEST58]]**
1257 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST58]]* [[T0]] to i8*
1258 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutorelease(i8* [[T1]])
1259 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST58]]*
1260 // CHECK-NEXT: [[T4:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
1261 // CHECK-NEXT: [[T5:%.*]] = bitcast [[TEST58]]* [[T3]] to i8*
1262 // CHECK-NEXT: [[T6:%.*]] = call i8* bitcast
1263 // CHECK-NEXT: store i8* [[T6]], i8**
1264 // CHECK-NEXT: [[T0:%.*]] = load [[TEST58]]**
1265 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST58]]* [[T0]] to i8*
Bill Wendling4e1125f2013-02-22 09:10:20 +00001266 // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release
John McCalldc7c5ad2011-07-22 08:53:00 +00001267 // CHECK-NEXT: ret void
1268 Test58 *ptr = test58_helper();
1269 char *c = [(ptr) interior];
1270}
1271
1272// CHECK: define void @test58b()
1273void test58b(void) {
1274 // CHECK: [[T0:%.*]] = call [[TEST58:%.*]]* @test58_helper()
1275 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST58]]* [[T0]] to i8*
1276 // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]])
1277 // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST58]]*
1278 // CHECK-NEXT: store [[TEST58]]* [[T3]]
1279 // CHECK-NEXT: [[T0:%.*]] = load [[TEST58]]**
1280 // CHECK-NEXT: [[T1:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
1281 // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST58]]* [[T0]] to i8*
1282 // CHECK-NEXT: [[T3:%.*]] = call i8* bitcast
1283 // CHECK-NEXT: store i8* [[T3]], i8**
1284 // CHECK-NEXT: [[T0:%.*]] = load [[TEST58]]**
1285 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST58]]* [[T0]] to i8*
Bill Wendling4e1125f2013-02-22 09:10:20 +00001286 // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]]
John McCalldc7c5ad2011-07-22 08:53:00 +00001287 // CHECK-NOT: clang.imprecise_release
1288 // CHECK-NEXT: ret void
1289 __attribute__((objc_precise_lifetime)) Test58 *ptr = test58_helper();
1290 char *c = [ptr interior];
1291}
John McCall07524032011-07-27 21:50:02 +00001292
1293// rdar://problem/9842343
1294void test59(void) {
1295 extern id test59_getlock(void);
1296 extern void test59_body(void);
1297 @synchronized (test59_getlock()) {
1298 test59_body();
1299 }
1300
1301 // CHECK: define void @test59()
1302 // CHECK: [[T0:%.*]] = call i8* @test59_getlock()
1303 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
Aaron Ballman2d234d732012-09-06 16:44:16 +00001304 // CHECK-NEXT: call i32 @objc_sync_enter(i8* [[T1]])
John McCall07524032011-07-27 21:50:02 +00001305 // CHECK-NEXT: call void @test59_body()
Aaron Ballman2d234d732012-09-06 16:44:16 +00001306 // CHECK-NEXT: call i32 @objc_sync_exit(i8* [[T1]])
John McCall07524032011-07-27 21:50:02 +00001307 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
1308 // CHECK-NEXT: ret void
1309}
John McCallfb720812011-07-28 07:23:35 +00001310
John McCallfc4b1912011-08-03 07:02:44 +00001311// Verify that we don't try to reclaim the result of performSelector.
1312// rdar://problem/9887545
1313@interface Test61
1314- (id) performSelector: (SEL) selector;
1315- (void) test61_void;
1316- (id) test61_id;
1317@end
1318void test61(void) {
1319 // CHECK: define void @test61()
1320 // CHECK: [[Y:%.*]] = alloca i8*, align 8
1321
1322 extern id test61_make(void);
1323
1324 // CHECK-NEXT: [[T0:%.*]] = call i8* @test61_make()
1325 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1326 // CHECK-NEXT: [[T2:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
1327 // CHECK-NEXT: [[T3:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
1328 // CHECK-NEXT: [[T4:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T1]], i8* [[T3]], i8* [[T2]])
1329 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
1330 [test61_make() performSelector: @selector(test61_void)];
1331
1332 // CHECK-NEXT: [[T0:%.*]] = call i8* @test61_make()
1333 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1334 // CHECK-NEXT: [[T2:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
1335 // CHECK-NEXT: [[T3:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
1336 // CHECK-NEXT: [[T4:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T1]], i8* [[T3]], i8* [[T2]])
1337 // CHECK-NEXT: [[T5:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T4]])
1338 // CHECK-NEXT: store i8* [[T5]], i8** [[Y]]
1339 // CHECK-NEXT: call void @objc_release(i8* [[T1]])
1340 id y = [test61_make() performSelector: @selector(test61_id)];
1341
1342 // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]]
1343 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
1344 // CHECK-NEXT: ret void
1345}
John McCallbddfd872011-08-03 22:24:24 +00001346
1347// rdar://problem/9891815
1348void test62(void) {
1349 // CHECK: define void @test62()
1350 // CHECK: [[I:%.*]] = alloca i32, align 4
1351 // CHECK-NEXT: [[CLEANUP_VALUE:%.*]] = alloca i8*
1352 // CHECK-NEXT: [[CLEANUP_REQUIRED:%.*]] = alloca i1
1353 extern id test62_make(void);
1354 extern void test62_body(void);
1355
1356 // CHECK-NEXT: store i32 0, i32* [[I]], align 4
1357 // CHECK-NEXT: br label
1358
1359 // CHECK: [[T0:%.*]] = load i32* [[I]], align 4
1360 // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 20
1361 // CHECK-NEXT: br i1 [[T1]],
1362
1363 for (unsigned i = 0; i != 20; ++i) {
1364 // CHECK: [[T0:%.*]] = load i32* [[I]], align 4
1365 // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 0
1366 // CHECK-NEXT: store i1 false, i1* [[CLEANUP_REQUIRED]]
1367 // CHECK-NEXT: br i1 [[T1]],
1368 // CHECK: [[T0:%.*]] = call i8* @test62_make()
1369 // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1370 // CHECK-NEXT: store i8* [[T1]], i8** [[CLEANUP_VALUE]]
1371 // CHECK-NEXT: store i1 true, i1* [[CLEANUP_REQUIRED]]
1372 // CHECK-NEXT: [[T2:%.*]] = icmp ne i8* [[T1]], null
1373 // CHECK-NEXT: br label
1374 // CHECK: [[COND:%.*]] = phi i1 [ false, {{%.*}} ], [ [[T2]], {{%.*}} ]
1375 // CHECK-NEXT: [[T0:%.*]] = load i1* [[CLEANUP_REQUIRED]]
1376 // CHECK-NEXT: br i1 [[T0]],
1377 // CHECK: [[T0:%.*]] = load i8** [[CLEANUP_VALUE]]
1378 // CHECK-NEXT: call void @objc_release(i8* [[T0]])
1379 // CHECK-NEXT: br label
1380 // CHECK: br i1 [[COND]]
1381 // CHECK: call void @test62_body()
1382 // CHECK-NEXT: br label
1383 // CHECK: br label
1384 if (i != 0 && test62_make() != 0)
1385 test62_body();
1386 }
1387
1388 // CHECK: [[T0:%.*]] = load i32* [[I]], align 4
1389 // CHECK-NEXT: [[T1:%.*]] = add i32 [[T0]], 1
1390 // CHECK-NEXT: store i32 [[T1]], i32* [[I]]
1391 // CHECK-NEXT: br label
1392
1393 // CHECK: ret void
1394}
Fariborz Jahanianbc03aea2011-08-19 19:28:44 +00001395
1396// rdar://9971982
1397@class NSString;
1398
1399@interface Person {
1400 NSString *name;
1401}
1402@property NSString *address;
1403@end
1404
1405@implementation Person
1406@synthesize address;
1407@end
1408// CHECK: call i8* @objc_getProperty
1409// CHECK: call void @objc_setProperty
1410
John McCallcdda47f2011-10-01 09:56:14 +00001411// Verify that we successfully parse and preserve this attribute in
1412// this position.
1413@interface Test66
1414- (void) consume: (id __attribute__((ns_consumed))) ptr;
1415@end
1416void test66(void) {
1417 extern Test66 *test66_receiver(void);
1418 extern id test66_arg(void);
1419 [test66_receiver() consume: test66_arg()];
1420}
1421// CHECK: define void @test66()
1422// CHECK: [[T0:%.*]] = call [[TEST66:%.*]]* @test66_receiver()
1423// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST66]]* [[T0]] to i8*
1424// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]])
1425// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST66]]*
Fariborz Jahanian4e1524b2012-01-29 20:27:13 +00001426// CHECK-NEXT: [[T4:%.*]] = call i8* @test66_arg()
John McCallcdda47f2011-10-01 09:56:14 +00001427// CHECK-NEXT: [[T5:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T4]])
1428// CHECK-NEXT: [[T6:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES
1429// CHECK-NEXT: [[T7:%.*]] = bitcast [[TEST66]]* [[T3]] to i8*
Fariborz Jahanian3c267e62012-01-30 21:40:37 +00001430// CHECK-NEXT: [[SIX:%.*]] = icmp eq i8* [[T7]], null
1431// CHECK-NEXT: br i1 [[SIX]], label [[NULINIT:%.*]], label [[CALL:%.*]]
1432// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i8*)*)(i8* [[T7]], i8* [[T6]], i8* [[T5]])
1433// CHECK-NEXT: br label [[CONT:%.*]]
Bill Wendling4e1125f2013-02-22 09:10:20 +00001434// CHECK: call void @objc_release(i8* [[T5]]) [[NUW]]
Fariborz Jahanian3c267e62012-01-30 21:40:37 +00001435// CHECK-NEXT: br label [[CONT:%.*]]
1436// CHECK: [[T8:%.*]] = bitcast [[TEST66]]* [[T3]] to i8*
John McCallcdda47f2011-10-01 09:56:14 +00001437// CHECK-NEXT: call void @objc_release(i8* [[T8]])
1438// CHECK-NEXT: ret void
John McCall567c5862011-11-14 19:53:16 +00001439
1440// rdar://problem/9953540
1441Class test67_helper(void);
1442void test67(void) {
1443 Class cl = test67_helper();
1444}
1445// CHECK: define void @test67()
1446// CHECK: [[CL:%.*]] = alloca i8*, align 8
1447// CHECK-NEXT: [[T0:%.*]] = call i8* @test67_helper()
1448// CHECK-NEXT: store i8* [[T0]], i8** [[CL]], align 8
1449// CHECK-NEXT: ret void
1450
1451Class test68_helper(void);
1452void test68(void) {
1453 __strong Class cl = test67_helper();
1454}
1455// CHECK: define void @test68()
1456// CHECK: [[CL:%.*]] = alloca i8*, align 8
1457// CHECK-NEXT: [[T0:%.*]] = call i8* @test67_helper()
1458// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
1459// CHECK-NEXT: store i8* [[T1]], i8** [[CL]], align 8
1460// CHECK-NEXT: [[T2:%.*]] = load i8** [[CL]]
1461// CHECK-NEXT: call void @objc_release(i8* [[T2]])
1462// CHECK-NEXT: ret void
John McCall77fe6cd2012-01-29 07:46:59 +00001463
1464// rdar://problem/10564852
1465@interface Test69 @end
1466@implementation Test69
1467- (id) foo { return self; }
1468@end
1469// CHECK: define internal i8* @"\01-[Test69 foo]"(
1470// CHECK: [[SELF:%.*]] = alloca [[TEST69:%.*]]*, align 8
1471// CHECK: [[T0:%.*]] = load [[TEST69]]** [[SELF]], align 8
1472// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST69]]* [[T0]] to i8*
1473// CHECK-NEXT: ret i8* [[T1]]
Eli Friedmanb1e3f322012-02-22 05:38:59 +00001474
1475// rdar://problem/10907547
1476void test70(id i) {
1477 // CHECK: define void @test70
1478 // CHECK: store i8* null, i8**
1479 // CHECK: store i8* null, i8**
1480 // CHECK: [[ID:%.*]] = call i8* @objc_retain(i8*
1481 // CHECK: store i8* [[ID]], i8**
1482 id x[3] = {
1483 [2] = i
1484 };
1485}
Bill Wendlingf7a9da02013-02-20 07:22:19 +00001486
Bill Wendling89924572013-02-27 00:06:04 +00001487// ARC-ALIEN: attributes [[NLB]] = { nonlazybind }
1488// ARC-NATIVE: attributes [[NLB]] = { nonlazybind }
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +00001489// CHECK: attributes [[NUW]] = { nounwind }