[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / CodeGenObjC / arc-loadweakretained-release.m
blob2ed863a560b79b16a14de518301f8c5c5ef28b78
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
2 // rdar://10849570
4 @interface NSObject @end
6 @interface SomeClass : NSObject
7 - (id) init;
8 @end
10 @implementation SomeClass
11 - (void)foo {
13 - (id) init {
14     return 0;
16 + alloc { return 0; }
17 @end
19 int main (int argc, const char * argv[]) {
20     @autoreleasepool {
21         SomeClass *objPtr1 = [[SomeClass alloc] init];
22         __weak SomeClass *weakRef = objPtr1;
24         [weakRef foo];
26         objPtr1 = (void *)0;
27         return 0;
28     }
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 *);
41   __weak id weak;
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