1 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck %s
4 @interface NSObject @end
6 @interface SomeClass : NSObject
10 @implementation SomeClass
19 int main (int argc, const char * argv[]) {
21 SomeClass *objPtr1 = [[SomeClass alloc] init];
22 __weak SomeClass *weakRef = objPtr1;
31 // CHECK: [[SIXTEEN:%.*]] = call i8* @llvm.objc.loadWeakRetained(i8** {{%.*}})
32 // CHECK-NEXT: [[SEVENTEEN:%.*]] = bitcast i8* [[SIXTEEN]] to {{%.*}}
33 // CHECK-NEXT: [[NINETEEN:%.*]] = bitcast %0* [[SEVENTEEN]] to i8*
34 // CHECK-NEXT: [[EIGHTEEN:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES_.6
35 // CHECK-NEXT: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
36 // CHECK-NEXT: [[TWENTY:%.*]] = bitcast %0* [[SEVENTEEN]] to i8*
37 // CHECK-NEXT: call void @llvm.objc.release(i8* [[TWENTY]])
39 void test1(int cond) {
40 extern void test34_sink(id *);
42 test34_sink(cond ? &weak : 0);
45 // CHECK-LABEL: define{{.*}} void @test1(
46 // CHECK: [[CONDADDR:%.*]] = alloca i32
47 // CHECK-NEXT: [[WEAK:%.*]] = alloca i8*
48 // CHECK-NEXT: [[INCRTEMP:%.*]] = alloca i8*
49 // CHECK-NEXT: [[CONDCLEANUPSAVE:%.*]] = alloca i8*
50 // CHECK-NEXT: [[CONDCLEANUP:%.*]] = alloca i1
51 // CHECK-NEXT: store i32
52 // CHECK-NEXT: store i8* null, i8** [[WEAK]]
53 // CHECK: [[COND1:%.*]] = phi i8**
54 // CHECK-NEXT: [[ICRISNULL:%.*]] = icmp eq i8** [[COND1]], null
55 // CHECK-NEXT: [[ICRARGUMENT:%.*]] = select i1 [[ICRISNULL]], i8** null, i8** [[INCRTEMP]]
56 // CHECK-NEXT: store i1 false, i1* [[CONDCLEANUP]]
57 // CHECK-NEXT: br i1 [[ICRISNULL]], label [[ICRCONT:%.*]], label [[ICRCOPY:%.*]]
58 // CHECK: [[ONE:%.*]] = call i8* @llvm.objc.loadWeakRetained(
59 // CHECK-NEXT: store i8* [[ONE]], i8** [[CONDCLEANUPSAVE]]
60 // CHECK-NEXT: store i1 true, i1* [[CONDCLEANUP]]
61 // CHECK-NEXT: store i8* [[ONE]], i8** [[INCRTEMP]]
62 // CHECK-NEXT: br label
64 // CHECK: call void @test34_sink(
65 // CHECK-NEXT: [[ICRISNULL1:%.*]] = icmp eq i8** [[COND1]], null
66 // CHECK-NEXT: br i1 [[ICRISNULL1]], label [[ICRDONE:%.*]], label [[ICRWRITEBACK:%.*]]
67 // CHECK: [[TWO:%.*]] = load i8*, i8** [[INCRTEMP]]
68 // CHECK-NEXT: [[THREE:%.*]] = call i8* @llvm.objc.storeWeak(
69 // CHECK-NEXT: br label [[ICRDONE]]
70 // CHECK: [[CLEANUPISACTIVE:%.*]] = load i1, i1* [[CONDCLEANUP]]
71 // CHECK-NEXT: br i1 [[CLEANUPISACTIVE]], label [[CLEASNUPACTION:%.*]], label [[CLEANUPDONE:%.*]]
73 // CHECK: [[FOUR:%.*]] = load i8*, i8** [[CONDCLEANUPSAVE]]
74 // CHECK-NEXT: call void @llvm.objc.release(i8* [[FOUR]])
75 // CHECK-NEXT: br label
76 // CHECK: call void @llvm.objc.destroyWeak(i8** [[WEAK]])
77 // CHECK-NEXT: ret void