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