llvm-project
73 строки · 2.5 Кб
1// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck %s
2
3@interface NSObject @end
4
5@interface SomeClass : NSObject
6- (id) init;
7@end
8
9@implementation SomeClass
10- (void)foo {
11}
12- (id) init {
13return 0;
14}
15+ alloc { return 0; }
16@end
17
18int main (int argc, const char * argv[]) {
19@autoreleasepool {
20SomeClass *objPtr1 = [[SomeClass alloc] init];
21__weak SomeClass *weakRef = objPtr1;
22
23[weakRef foo];
24
25objPtr1 = (void *)0;
26return 0;
27}
28}
29
30// CHECK: [[SIXTEEN:%.*]] = call ptr @llvm.objc.loadWeakRetained(ptr {{%.*}})
31// CHECK-NEXT: [[EIGHTEEN:%.*]] = load ptr, ptr @OBJC_SELECTOR_REFERENCES_.6
32// CHECK-NEXT: call void @objc_msgSend
33// CHECK-NEXT: call void @llvm.objc.release(ptr [[SIXTEEN]])
34
35void test1(int cond) {
36extern void test34_sink(id *);
37__weak id weak;
38test34_sink(cond ? &weak : 0);
39}
40
41// CHECK-LABEL: define{{.*}} void @test1(
42// CHECK: [[CONDADDR:%.*]] = alloca i32
43// CHECK-NEXT: [[WEAK:%.*]] = alloca ptr
44// CHECK-NEXT: [[INCRTEMP:%.*]] = alloca ptr
45// CHECK-NEXT: [[CONDCLEANUPSAVE:%.*]] = alloca ptr
46// CHECK-NEXT: [[CONDCLEANUP:%.*]] = alloca i1
47// CHECK-NEXT: store i32
48// CHECK-NEXT: store ptr null, ptr [[WEAK]]
49// CHECK: [[COND1:%.*]] = phi ptr
50// CHECK-NEXT: [[ICRISNULL:%.*]] = icmp eq ptr [[COND1]], null
51// CHECK-NEXT: [[ICRARGUMENT:%.*]] = select i1 [[ICRISNULL]], ptr null, ptr [[INCRTEMP]]
52// CHECK-NEXT: store i1 false, ptr [[CONDCLEANUP]]
53// CHECK-NEXT: br i1 [[ICRISNULL]], label [[ICRCONT:%.*]], label [[ICRCOPY:%.*]]
54// CHECK: [[ONE:%.*]] = call ptr @llvm.objc.loadWeakRetained(
55// CHECK-NEXT: store ptr [[ONE]], ptr [[CONDCLEANUPSAVE]]
56// CHECK-NEXT: store i1 true, ptr [[CONDCLEANUP]]
57// CHECK-NEXT: store ptr [[ONE]], ptr [[INCRTEMP]]
58// CHECK-NEXT: br label
59
60// CHECK: call void @test34_sink(
61// CHECK-NEXT: [[ICRISNULL1:%.*]] = icmp eq ptr [[COND1]], null
62// CHECK-NEXT: br i1 [[ICRISNULL1]], label [[ICRDONE:%.*]], label [[ICRWRITEBACK:%.*]]
63// CHECK: [[TWO:%.*]] = load ptr, ptr [[INCRTEMP]]
64// CHECK-NEXT: [[THREE:%.*]] = call ptr @llvm.objc.storeWeak(
65// CHECK-NEXT: br label [[ICRDONE]]
66// CHECK: [[CLEANUPISACTIVE:%.*]] = load i1, ptr [[CONDCLEANUP]]
67// CHECK-NEXT: br i1 [[CLEANUPISACTIVE]], label [[CLEASNUPACTION:%.*]], label [[CLEANUPDONE:%.*]]
68
69// CHECK: [[FOUR:%.*]] = load ptr, ptr [[CONDCLEANUPSAVE]]
70// CHECK-NEXT: call void @llvm.objc.release(ptr [[FOUR]])
71// CHECK-NEXT: br label
72// CHECK: call void @llvm.objc.destroyWeak(ptr [[WEAK]])
73// CHECK-NEXT: ret void
74