1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck %s
3 @interface NSObject @end
5 @interface SomeClass : NSObject
9 @implementation SomeClass
18 int main (int argc, const char * argv[]) {
20 SomeClass *objPtr1 = [[SomeClass alloc] init];
21 __weak SomeClass *weakRef = objPtr1;
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]])
35 void test1(int cond) {
36 extern void test34_sink(id *);
38 test34_sink(cond ? &weak : 0);
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
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:%.*]]
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