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-LABEL: define void @test_numeric() 16void 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 @llvm.lifetime.end 31 // CHECK: call void @objc_release 32 // CHECK: call void @llvm.lifetime.end 33 // CHECK: call void @objc_release 34 // CHECK: call void @llvm.lifetime.end 35 // CHECK: call void @objc_release 36 // CHECK: call void @llvm.lifetime.end 37 // CHECK-NEXT: ret void 38} 39 40// CHECK-LABEL: define void @test_array 41void test_array(id a, id b) { 42 // CHECK: [[A:%.*]] = alloca i8*, 43 // CHECK: [[B:%.*]] = alloca i8*, 44 45 // Retaining parameters 46 // CHECK: call i8* @objc_retain(i8* 47 // CHECK: call i8* @objc_retain(i8* 48 49 // Constructing the array 50 // CHECK: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS:%[A-Za-z0-9]+]], i64 0, i64 0 51 // CHECK-NEXT: [[V0:%.*]] = load i8*, i8** [[A]], 52 // CHECK-NEXT: store i8* [[V0]], i8** [[T0]] 53 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i64 0, i64 1 54 // CHECK-NEXT: [[V1:%.*]] = load i8*, i8** [[B]], 55 // CHECK-NEXT: store i8* [[V1]], i8** [[T0]] 56 57 // CHECK-NEXT: [[T0:%.*]] = load [[CLASS_T:%.*]]*, [[CLASS_T:%.*]]** @"OBJC_CLASSLIST 58 // CHECK-NEXT: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES 59 // CHECK-NEXT: [[T1:%.*]] = bitcast [[CLASS_T]]* [[T0]] to i8* 60 // CHECK-NEXT: [[T2:%.*]] = bitcast [2 x i8*]* [[OBJECTS]] to i8** 61 // CHECK-NEXT: [[T3:%.*]] = call i8* bitcast ({{.*@objc_msgSend.*}})(i8* [[T1]], i8* [[SEL]], i8** [[T2]], i64 2) 62 // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T3]]) 63 // CHECK: call void (...) @clang.arc.use(i8* [[V0]], i8* [[V1]]) 64 id arr = @[a, b]; 65 66 // CHECK: call void @objc_release 67 // CHECK: call void @objc_release 68 // CHECK: call void @objc_release 69 // CHECK-NEXT: ret void 70} 71 72// CHECK-LABEL: define void @test_dictionary 73void test_dictionary(id k1, id o1, id k2, id o2) { 74 // CHECK: [[K1:%.*]] = alloca i8*, 75 // CHECK: [[O1:%.*]] = alloca i8*, 76 // CHECK: [[K2:%.*]] = alloca i8*, 77 // CHECK: [[O2:%.*]] = alloca i8*, 78 79 // Retaining parameters 80 // CHECK: call i8* @objc_retain(i8* 81 // CHECK: call i8* @objc_retain(i8* 82 // CHECK: call i8* @objc_retain(i8* 83 // CHECK: call i8* @objc_retain(i8* 84 85 // Constructing the arrays 86 // CHECK: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[KEYS:%[A-Za-z0-9]+]], i64 0, i64 0 87 // CHECK-NEXT: [[V0:%.*]] = load i8*, i8** [[K1]], 88 // CHECK-NEXT: store i8* [[V0]], i8** [[T0]] 89 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS:%[A-Za-z0-9]+]], i64 0, i64 0 90 // CHECK-NEXT: [[V1:%.*]] = load i8*, i8** [[O1]], 91 // CHECK-NEXT: store i8* [[V1]], i8** [[T0]] 92 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[KEYS]], i64 0, i64 1 93 // CHECK-NEXT: [[V2:%.*]] = load i8*, i8** [[K2]], 94 // CHECK-NEXT: store i8* [[V2]], i8** [[T0]] 95 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i64 0, i64 1 96 // CHECK-NEXT: [[V3:%.*]] = load i8*, i8** [[O2]], 97 // CHECK-NEXT: store i8* [[V3]], i8** [[T0]] 98 99 // Constructing the dictionary 100 // CHECK-NEXT: [[T0:%.*]] = load [[CLASS_T:%.*]]*, [[CLASS_T:%.*]]** @"OBJC_CLASSLIST 101 // CHECK-NEXT: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES 102 // CHECK-NEXT: [[T1:%.*]] = bitcast [[CLASS_T]]* [[T0]] to i8* 103 // CHECK-NEXT: [[T2:%.*]] = bitcast [2 x i8*]* [[OBJECTS]] to i8** 104 // CHECK-NEXT: [[T3:%.*]] = bitcast [2 x i8*]* [[KEYS]] to i8** 105 // CHECK-NEXT: [[T4:%.*]] = call i8* bitcast ({{.*@objc_msgSend.*}})(i8* [[T1]], i8* [[SEL]], i8** [[T2]], i8** [[T3]], i64 2) 106 // CHECK-NEXT: [[T5:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T4]]) 107 // CHECK-NEXT: call void (...) @clang.arc.use(i8* [[V0]], i8* [[V1]], i8* [[V2]], i8* [[V3]]) 108 109 id dict = @{ k1 : o1, k2 : o2 }; 110 111 // CHECK: call void @objc_release 112 // CHECK: call void @objc_release 113 // CHECK: call void @objc_release 114 // CHECK: call void @objc_release 115 // CHECK: call void @objc_release 116 // CHECK-NEXT: ret void 117} 118 119@interface A 120@end 121 122@interface B 123@property (retain) A* prop; 124@end 125 126// CHECK-LABEL: define void @test_property 127void test_property(B *b) { 128 // Retain parameter 129 // CHECK: call i8* @objc_retain 130 131 // CHECK: [[T0:%.*]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[OBJECTS:%.*]], i64 0, i64 0 132 133 // Invoke 'prop' 134 // CHECK: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES 135 // CHECK-NEXT: [[T1:%.*]] = bitcast 136 // CHECK-NEXT: [[T2:%.*]] = call [[B:%.*]]* bitcast ({{.*}} @objc_msgSend to {{.*}})(i8* [[T1]], i8* [[SEL]]) 137 // CHECK-NEXT: [[T3:%.*]] = bitcast [[B]]* [[T2]] to i8* 138 // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T3]]) 139 // CHECK-NEXT: [[V0:%.*]] = bitcast i8* [[T4]] to [[B]]* 140 // CHECK-NEXT: [[V1:%.*]] = bitcast [[B]]* [[V0]] to i8* 141 142 // Store to array. 143 // CHECK-NEXT: store i8* [[V1]], i8** [[T0]] 144 145 // Invoke arrayWithObjects:count: 146 // CHECK-NEXT: [[T0:%.*]] = load [[CLASS_T]]*, [[CLASS_T]]** @"OBJC_CLASSLIST 147 // CHECK-NEXT: [[SEL:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES 148 // CHECK-NEXT: [[T1:%.*]] = bitcast [[CLASS_T]]* [[T0]] to i8* 149 // CHECK-NEXT: [[T2:%.*]] = bitcast [1 x i8*]* [[OBJECTS]] to i8** 150 // CHECK-NEXT: [[T3:%.*]] = call i8* bitcast ({{.*}} @objc_msgSend to {{.*}}(i8* [[T1]], i8* [[SEL]], i8** [[T2]], i64 1) 151 // CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue(i8* [[T3]]) 152 // CHECK-NEXT: call void (...) @clang.arc.use(i8* [[V1]]) 153 // CHECK-NEXT: bitcast 154 // CHECK-NEXT: bitcast 155 // CHECK-NEXT: store 156 id arr = @[ b.prop ]; 157 158 // Release b.prop 159 // CHECK-NEXT: [[T0:%.*]] = bitcast [[B]]* [[V0]] to i8* 160 // CHECK-NEXT: call void @objc_release(i8* [[T0]]) 161 162 // Destroy arr 163 // CHECK: call void @objc_release 164 165 // Destroy b 166 // CHECK: call void @objc_release 167 // CHECK-NEXT: ret void 168} 169