1 // RUN: %clang_cc1 -I %S/Inputs -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -O2 -disable-llvm-optzns -o - %s | FileCheck %s 2 3 #include "literal-support.h" 4 5 // Check the various selector names we'll be using, in order. 6 7 // CHECK: c"numberWithInt:\00" 8 // CHECK: c"numberWithUnsignedInt:\00" 9 // CHECK: c"numberWithUnsignedLongLong:\00" 10 // CHECK: c"numberWithChar:\00" 11 // CHECK: c"arrayWithObjects:count:\00" 12 // CHECK: c"dictionaryWithObjects:forKeys:count:\00" 13 // CHECK: c"prop\00" 14 15 // CHECK: define void @test_numeric() 16 void test_numeric() { 17 // CHECK: {{call.*objc_msgSend.*i32 17}} 18 // CHECK: call i8* @objc_retainAutoreleasedReturnValue 19 id ilit = @17; 20 // CHECK: {{call.*objc_msgSend.*i32 25}} 21 // CHECK: call i8* @objc_retainAutoreleasedReturnValue 22 id ulit = @25u; 23 // CHECK: {{call.*objc_msgSend.*i64 42}} 24 // CHECK: call i8* @objc_retainAutoreleasedReturnValue 25 id ulllit = @42ull; 26 // CHECK: {{call.*objc_msgSend.*i8 signext 97}} 27 // CHECK: call i8* @objc_retainAutoreleasedReturnValue 28 id charlit = @'a'; 29 // CHECK: call void @objc_release 30 // CHECK: call void @objc_release 31 // CHECK: call void @objc_release 32 // CHECK: call void @objc_release 33 // CHECK-NEXT: ret void 34 } 35 36 // CHECK: define void @test_array 37 void test_array(id a, id b) { 38 // CHECK: [[A:%.*]] = alloca i8*, 39 // CHECK: [[B:%.*]] = alloca i8*, 40 41 // Retaining parameters 42 // CHECK: call i8* @objc_retain(i8* 43 // CHECK: call i8* @objc_retain(i8* 44 45 // Constructing the array 46 // CHECK: [[T0:%.*]] = getelementptr inbounds [2 x i8*]* [[OBJECTS:%[A-Za-z0-9]+]], i32 0, i32 0 47 // CHECK-NEXT: [[V0:%.*]] = load i8** [[A]], 48 // CHECK-NEXT: store i8* [[V0]], i8** [[T0]] 49 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*]* [[OBJECTS]], i32 0, i32 1 50 // CHECK-NEXT: [[V1:%.*]] = load i8** [[B]], 51 // CHECK-NEXT: store i8* [[V1]], i8** [[T0]] 52 53 // CHECK-NEXT: [[T0:%.*]] = load [[CLASS_T:%.*]]** @"\01L_OBJC_CLASSLIST 54 // CHECK-NEXT: [[SEL:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES 55 // CHECK-NEXT: [[T1:%.*]] = bitcast [[CLASS_T]]* [[T0]] to i8* 56 // CHECK-NEXT: [[T2:%.*]] = bitcast [2 x i8*]* [[OBJECTS]] to i8** 57 // CHECK-NEXT: [[T3:%.*]] = call i8* bitcast ({{.*@objc_msgSend.*}})(i8* [[T1]], i8* [[SEL]], i8** [[T2]], i64 2) 58 // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T3]]) 59 // CHECK: call void (...)* @clang.arc.use(i8* [[V0]], i8* [[V1]]) 60 id arr = @[a, b]; 61 62 // CHECK: call void @objc_release 63 // CHECK: call void @objc_release 64 // CHECK: call void @objc_release 65 // CHECK-NEXT: ret void 66 } 67 68 // CHECK: define void @test_dictionary 69 void test_dictionary(id k1, id o1, id k2, id o2) { 70 // CHECK: [[K1:%.*]] = alloca i8*, 71 // CHECK: [[O1:%.*]] = alloca i8*, 72 // CHECK: [[K2:%.*]] = alloca i8*, 73 // CHECK: [[O2:%.*]] = alloca i8*, 74 75 // Retaining parameters 76 // CHECK: call i8* @objc_retain(i8* 77 // CHECK: call i8* @objc_retain(i8* 78 // CHECK: call i8* @objc_retain(i8* 79 // CHECK: call i8* @objc_retain(i8* 80 81 // Constructing the arrays 82 // CHECK: [[T0:%.*]] = getelementptr inbounds [2 x i8*]* [[KEYS:%[A-Za-z0-9]+]], i32 0, i32 0 83 // CHECK-NEXT: [[V0:%.*]] = load i8** [[K1]], 84 // CHECK-NEXT: store i8* [[V0]], i8** [[T0]] 85 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*]* [[OBJECTS:%[A-Za-z0-9]+]], i32 0, i32 0 86 // CHECK-NEXT: [[V1:%.*]] = load i8** [[O1]], 87 // CHECK-NEXT: store i8* [[V1]], i8** [[T0]] 88 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*]* [[KEYS]], i32 0, i32 1 89 // CHECK-NEXT: [[V2:%.*]] = load i8** [[K2]], 90 // CHECK-NEXT: store i8* [[V2]], i8** [[T0]] 91 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*]* [[OBJECTS]], i32 0, i32 1 92 // CHECK-NEXT: [[V3:%.*]] = load i8** [[O2]], 93 // CHECK-NEXT: store i8* [[V3]], i8** [[T0]] 94 95 // Constructing the dictionary 96 // CHECK-NEXT: [[T0:%.*]] = load [[CLASS_T:%.*]]** @"\01L_OBJC_CLASSLIST 97 // CHECK-NEXT: [[SEL:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES 98 // CHECK-NEXT: [[T1:%.*]] = bitcast [[CLASS_T]]* [[T0]] to i8* 99 // CHECK-NEXT: [[T2:%.*]] = bitcast [2 x i8*]* [[OBJECTS]] to i8** 100 // CHECK-NEXT: [[T3:%.*]] = bitcast [2 x i8*]* [[KEYS]] to i8** 101 // CHECK-NEXT: [[T4:%.*]] = call i8* bitcast ({{.*@objc_msgSend.*}})(i8* [[T1]], i8* [[SEL]], i8** [[T2]], i8** [[T3]], i64 2) 102 // CHECK-NEXT: [[T5:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T4]]) 103 // CHECK-NEXT: call void (...)* @clang.arc.use(i8* [[V0]], i8* [[V1]], i8* [[V2]], i8* [[V3]]) 104 105 id dict = @{ k1 : o1, k2 : o2 }; 106 107 // CHECK: call void @objc_release 108 // CHECK: call void @objc_release 109 // CHECK: call void @objc_release 110 // CHECK: call void @objc_release 111 // CHECK: call void @objc_release 112 // CHECK-NEXT: ret void 113 } 114 115 @interface A 116 @end 117 118 @interface B 119 @property (retain) A* prop; 120 @end 121 122 // CHECK: define void @test_property 123 void test_property(B *b) { 124 // Retain parameter 125 // CHECK: call i8* @objc_retain 126 127 // CHECK: [[T0:%.*]] = getelementptr inbounds [1 x i8*]* [[OBJECTS:%.*]], i32 0, i32 0 128 129 // Invoke 'prop' 130 // CHECK: [[SEL:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES 131 // CHECK-NEXT: [[T1:%.*]] = bitcast 132 // CHECK-NEXT: [[T2:%.*]] = call [[B:%.*]]* bitcast ({{.*}} @objc_msgSend to {{.*}})(i8* [[T1]], i8* [[SEL]]) 133 // CHECK-NEXT: [[T3:%.*]] = bitcast [[B]]* [[T2]] to i8* 134 // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T3]]) 135 // CHECK-NEXT: [[V0:%.*]] = bitcast i8* [[T4]] to [[B]]* 136 // CHECK-NEXT: [[V1:%.*]] = bitcast [[B]]* [[V0]] to i8* 137 138 // Store to array. 139 // CHECK-NEXT: store i8* [[V1]], i8** [[T0]] 140 141 // Invoke arrayWithObjects:count: 142 // CHECK-NEXT: [[T0:%.*]] = load [[CLASS_T]]** @"\01L_OBJC_CLASSLIST 143 // CHECK-NEXT: [[SEL:%.*]] = load i8** @"\01L_OBJC_SELECTOR_REFERENCES 144 // CHECK-NEXT: [[T1:%.*]] = bitcast [[CLASS_T]]* [[T0]] to i8* 145 // CHECK-NEXT: [[T2:%.*]] = bitcast [1 x i8*]* [[OBJECTS]] to i8** 146 // CHECK-NEXT: [[T3:%.*]] = call i8* bitcast ({{.*}} @objc_msgSend to {{.*}}(i8* [[T1]], i8* [[SEL]], i8** [[T2]], i64 1) 147 // CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue(i8* [[T3]]) 148 // CHECK-NEXT: call void (...)* @clang.arc.use(i8* [[V1]]) 149 // CHECK-NEXT: bitcast 150 // CHECK-NEXT: bitcast 151 // CHECK-NEXT: store 152 id arr = @[ b.prop ]; 153 154 // Release b.prop 155 // CHECK-NEXT: [[T0:%.*]] = bitcast [[B]]* [[V0]] to i8* 156 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) 157 158 // Destroy arr 159 // CHECK: call void @objc_release 160 161 // Destroy b 162 // CHECK: call void @objc_release 163 // CHECK-NEXT: ret void 164 } 165