1f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -O2 -disable-llvm-optzns -o - %s | FileCheck %s 2f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=CHECK-GLOBALS %s 3f4a2713aSLionel Sambuc 4f4a2713aSLionel Sambuc// rdar://13129783. Check both native/non-native arc platforms. Here we check 5f4a2713aSLionel Sambuc// that they treat nonlazybind differently. 6f4a2713aSLionel Sambuc// RUN: %clang_cc1 -fobjc-runtime=macosx-10.6.0 -triple x86_64-apple-darwin10 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=ARC-ALIEN %s 7f4a2713aSLionel Sambuc// RUN: %clang_cc1 -fobjc-runtime=macosx-10.7.0 -triple x86_64-apple-darwin11 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=ARC-NATIVE %s 8f4a2713aSLionel Sambuc 9f4a2713aSLionel Sambuc// ARC-ALIEN: declare extern_weak void @objc_storeStrong(i8**, i8*) 10f4a2713aSLionel Sambuc// ARC-ALIEN: declare extern_weak i8* @objc_retain(i8*) 11f4a2713aSLionel Sambuc// ARC-ALIEN: declare extern_weak i8* @objc_autoreleaseReturnValue(i8*) 12f4a2713aSLionel Sambuc// ARC-ALIEN: declare i8* @objc_msgSend(i8*, i8*, ...) [[NLB:#[0-9]+]] 13f4a2713aSLionel Sambuc// ARC-ALIEN: declare extern_weak void @objc_release(i8*) 14f4a2713aSLionel Sambuc// ARC-ALIEN: declare extern_weak i8* @objc_retainAutoreleasedReturnValue(i8*) 15f4a2713aSLionel Sambuc// ARC-ALIEN: declare extern_weak i8* @objc_initWeak(i8**, i8*) 16f4a2713aSLionel Sambuc// ARC-ALIEN: declare extern_weak i8* @objc_storeWeak(i8**, i8*) 17f4a2713aSLionel Sambuc// ARC-ALIEN: declare extern_weak i8* @objc_loadWeakRetained(i8**) 18f4a2713aSLionel Sambuc// ARC-ALIEN: declare extern_weak void @objc_destroyWeak(i8**) 19f4a2713aSLionel Sambuc// ARC-ALIEN: declare extern_weak i8* @objc_autorelease(i8*) 20f4a2713aSLionel Sambuc// ARC-ALIEN: declare extern_weak i8* @objc_retainAutorelease(i8*) 21f4a2713aSLionel Sambuc 22f4a2713aSLionel Sambuc// ARC-NATIVE: declare void @objc_storeStrong(i8**, i8*) 23f4a2713aSLionel Sambuc// ARC-NATIVE: declare i8* @objc_retain(i8*) [[NLB:#[0-9]+]] 24f4a2713aSLionel Sambuc// ARC-NATIVE: declare i8* @objc_autoreleaseReturnValue(i8*) 25f4a2713aSLionel Sambuc// ARC-NATIVE: declare i8* @objc_msgSend(i8*, i8*, ...) [[NLB]] 26f4a2713aSLionel Sambuc// ARC-NATIVE: declare void @objc_release(i8*) [[NLB]] 27f4a2713aSLionel Sambuc// ARC-NATIVE: declare i8* @objc_retainAutoreleasedReturnValue(i8*) 28f4a2713aSLionel Sambuc// ARC-NATIVE: declare i8* @objc_initWeak(i8**, i8*) 29f4a2713aSLionel Sambuc// ARC-NATIVE: declare i8* @objc_storeWeak(i8**, i8*) 30f4a2713aSLionel Sambuc// ARC-NATIVE: declare i8* @objc_loadWeakRetained(i8**) 31f4a2713aSLionel Sambuc// ARC-NATIVE: declare void @objc_destroyWeak(i8**) 32f4a2713aSLionel Sambuc// ARC-NATIVE: declare i8* @objc_autorelease(i8*) 33f4a2713aSLionel Sambuc// ARC-NATIVE: declare i8* @objc_retainAutorelease(i8*) 34f4a2713aSLionel Sambuc 35f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test0 36f4a2713aSLionel Sambucvoid test0(id x) { 37f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i8* 38f4a2713aSLionel Sambuc // CHECK-NEXT: [[PARM:%.*]] = call i8* @objc_retain(i8* {{.*}}) 39f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[PARM]], i8** [[X]] 40f4a2713aSLionel Sambuc // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]] 41f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) 42f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 43f4a2713aSLionel Sambuc} 44f4a2713aSLionel Sambuc 45f4a2713aSLionel Sambuc// CHECK-LABEL: define i8* @test1(i8* 46f4a2713aSLionel Sambucid test1(id x) { 47f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i8* 48f4a2713aSLionel Sambuc // CHECK-NEXT: [[Y:%.*]] = alloca i8* 49f4a2713aSLionel Sambuc // CHECK-NEXT: alloca i32 50f4a2713aSLionel Sambuc // CHECK-NEXT: [[PARM:%.*]] = call i8* @objc_retain(i8* {{%.*}}) 51f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[PARM]], i8** [[X]] 52f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* null, i8** [[Y]] 53f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] 54f4a2713aSLionel Sambuc // CHECK-NEXT: [[RET:%.*]] = call i8* @objc_retain(i8* [[T0]]) 55f4a2713aSLionel Sambuc // CHECK-NEXT: store i32 56f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] 57f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T0]]) 58f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] 59f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) 60f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* [[RET]]) 61f4a2713aSLionel Sambuc // CHECK-NEXT: ret i8* [[T1]] 62f4a2713aSLionel Sambuc id y; 63f4a2713aSLionel Sambuc return y; 64f4a2713aSLionel Sambuc} 65f4a2713aSLionel Sambuc 66f4a2713aSLionel Sambuc@interface Test2 67f4a2713aSLionel Sambuc+ (void) class_method; 68f4a2713aSLionel Sambuc- (void) inst_method; 69f4a2713aSLionel Sambuc@end 70f4a2713aSLionel Sambuc@implementation Test2 71f4a2713aSLionel Sambuc 72f4a2713aSLionel Sambuc// The self pointer of a class method is not retained. 73f4a2713aSLionel Sambuc// CHECK: define internal void @"\01+[Test2 class_method]" 74f4a2713aSLionel Sambuc// CHECK: alloca 75f4a2713aSLionel Sambuc// CHECK-NEXT: alloca 76f4a2713aSLionel Sambuc// CHECK-NEXT: store 77f4a2713aSLionel Sambuc// CHECK-NEXT: store 78f4a2713aSLionel Sambuc// CHECK-NEXT: ret void 79f4a2713aSLionel Sambuc+ (void) class_method {} 80f4a2713aSLionel Sambuc 81f4a2713aSLionel Sambuc// The self pointer of an instance method is not retained. 82f4a2713aSLionel Sambuc// CHECK: define internal void @"\01-[Test2 inst_method]" 83f4a2713aSLionel Sambuc// CHECK: alloca 84f4a2713aSLionel Sambuc// CHECK-NEXT: alloca 85f4a2713aSLionel Sambuc// CHECK-NEXT: store 86f4a2713aSLionel Sambuc// CHECK-NEXT: store 87f4a2713aSLionel Sambuc// CHECK-NEXT: ret void 88f4a2713aSLionel Sambuc- (void) inst_method {} 89f4a2713aSLionel Sambuc@end 90f4a2713aSLionel Sambuc 91f4a2713aSLionel Sambuc@interface Test3 92f4a2713aSLionel Sambuc+ (id) alloc; 93f4a2713aSLionel Sambuc- (id) initWith: (int) x; 94f4a2713aSLionel Sambuc- (id) copy; 95f4a2713aSLionel Sambuc@end 96f4a2713aSLionel Sambuc 97f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test3_unelided() 98f4a2713aSLionel Sambucvoid test3_unelided() { 99f4a2713aSLionel Sambuc extern void test3_helper(void); 100f4a2713aSLionel Sambuc 101f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca [[TEST3:%.*]]* 102f4a2713aSLionel Sambuc // CHECK-NEXT: store [[TEST3]]* null, [[TEST3]]** [[X]], align 103f4a2713aSLionel Sambuc Test3 *x; 104f4a2713aSLionel Sambuc 105f4a2713aSLionel Sambuc // Call to +alloc. 106*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load {{.*}}* @"OBJC_CLASSLIST_REFERENCES_ 107*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load i8** @OBJC_SELECTOR_REFERENCES_ 108f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 109f4a2713aSLionel Sambuc // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend 110f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 111f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 112f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* 113f4a2713aSLionel Sambuc [Test3 alloc]; 114f4a2713aSLionel Sambuc 115f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[TEST3]]** [[X]] 116*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load i8** @OBJC_SELECTOR_REFERENCES_ 117f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST3]]* [[T0]] to i8* 118f4a2713aSLionel Sambuc // CHECK-NEXT: [[COPY:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend {{.*}})(i8* [[T1]], 119f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[COPY]]) [[NUW:#[0-9]+]] 120f4a2713aSLionel Sambuc [x copy]; 121f4a2713aSLionel Sambuc 122f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[TEST3]]** [[X]] 123f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST3]]* [[T0]] to i8* 124f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]] 125f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 126f4a2713aSLionel Sambuc} 127f4a2713aSLionel Sambuc 128f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test3() 129f4a2713aSLionel Sambucvoid test3() { 130f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i8* 131f4a2713aSLionel Sambuc 132f4a2713aSLionel Sambuc id x = [[Test3 alloc] initWith: 5]; 133f4a2713aSLionel Sambuc 134f4a2713aSLionel Sambuc // Call to +alloc. 135*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load {{.*}}* @"OBJC_CLASSLIST_REFERENCES_ 136*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load i8** @OBJC_SELECTOR_REFERENCES_ 137f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 138f4a2713aSLionel Sambuc // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend 139f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 140f4a2713aSLionel Sambuc 141f4a2713aSLionel Sambuc // Call to -initWith: with elided retain of consumed argument. 142*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load i8** @OBJC_SELECTOR_REFERENCES_ 143f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 144f4a2713aSLionel Sambuc // CHECK-NEXT: [[INIT:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i32)*)(i8* 145f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 146f4a2713aSLionel Sambuc // CHECK-NEXT: [[INIT:%.*]] = bitcast 147f4a2713aSLionel Sambuc // Assignment for initialization, retention elided. 148f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[INIT]], i8** [[X]] 149f4a2713aSLionel Sambuc 150f4a2713aSLionel Sambuc // Call to -copy. 151f4a2713aSLionel Sambuc // CHECK-NEXT: [[V:%.*]] = load i8** [[X]] 152*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load i8** @OBJC_SELECTOR_REFERENCES_ 153f4a2713aSLionel Sambuc // CHECK-NEXT: [[COPY:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend {{.*}})(i8* [[V]], 154f4a2713aSLionel Sambuc 155f4a2713aSLionel Sambuc // Assignment to x. 156f4a2713aSLionel Sambuc // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]] 157f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[COPY]], i8** [[X]] 158f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) [[NUW]] 159f4a2713aSLionel Sambuc 160f4a2713aSLionel Sambuc x = [x copy]; 161f4a2713aSLionel Sambuc 162f4a2713aSLionel Sambuc // Cleanup for x. 163f4a2713aSLionel Sambuc // CHECK-NEXT: [[TMP:%.*]] = load i8** [[X]] 164f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) [[NUW]] 165f4a2713aSLionel Sambuc 166f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 167f4a2713aSLionel Sambuc} 168f4a2713aSLionel Sambuc 169f4a2713aSLionel Sambuc// CHECK-LABEL: define i8* @test4() 170f4a2713aSLionel Sambucid test4() { 171f4a2713aSLionel Sambuc // Call to +alloc. 172*0a6a1f1dSLionel Sambuc // CHECK: load {{.*}}* @"OBJC_CLASSLIST_REFERENCES_ 173*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load i8** @OBJC_SELECTOR_REFERENCES_ 174f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 175f4a2713aSLionel Sambuc // CHECK-NEXT: [[ALLOC:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend 176f4a2713aSLionel Sambuc // CHECK-NEXT: [[ALLOC:%.*]] = bitcast 177f4a2713aSLionel Sambuc 178f4a2713aSLionel Sambuc // Call to -initWith: with elided retain of consumed argument. 179*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load i8** @OBJC_SELECTOR_REFERENCES_ 180f4a2713aSLionel Sambuc // CHECK-NEXT: [[ALLOC:%.*]] = bitcast 181f4a2713aSLionel Sambuc // CHECK-NEXT: [[INIT:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i32)*)(i8* [[ALLOC]], 182f4a2713aSLionel Sambuc 183*0a6a1f1dSLionel Sambuc // Initialization of return value, occurring within full-expression. 184f4a2713aSLionel Sambuc // Retain/release elided. 185f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 186f4a2713aSLionel Sambuc // CHECK-NEXT: [[INIT:%.*]] = bitcast 187f4a2713aSLionel Sambuc // CHECK-NEXT: [[RET:%.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* [[INIT]]) 188f4a2713aSLionel Sambuc 189f4a2713aSLionel Sambuc // CHECK-NEXT: ret i8* [[RET]] 190f4a2713aSLionel Sambuc 191f4a2713aSLionel Sambuc return [[Test3 alloc] initWith: 6]; 192f4a2713aSLionel Sambuc} 193f4a2713aSLionel Sambuc 194f4a2713aSLionel Sambuc@interface Test5 { 195f4a2713aSLionel Sambuc@public 196f4a2713aSLionel Sambuc id var; 197f4a2713aSLionel Sambuc} 198f4a2713aSLionel Sambuc@end 199f4a2713aSLionel Sambuc 200f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test5 201f4a2713aSLionel Sambucvoid test5(Test5 *x, id y) { 202f4a2713aSLionel Sambuc // Prologue. 203f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca [[TEST5:%.*]]*, 204f4a2713aSLionel Sambuc // CHECK-NEXT: [[Y:%.*]] = alloca i8* 205f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast [[TEST5]]* {{%.*}} to i8* 206f4a2713aSLionel Sambuc // CHECK-NEXT: call i8* @objc_retain 207f4a2713aSLionel Sambuc // CHECK-NEXT: [[PARMX:%.*]] = bitcast i8* {{%.*}} to [[TEST5]]* 208f4a2713aSLionel Sambuc // CHECK-NEXT: store [[TEST5]]* [[PARMX]], [[TEST5]]** [[X]] 209f4a2713aSLionel Sambuc // CHECK-NEXT: call i8* @objc_retain 210f4a2713aSLionel Sambuc // CHECK-NEXT: store 211f4a2713aSLionel Sambuc 212f4a2713aSLionel Sambuc // CHECK-NEXT: load [[TEST5]]** [[X]] 213f4a2713aSLionel Sambuc // CHECK-NEXT: load i64* @"OBJC_IVAR_$_Test5.var" 214f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 215f4a2713aSLionel Sambuc // CHECK-NEXT: getelementptr 216f4a2713aSLionel Sambuc // CHECK-NEXT: [[VAR:%.*]] = bitcast 217f4a2713aSLionel Sambuc // CHECK-NEXT: [[TMP:%.*]] = load i8** [[VAR]] 218f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* null, i8** [[VAR]] 219f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) [[NUW]] 220f4a2713aSLionel Sambuc x->var = 0; 221f4a2713aSLionel Sambuc 222f4a2713aSLionel Sambuc // CHECK-NEXT: [[YVAL:%.*]] = load i8** [[Y]] 223f4a2713aSLionel Sambuc // CHECK-NEXT: load [[TEST5]]** [[X]] 224f4a2713aSLionel Sambuc // CHECK-NEXT: load i64* @"OBJC_IVAR_$_Test5.var" 225f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 226f4a2713aSLionel Sambuc // CHECK-NEXT: getelementptr 227f4a2713aSLionel Sambuc // CHECK-NEXT: [[VAR:%.*]] = bitcast 228f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* [[YVAL]]) [[NUW]] 229f4a2713aSLionel Sambuc // CHECK-NEXT: [[TMP:%.*]] = load i8** [[VAR]] 230f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T0]], i8** [[VAR]] 231f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) [[NUW]] 232f4a2713aSLionel Sambuc x->var = y; 233f4a2713aSLionel Sambuc 234f4a2713aSLionel Sambuc // Epilogue. 235f4a2713aSLionel Sambuc // CHECK-NEXT: [[TMP:%.*]] = load i8** [[Y]] 236f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[TMP]]) [[NUW]] 237f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[TEST5]]** [[X]] 238f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST5]]* [[T0]] to i8* 239f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]] 240f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 241f4a2713aSLionel Sambuc} 242f4a2713aSLionel Sambuc 243f4a2713aSLionel Sambucid test6_helper(void) __attribute__((ns_returns_retained)); 244f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test6() 245f4a2713aSLionel Sambucvoid test6() { 246f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i8* 247f4a2713aSLionel Sambuc // CHECK-NEXT: [[CALL:%.*]] = call i8* @test6_helper() 248f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[CALL]], i8** [[X]] 249f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] 250f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release 251f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 252f4a2713aSLionel Sambuc id x = test6_helper(); 253f4a2713aSLionel Sambuc} 254f4a2713aSLionel Sambuc 255f4a2713aSLionel Sambucvoid test7_helper(id __attribute__((ns_consumed))); 256f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test7() 257f4a2713aSLionel Sambucvoid test7() { 258f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i8* 259f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* null, i8** [[X]] 260f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] 261f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) [[NUW]] 262f4a2713aSLionel Sambuc // CHECK-NEXT: call void @test7_helper(i8* [[T1]]) 263f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] 264f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release 265f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 266f4a2713aSLionel Sambuc id x; 267f4a2713aSLionel Sambuc test7_helper(x); 268f4a2713aSLionel Sambuc} 269f4a2713aSLionel Sambuc 270f4a2713aSLionel Sambucid test8_helper(void) __attribute__((ns_returns_retained)); 271f4a2713aSLionel Sambucvoid test8() { 272f4a2713aSLionel Sambuc __unsafe_unretained id x = test8_helper(); 273f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i8* 274f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = call i8* @test8_helper() 275f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T0]], i8** [[X]] 276f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release 277f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 278f4a2713aSLionel Sambuc} 279f4a2713aSLionel Sambuc 280f4a2713aSLionel Sambuc@interface Test10 281f4a2713aSLionel Sambuc@property (retain) Test10 *me; 282f4a2713aSLionel Sambuc@end 283f4a2713aSLionel Sambucvoid test10() { 284f4a2713aSLionel Sambuc Test10 *x; 285f4a2713aSLionel Sambuc id y = x.me.me; 286f4a2713aSLionel Sambuc 287f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test10() 288f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca [[TEST10:%.*]]*, align 289f4a2713aSLionel Sambuc // CHECK-NEXT: [[Y:%.*]] = alloca i8*, align 290f4a2713aSLionel Sambuc // CHECK-NEXT: store [[TEST10]]* null, [[TEST10]]** [[X]] 291f4a2713aSLionel Sambuc // CHECK-NEXT: load [[TEST10]]** [[X]], align 292*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load i8** @OBJC_SELECTOR_REFERENCES_{{[0-9]*}} 293f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 294f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = call [[TEST10]]* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend 295f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8* 296f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) 297f4a2713aSLionel Sambuc // CHECK-NEXT: [[V:%.*]] = bitcast i8* [[T2]] to [[TEST10]]* 298*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load i8** @OBJC_SELECTOR_REFERENCES_{{[0-9]*}} 299f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 300f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = call [[TEST10]]* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend 301f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8* 302f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) 303f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST10]]* 304f4a2713aSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = bitcast [[TEST10]]* [[T3]] to i8* 305f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T4]], i8** [[Y]] 306f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST10]]* [[V]] to i8* 307f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T0]]) 308f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] 309f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T0]]) 310f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[TEST10]]** [[X]] 311f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST10]]* [[T0]] to i8* 312f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) 313f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 314f4a2713aSLionel Sambuc} 315f4a2713aSLionel Sambuc 316f4a2713aSLionel Sambucvoid test11(id (*f)(void) __attribute__((ns_returns_retained))) { 317f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test11( 318f4a2713aSLionel Sambuc // CHECK: [[F:%.*]] = alloca i8* ()*, align 319f4a2713aSLionel Sambuc // CHECK-NEXT: [[X:%.*]] = alloca i8*, align 320f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* ()* {{%.*}}, i8* ()** [[F]], align 321f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i8* ()** [[F]], align 322f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = call i8* [[T0]]() 323f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T1]], i8** [[X]], align 324f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = load i8** [[X]] 325f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T3]]) [[NUW]], !clang.imprecise_release 326f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 327f4a2713aSLionel Sambuc id x = f(); 328f4a2713aSLionel Sambuc} 329f4a2713aSLionel Sambuc 330f4a2713aSLionel Sambucvoid test12(void) { 331f4a2713aSLionel Sambuc extern id test12_helper(void); 332f4a2713aSLionel Sambuc 333f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test12() 334f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i8*, align 335f4a2713aSLionel Sambuc // CHECK-NEXT: [[Y:%.*]] = alloca i8*, align 336f4a2713aSLionel Sambuc 337f4a2713aSLionel Sambuc __weak id x = test12_helper(); 338f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = call i8* @test12_helper() 339f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) 340f4a2713aSLionel Sambuc // CHECK-NEXT: call i8* @objc_initWeak(i8** [[X]], i8* [[T1]]) 341f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) 342f4a2713aSLionel Sambuc 343f4a2713aSLionel Sambuc x = test12_helper(); 344f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = call i8* @test12_helper() 345f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) 346f4a2713aSLionel Sambuc // CHECK-NEXT: call i8* @objc_storeWeak(i8** [[X]], i8* [[T1]]) 347f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) 348f4a2713aSLionel Sambuc 349f4a2713aSLionel Sambuc id y = x; 350f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_loadWeakRetained(i8** [[X]]) 351f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T2]], i8** [[Y]], align 352f4a2713aSLionel Sambuc 353f4a2713aSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = load i8** [[Y]] 354f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T4]]) [[NUW]], !clang.imprecise_release 355f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]]) 356f4a2713aSLionel Sambuc // CHECK: ret void 357f4a2713aSLionel Sambuc} 358f4a2713aSLionel Sambuc 359f4a2713aSLionel Sambuc// Indirect consuming calls. 360f4a2713aSLionel Sambucvoid test13(void) { 361f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test13() 362f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i8*, align 363f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* null, i8** [[X]], align 364f4a2713aSLionel Sambuc id x; 365f4a2713aSLionel Sambuc 366f4a2713aSLionel Sambuc typedef void fnty(id __attribute__((ns_consumed))); 367f4a2713aSLionel Sambuc extern fnty *test13_func; 368f4a2713aSLionel Sambuc // CHECK-NEXT: [[FN:%.*]] = load void (i8*)** @test13_func, align 369f4a2713aSLionel Sambuc // CHECK-NEXT: [[X_VAL:%.*]] = load i8** [[X]], align 370f4a2713aSLionel Sambuc // CHECK-NEXT: [[X_TMP:%.*]] = call i8* @objc_retain(i8* [[X_VAL]]) [[NUW]] 371f4a2713aSLionel Sambuc // CHECK-NEXT: call void [[FN]](i8* [[X_TMP]]) 372f4a2713aSLionel Sambuc test13_func(x); 373f4a2713aSLionel Sambuc 374f4a2713aSLionel Sambuc extern fnty ^test13_block; 375f4a2713aSLionel Sambuc // CHECK-NEXT: [[TMP:%.*]] = load void (i8*)** @test13_block, align 376f4a2713aSLionel Sambuc // CHECK-NEXT: [[BLOCK:%.*]] = bitcast void (i8*)* [[TMP]] to [[BLOCKTY:%.*]]* 377f4a2713aSLionel Sambuc // CHECK-NEXT: [[BLOCK_FN_PTR:%.*]] = getelementptr inbounds [[BLOCKTY]]* [[BLOCK]], i32 0, i32 3 378f4a2713aSLionel Sambuc // CHECK-NEXT: [[BLOCK_OPAQUE:%.*]] = bitcast [[BLOCKTY]]* [[BLOCK]] to i8* 379f4a2713aSLionel Sambuc // CHECK-NEXT: [[X_VAL:%.*]] = load i8** [[X]], align 380f4a2713aSLionel Sambuc // CHECK-NEXT: [[X_TMP:%.*]] = call i8* @objc_retain(i8* [[X_VAL]]) [[NUW]] 381f4a2713aSLionel Sambuc // CHECK-NEXT: [[BLOCK_FN_TMP:%.*]] = load i8** [[BLOCK_FN_PTR]] 382f4a2713aSLionel Sambuc // CHECK-NEXT: [[BLOCK_FN:%.*]] = bitcast i8* [[BLOCK_FN_TMP]] to void (i8*, i8*)* 383f4a2713aSLionel Sambuc // CHECK-NEXT: call void [[BLOCK_FN]](i8* [[BLOCK_OPAQUE]], i8* [[X_TMP]]) 384f4a2713aSLionel Sambuc test13_block(x); 385f4a2713aSLionel Sambuc 386f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] 387f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]] 388f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 389f4a2713aSLionel Sambuc} 390f4a2713aSLionel Sambuc 391f4a2713aSLionel Sambuc@interface Test16_super @end 392f4a2713aSLionel Sambuc@interface Test16 : Test16_super { 393f4a2713aSLionel Sambuc id z; 394f4a2713aSLionel Sambuc} 395f4a2713aSLionel Sambuc@property (assign) int x; 396f4a2713aSLionel Sambuc@property (retain) id y; 397f4a2713aSLionel Sambuc- (void) dealloc; 398f4a2713aSLionel Sambuc@end 399f4a2713aSLionel Sambuc@implementation Test16 400f4a2713aSLionel Sambuc@synthesize x; 401f4a2713aSLionel Sambuc@synthesize y; 402f4a2713aSLionel Sambuc- (void) dealloc { 403f4a2713aSLionel Sambuc // CHECK: define internal void @"\01-[Test16 dealloc]"( 404f4a2713aSLionel Sambuc // CHECK: [[SELF:%.*]] = alloca [[TEST16:%.*]]*, align 405f4a2713aSLionel Sambuc // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align 406f4a2713aSLionel Sambuc // CHECK-NEXT: alloca 407f4a2713aSLionel Sambuc // CHECK-NEXT: store [[TEST16]]* {{%.*}}, [[TEST16]]** [[SELF]], align 408f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] 409f4a2713aSLionel Sambuc // CHECK-NEXT: [[BASE:%.*]] = load [[TEST16]]** [[SELF]] 410f4a2713aSLionel Sambuc 411f4a2713aSLionel Sambuc // Call super. 412f4a2713aSLionel Sambuc // CHECK-NEXT: [[BASE2:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8* 413f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = getelementptr 414f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[BASE2]], i8** [[T0]] 415*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load {{%.*}}** @"OBJC_CLASSLIST_SUP_REFS_$_ 416f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 417f4a2713aSLionel Sambuc // CHECK-NEXT: getelementptr 418f4a2713aSLionel Sambuc // CHECK-NEXT: store 419*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load i8** @OBJC_SELECTOR_REFERENCES_ 420f4a2713aSLionel Sambuc // CHECK-NEXT: call void bitcast (i8* ({{.*}})* @objc_msgSendSuper2 to void ( 421f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 422f4a2713aSLionel Sambuc} 423f4a2713aSLionel Sambuc 424f4a2713aSLionel Sambuc// .cxx_destruct 425f4a2713aSLionel Sambuc // CHECK: define internal void @"\01-[Test16 .cxx_destruct]"( 426f4a2713aSLionel Sambuc // CHECK: [[SELF:%.*]] = alloca [[TEST16:%.*]]*, align 427f4a2713aSLionel Sambuc // CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align 428f4a2713aSLionel Sambuc // CHECK-NEXT: store [[TEST16]]* {{%.*}}, [[TEST16]]** [[SELF]], align 429f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] 430f4a2713aSLionel Sambuc // CHECK-NEXT: [[BASE:%.*]] = load [[TEST16]]** [[SELF]] 431f4a2713aSLionel Sambuc 432f4a2713aSLionel Sambuc // Destroy y. 433f4a2713aSLionel Sambuc // CHECK-NEXT: [[Y_OFF:%.*]] = load i64* @"OBJC_IVAR_$_Test16.y" 434f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8* 435f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[Y_OFF]] 436f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8** 437f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) [[NUW]] 438f4a2713aSLionel Sambuc 439f4a2713aSLionel Sambuc // Destroy z. 440f4a2713aSLionel Sambuc // CHECK-NEXT: [[Z_OFF:%.*]] = load i64* @"OBJC_IVAR_$_Test16.z" 441f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST16]]* [[BASE]] to i8* 442f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[Z_OFF]] 443f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8** 444f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) [[NUW]] 445f4a2713aSLionel Sambuc 446f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 447f4a2713aSLionel Sambuc 448f4a2713aSLionel Sambuc@end 449f4a2713aSLionel Sambuc 450f4a2713aSLionel Sambuc// This shouldn't crash. 451f4a2713aSLionel Sambuc@interface Test17A 452f4a2713aSLionel Sambuc@property (assign) int x; 453f4a2713aSLionel Sambuc@end 454f4a2713aSLionel Sambuc@interface Test17B : Test17A 455f4a2713aSLionel Sambuc@end 456f4a2713aSLionel Sambuc@implementation Test17B 457f4a2713aSLionel Sambuc- (int) x { return super.x + 1; } 458f4a2713aSLionel Sambuc@end 459f4a2713aSLionel Sambuc 460f4a2713aSLionel Sambucvoid test19() { 461f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test19() 462f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca [5 x i8*], align 16 463f4a2713aSLionel Sambuc // CHECK: call void @llvm.lifetime.start 464f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = bitcast [5 x i8*]* [[X]] to i8* 465f4a2713aSLionel Sambuc // CHECK: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 40, i32 16, i1 false) 466f4a2713aSLionel Sambuc id x[5]; 467f4a2713aSLionel Sambuc 468f4a2713aSLionel Sambuc extern id test19_helper(void); 469f4a2713aSLionel Sambuc x[2] = test19_helper(); 470f4a2713aSLionel Sambuc 471f4a2713aSLionel Sambuc // CHECK-NEXT: [[CALL:%.*]] = call i8* @test19_helper() 472f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) [[NUW]] 473f4a2713aSLionel Sambuc // CHECK-NEXT: [[SLOT:%.*]] = getelementptr inbounds [5 x i8*]* [[X]], i32 0, i64 2 474f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i8** [[SLOT]] 475f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T1]], i8** [[SLOT]] 476f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]] 477f4a2713aSLionel Sambuc 478f4a2713aSLionel Sambuc // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [5 x i8*]* [[X]], i32 0, i32 0 479f4a2713aSLionel Sambuc // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 5 480f4a2713aSLionel Sambuc // CHECK-NEXT: br label 481f4a2713aSLionel Sambuc 482f4a2713aSLionel Sambuc // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ] 483f4a2713aSLionel Sambuc // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1 484f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]] 485f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release 486f4a2713aSLionel Sambuc // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]] 487f4a2713aSLionel Sambuc // CHECK-NEXT: br i1 [[EQ]], 488f4a2713aSLionel Sambuc 489f4a2713aSLionel Sambuc // CHECK: ret void 490f4a2713aSLionel Sambuc} 491f4a2713aSLionel Sambuc 492f4a2713aSLionel Sambucvoid test20(unsigned n) { 493f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test20 494f4a2713aSLionel Sambuc // CHECK: [[N:%.*]] = alloca i32, align 4 495f4a2713aSLionel Sambuc // CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca i8* 496f4a2713aSLionel Sambuc // CHECK-NEXT: store i32 {{%.*}}, i32* [[N]], align 4 497f4a2713aSLionel Sambuc 498f4a2713aSLionel Sambuc id x[n]; 499f4a2713aSLionel Sambuc 500f4a2713aSLionel Sambuc // Capture the VLA size. 501f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4 502f4a2713aSLionel Sambuc // CHECK-NEXT: [[DIM:%.*]] = zext i32 [[T0]] to i64 503f4a2713aSLionel Sambuc 504f4a2713aSLionel Sambuc // Save the stack pointer. 505f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = call i8* @llvm.stacksave() 506f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T0]], i8** [[SAVED_STACK]] 507f4a2713aSLionel Sambuc 508f4a2713aSLionel Sambuc // Allocate the VLA. 509f4a2713aSLionel Sambuc // CHECK-NEXT: [[VLA:%.*]] = alloca i8*, i64 [[DIM]], align 16 510f4a2713aSLionel Sambuc 511f4a2713aSLionel Sambuc // Zero-initialize. 512f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = bitcast i8** [[VLA]] to i8* 513f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 [[DIM]], 8 514f4a2713aSLionel Sambuc // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 [[T1]], i32 8, i1 false) 515f4a2713aSLionel Sambuc 516f4a2713aSLionel Sambuc // Destroy. 517f4a2713aSLionel Sambuc // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[VLA]], i64 [[DIM]] 518f4a2713aSLionel Sambuc // CHECK-NEXT: [[EMPTY:%.*]] = icmp eq i8** [[VLA]], [[END]] 519f4a2713aSLionel Sambuc // CHECK-NEXT: br i1 [[EMPTY]] 520f4a2713aSLionel Sambuc 521f4a2713aSLionel Sambuc // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ] 522f4a2713aSLionel Sambuc // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1 523f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]] 524f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release 525f4a2713aSLionel Sambuc // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[VLA]] 526f4a2713aSLionel Sambuc // CHECK-NEXT: br i1 [[EQ]], 527f4a2713aSLionel Sambuc 528f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = load i8** [[SAVED_STACK]] 529f4a2713aSLionel Sambuc // CHECK-NEXT: call void @llvm.stackrestore(i8* [[T0]]) 530f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 531f4a2713aSLionel Sambuc} 532f4a2713aSLionel Sambuc 533f4a2713aSLionel Sambucvoid test21(unsigned n) { 534f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test21 535f4a2713aSLionel Sambuc // CHECK: [[N:%.*]] = alloca i32, align 4 536f4a2713aSLionel Sambuc // CHECK-NEXT: [[SAVED_STACK:%.*]] = alloca i8* 537f4a2713aSLionel Sambuc // CHECK-NEXT: store i32 {{%.*}}, i32* [[N]], align 4 538f4a2713aSLionel Sambuc 539f4a2713aSLionel Sambuc id x[2][n][3]; 540f4a2713aSLionel Sambuc 541f4a2713aSLionel Sambuc // Capture the VLA size. 542f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i32* [[N]], align 4 543f4a2713aSLionel Sambuc // CHECK-NEXT: [[DIM:%.*]] = zext i32 [[T0]] to i64 544f4a2713aSLionel Sambuc 545f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = call i8* @llvm.stacksave() 546f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T0]], i8** [[SAVED_STACK]] 547f4a2713aSLionel Sambuc 548f4a2713aSLionel Sambuc 549f4a2713aSLionel Sambuc // Allocate the VLA. 550f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = mul nuw i64 2, [[DIM]] 551f4a2713aSLionel Sambuc // CHECK-NEXT: [[VLA:%.*]] = alloca [3 x i8*], i64 [[T0]], align 16 552f4a2713aSLionel Sambuc 553f4a2713aSLionel Sambuc // Zero-initialize. 554f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = bitcast [3 x i8*]* [[VLA]] to i8* 555f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 2, [[DIM]] 556f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = mul nuw i64 [[T1]], 24 557f4a2713aSLionel Sambuc // CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 [[T2]], i32 8, i1 false) 558f4a2713aSLionel Sambuc 559f4a2713aSLionel Sambuc // Destroy. 560f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = mul nuw i64 2, [[DIM]] 561f4a2713aSLionel Sambuc // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [3 x i8*]* [[VLA]], i32 0, i32 0 562f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = mul nuw i64 [[T0]], 3 563f4a2713aSLionel Sambuc // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 [[T1]] 564f4a2713aSLionel Sambuc // CHECK-NEXT: [[EMPTY:%.*]] = icmp eq i8** [[BEGIN]], [[END]] 565f4a2713aSLionel Sambuc // CHECK-NEXT: br i1 [[EMPTY]] 566f4a2713aSLionel Sambuc 567f4a2713aSLionel Sambuc // CHECK: [[AFTER:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ] 568f4a2713aSLionel Sambuc // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds i8** [[AFTER]], i64 -1 569f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i8** [[CUR]] 570f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release 571f4a2713aSLionel Sambuc // CHECK-NEXT: [[EQ:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]] 572f4a2713aSLionel Sambuc // CHECK-NEXT: br i1 [[EQ]], 573f4a2713aSLionel Sambuc 574f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = load i8** [[SAVED_STACK]] 575f4a2713aSLionel Sambuc // CHECK-NEXT: call void @llvm.stackrestore(i8* [[T0]]) 576f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 577f4a2713aSLionel Sambuc} 578f4a2713aSLionel Sambuc 579f4a2713aSLionel Sambuc// rdar://problem/8922540 580f4a2713aSLionel Sambuc// Note that we no longer emit .release_ivars flags. 581f4a2713aSLionel Sambuc// rdar://problem/12492434 582f4a2713aSLionel Sambuc// Note that we set the flag saying that we need destruction *and* 583f4a2713aSLionel Sambuc// the flag saying that we don't also need construction. 584*0a6a1f1dSLionel Sambuc// CHECK-GLOBALS: @"\01l_OBJC_CLASS_RO_$_Test23" = private global [[RO_T:%.*]] { i32 390, 585f4a2713aSLionel Sambuc@interface Test23 { id x; } @end 586f4a2713aSLionel Sambuc@implementation Test23 @end 587f4a2713aSLionel Sambuc 588*0a6a1f1dSLionel Sambuc// CHECK-GLOBALS: @"\01l_OBJC_CLASS_RO_$_Test24" = private global [[RO_T:%.*]] { i32 130, 589f4a2713aSLionel Sambuc@interface Test24 {} @end 590f4a2713aSLionel Sambuc@implementation Test24 @end 591f4a2713aSLionel Sambuc 592f4a2713aSLionel Sambuc// rdar://problem/8941012 593f4a2713aSLionel Sambuc@interface Test26 { id x[4]; } @end 594f4a2713aSLionel Sambuc@implementation Test26 @end 595f4a2713aSLionel Sambuc// CHECK: define internal void @"\01-[Test26 .cxx_destruct]"( 596f4a2713aSLionel Sambuc// CHECK: [[SELF:%.*]] = load [[TEST26:%.*]]** 597f4a2713aSLionel Sambuc// CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test26.x" 598f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST26]]* [[SELF]] to i8* 599f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[OFFSET]] 600f4a2713aSLionel Sambuc// CHECK-NEXT: [[X:%.*]] = bitcast i8* [[T1]] to [4 x i8*]* 601f4a2713aSLionel Sambuc// CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [4 x i8*]* [[X]], i32 0, i32 0 602f4a2713aSLionel Sambuc// CHECK-NEXT: [[END:%.*]] = getelementptr inbounds i8** [[BEGIN]], i64 4 603f4a2713aSLionel Sambuc// CHECK-NEXT: br label 604f4a2713aSLionel Sambuc// CHECK: [[PAST:%.*]] = phi i8** [ [[END]], {{%.*}} ], [ [[CUR:%.*]], {{%.*}} ] 605f4a2713aSLionel Sambuc// CHECK-NEXT: [[CUR]] = getelementptr inbounds i8** [[PAST]], i64 -1 606f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_storeStrong(i8** [[CUR]], i8* null) 607f4a2713aSLionel Sambuc// CHECK-NEXT: [[ISDONE:%.*]] = icmp eq i8** [[CUR]], [[BEGIN]] 608f4a2713aSLionel Sambuc// CHECK-NEXT: br i1 [[ISDONE]], 609f4a2713aSLionel Sambuc// CHECK: ret void 610f4a2713aSLionel Sambuc 611f4a2713aSLionel Sambuc// Check that 'init' retains self. 612f4a2713aSLionel Sambuc@interface Test27 613f4a2713aSLionel Sambuc- (id) init; 614f4a2713aSLionel Sambuc@end 615f4a2713aSLionel Sambuc@implementation Test27 616f4a2713aSLionel Sambuc- (id) init { return self; } 617f4a2713aSLionel Sambuc// CHECK: define internal i8* @"\01-[Test27 init]" 618f4a2713aSLionel Sambuc// CHECK: [[SELF:%.*]] = alloca [[TEST27:%.*]]*, 619f4a2713aSLionel Sambuc// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, 620f4a2713aSLionel Sambuc// CHECK-NEXT: [[DEST:%.*]] = alloca i32 621f4a2713aSLionel Sambuc// CHECK-NEXT: store [[TEST27]]* {{%.*}}, [[TEST27]]** [[SELF]] 622f4a2713aSLionel Sambuc// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] 623f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load [[TEST27]]** [[SELF]] 624f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST27]]* [[T0]] to i8* 625f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) 626f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST27]]* 627f4a2713aSLionel Sambuc// CHECK-NEXT: [[RET:%.*]] = bitcast [[TEST27]]* [[T3]] to i8* 628f4a2713aSLionel Sambuc// CHECK-NEXT: store i32 {{[0-9]+}}, i32* [[DEST]] 629f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load [[TEST27]]** [[SELF]] 630f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST27]]* [[T0]] to i8* 631f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_release(i8* [[T1]]) 632f4a2713aSLionel Sambuc// CHECK-NEXT: ret i8* [[RET]] 633f4a2713aSLionel Sambuc 634f4a2713aSLionel Sambuc@end 635f4a2713aSLionel Sambuc 636f4a2713aSLionel Sambuc// rdar://problem/8087194 637f4a2713aSLionel Sambuc@interface Test28 638f4a2713aSLionel Sambuc@property (copy) id prop; 639f4a2713aSLionel Sambuc@end 640f4a2713aSLionel Sambuc@implementation Test28 641f4a2713aSLionel Sambuc@synthesize prop; 642f4a2713aSLionel Sambuc@end 643f4a2713aSLionel Sambuc// CHECK: define internal void @"\01-[Test28 .cxx_destruct]" 644f4a2713aSLionel Sambuc// CHECK: [[SELF:%.*]] = load [[TEST28:%.*]]** 645f4a2713aSLionel Sambuc// CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test28.prop" 646f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST28]]* [[SELF]] to i8* 647f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8* [[T0]], i64 [[OFFSET]] 648f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to i8** 649f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_storeStrong(i8** [[T2]], i8* null) 650f4a2713aSLionel Sambuc// CHECK-NEXT: ret void 651f4a2713aSLionel Sambuc 652f4a2713aSLionel Sambuc@interface Test29_super 653f4a2713aSLionel Sambuc- (id) initWithAllocator: (id) allocator; 654f4a2713aSLionel Sambuc@end 655f4a2713aSLionel Sambuc@interface Test29 : Test29_super 656f4a2713aSLionel Sambuc- (id) init; 657f4a2713aSLionel Sambuc- (id) initWithAllocator: (id) allocator; 658f4a2713aSLionel Sambuc@end 659f4a2713aSLionel Sambuc@implementation Test29 660f4a2713aSLionel Sambucstatic id _test29_allocator = 0; 661f4a2713aSLionel Sambuc- (id) init { 662f4a2713aSLionel Sambuc// CHECK: define internal i8* @"\01-[Test29 init]"([[TEST29:%[^*]*]]* {{%.*}}, 663f4a2713aSLionel Sambuc// CHECK: [[SELF:%.*]] = alloca [[TEST29]]*, align 8 664f4a2713aSLionel Sambuc// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align 8 665f4a2713aSLionel Sambuc// CHECK-NEXT: [[CLEANUP:%.*]] = alloca i32 666f4a2713aSLionel Sambuc// CHECK-NEXT: store [[TEST29]]* {{%.*}}, [[TEST29]]** [[SELF]] 667f4a2713aSLionel Sambuc// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] 668f4a2713aSLionel Sambuc 669f4a2713aSLionel Sambuc// Evaluate arguments. Note that the send argument is evaluated 670f4a2713aSLionel Sambuc// before the zeroing of self. 671f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]], align 8 672f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = load i8** @_test29_allocator, align 8 673f4a2713aSLionel Sambuc 674f4a2713aSLionel Sambuc// Implicit null of 'self', i.e. direct transfer of ownership. 675f4a2713aSLionel Sambuc// CHECK-NEXT: store [[TEST29]]* null, [[TEST29]]** [[SELF]] 676f4a2713aSLionel Sambuc 677f4a2713aSLionel Sambuc// Actual message send. 678*0a6a1f1dSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = load i8** @OBJC_SELECTOR_REFERENCES_ 679f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* 680f4a2713aSLionel Sambuc// CHECK-NEXT: [[CALL:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T3]], i8* [[T2]], i8* [[T1]]) 681f4a2713aSLionel Sambuc 682f4a2713aSLionel Sambuc// Implicit write of result back into 'self'. This is not supposed to 683f4a2713aSLionel Sambuc// be detectable because we're supposed to ban accesses to the old 684f4a2713aSLionel Sambuc// self value past the delegate init call. 685f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]* 686f4a2713aSLionel Sambuc// CHECK-NEXT: store [[TEST29]]* [[T0]], [[TEST29]]** [[SELF]] 687f4a2713aSLionel Sambuc 688f4a2713aSLionel Sambuc// Return statement. 689f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[CALL]] 690f4a2713aSLionel Sambuc// CHECK-NEXT: [[CALL:%.*]] = bitcast 691f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* [[CALL]]) [[NUW]] 692f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[TEST29]]* 693f4a2713aSLionel Sambuc// CHECK-NEXT: [[RET:%.*]] = bitcast [[TEST29]]* [[T1]] to i8* 694f4a2713aSLionel Sambuc// CHECK-NEXT: store i32 1, i32* [[CLEANUP]] 695f4a2713aSLionel Sambuc 696f4a2713aSLionel Sambuc// Cleanup. 697f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]] 698f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* 699f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release 700f4a2713aSLionel Sambuc 701f4a2713aSLionel Sambuc// Return. 702f4a2713aSLionel Sambuc// CHECK-NEXT: ret i8* [[RET]] 703f4a2713aSLionel Sambuc return [self initWithAllocator: _test29_allocator]; 704f4a2713aSLionel Sambuc} 705f4a2713aSLionel Sambuc- (id) initWithAllocator: (id) allocator { 706f4a2713aSLionel Sambuc// CHECK: define internal i8* @"\01-[Test29 initWithAllocator:]"( 707f4a2713aSLionel Sambuc// CHECK: [[SELF:%.*]] = alloca [[TEST29]]*, align 8 708f4a2713aSLionel Sambuc// CHECK-NEXT: [[CMD:%.*]] = alloca i8*, align 8 709f4a2713aSLionel Sambuc// CHECK-NEXT: [[ALLOCATOR:%.*]] = alloca i8*, align 8 710f4a2713aSLionel Sambuc// CHECK-NEXT: alloca 711f4a2713aSLionel Sambuc// CHECK-NEXT: [[CLEANUP:%.*]] = alloca i32 712f4a2713aSLionel Sambuc// CHECK-NEXT: store [[TEST29]]* {{%.*}}, [[TEST29]]** [[SELF]] 713f4a2713aSLionel Sambuc// CHECK-NEXT: store i8* {{%.*}}, i8** [[CMD]] 714f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* {{%.*}}) 715f4a2713aSLionel Sambuc// CHECK-NEXT: store i8* [[T0]], i8** [[ALLOCATOR]] 716f4a2713aSLionel Sambuc 717f4a2713aSLionel Sambuc// Evaluate arguments. Note that the send argument is evaluated 718f4a2713aSLionel Sambuc// before the zeroing of self. 719f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]] 720f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = load i8** [[ALLOCATOR]], align 8 721f4a2713aSLionel Sambuc 722f4a2713aSLionel Sambuc// Implicit null of 'self', i.e. direct transfer of ownership. 723f4a2713aSLionel Sambuc// CHECK-NEXT: store [[TEST29]]* null, [[TEST29]]** [[SELF]] 724f4a2713aSLionel Sambuc 725f4a2713aSLionel Sambuc// Actual message send. 726f4a2713aSLionel Sambuc// CHECK: [[CALL:%.*]] = call {{.*}} @objc_msgSendSuper2 727f4a2713aSLionel Sambuc 728f4a2713aSLionel Sambuc// Implicit write of result back into 'self'. This is not supposed to 729f4a2713aSLionel Sambuc// be detectable because we're supposed to ban accesses to the old 730f4a2713aSLionel Sambuc// self value past the delegate init call. 731f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]* 732f4a2713aSLionel Sambuc// CHECK-NEXT: store [[TEST29]]* [[T0]], [[TEST29]]** [[SELF]] 733f4a2713aSLionel Sambuc 734f4a2713aSLionel Sambuc// Assignment. 735f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[CALL]] to [[TEST29]]* 736f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* 737f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) [[NUW]] 738f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST29]]* 739f4a2713aSLionel Sambuc// CHECK-NEXT: [[T4:%.*]] = load [[TEST29]]** [[SELF]], align 740f4a2713aSLionel Sambuc// CHECK-NEXT: store [[TEST29]]* [[T3]], [[TEST29]]** [[SELF]], align 741f4a2713aSLionel Sambuc// CHECK-NEXT: [[T5:%.*]] = bitcast [[TEST29]]* [[T4]] to i8* 742f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_release(i8* [[T5]]) 743f4a2713aSLionel Sambuc 744f4a2713aSLionel Sambuc// Return statement. 745f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]] 746f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* 747f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* [[T1]]) [[NUW]] 748f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[TEST29]]* 749f4a2713aSLionel Sambuc// CHECK-NEXT: [[RET:%.*]] = bitcast [[TEST29]]* [[T1]] to i8* 750f4a2713aSLionel Sambuc// CHECK-NEXT: store i32 1, i32* [[CLEANUP]] 751f4a2713aSLionel Sambuc 752f4a2713aSLionel Sambuc// Cleanup. 753f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load i8** [[ALLOCATOR]] 754f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]], !clang.imprecise_release 755f4a2713aSLionel Sambuc 756f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load [[TEST29]]** [[SELF]] 757f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST29]]* [[T0]] to i8* 758f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release 759f4a2713aSLionel Sambuc 760f4a2713aSLionel Sambuc// Return. 761f4a2713aSLionel Sambuc// CHECK-NEXT: ret i8* [[RET]] 762f4a2713aSLionel Sambuc self = [super initWithAllocator: allocator]; 763f4a2713aSLionel Sambuc return self; 764f4a2713aSLionel Sambuc} 765f4a2713aSLionel Sambuc@end 766f4a2713aSLionel Sambuc 767f4a2713aSLionel Sambuctypedef struct Test30_helper Test30_helper; 768f4a2713aSLionel Sambuc@interface Test30 769f4a2713aSLionel Sambuc- (id) init; 770f4a2713aSLionel Sambuc- (Test30_helper*) initHelper; 771f4a2713aSLionel Sambuc@end 772f4a2713aSLionel Sambuc@implementation Test30 { 773f4a2713aSLionel Sambucchar *helper; 774f4a2713aSLionel Sambuc} 775f4a2713aSLionel Sambuc- (id) init { 776f4a2713aSLionel Sambuc// CHECK: define internal i8* @"\01-[Test30 init]"([[TEST30:%[^*]*]]* {{%.*}}, 777f4a2713aSLionel Sambuc// CHECK: [[RET:%.*]] = alloca [[TEST30]]* 778f4a2713aSLionel Sambuc// CHECK-NEXT: alloca i8* 779f4a2713aSLionel Sambuc// CHECK-NEXT: alloca i32 780f4a2713aSLionel Sambuc// CHECK-NEXT: store [[TEST30]]* {{%.*}}, [[TEST30]]** [[SELF]] 781f4a2713aSLionel Sambuc// CHECK-NEXT: store 782f4a2713aSLionel Sambuc 783f4a2713aSLionel Sambuc// Call. 784f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]] 785*0a6a1f1dSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = load i8** @OBJC_SELECTOR_REFERENCES_ 786f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST30]]* [[T0]] to i8* 787f4a2713aSLionel Sambuc// CHECK-NEXT: [[CALL:%.*]] = call [[TEST30_HELPER:%.*]]* bitcast {{.*}} @objc_msgSend {{.*}}(i8* [[T2]], i8* [[T1]]) 788f4a2713aSLionel Sambuc 789f4a2713aSLionel Sambuc// Assignment. 790f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST30_HELPER]]* [[CALL]] to i8* 791f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = load [[TEST30]]** [[SELF]] 792f4a2713aSLionel Sambuc// CHECK-NEXT: [[IVAR:%.*]] = load i64* @"OBJC_IVAR_$_Test30.helper" 793f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST30]]* [[T1]] to i8* 794f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[IVAR]] 795f4a2713aSLionel Sambuc// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8** 796f4a2713aSLionel Sambuc// CHECK-NEXT#: [[T5:%.*]] = load i8** [[T4]] 797f4a2713aSLionel Sambuc// CHECK-NEXT#: [[T6:%.*]] = call i8* @objc_retain(i8* [[T0]]) 798f4a2713aSLionel Sambuc// CHECK-NEXT#: call void @objc_release(i8* [[T5]]) 799f4a2713aSLionel Sambuc// CHECK-NEXT: store i8* [[T0]], i8** [[T4]] 800f4a2713aSLionel Sambuc 801f4a2713aSLionel Sambuc// Return. 802f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]] 803f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST30]]* [[T0]] to i8* 804f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* [[T1]]) 805f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[TEST30]]* 806f4a2713aSLionel Sambuc// CHECK-NEXT: [[RET:%.*]] = bitcast [[TEST30]]* [[T1]] to i8* 807f4a2713aSLionel Sambuc// CHECK-NEXT: store i32 1 808f4a2713aSLionel Sambuc 809f4a2713aSLionel Sambuc// Cleanup. 810f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load [[TEST30]]** [[SELF]] 811f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST30]]* [[T0]] to i8* 812f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_release(i8* [[T1]]) 813f4a2713aSLionel Sambuc 814f4a2713aSLionel Sambuc// Epilogue. 815f4a2713aSLionel Sambuc// CHECK-NEXT: ret i8* [[RET]] 816f4a2713aSLionel Sambuc self->helper = [self initHelper]; 817f4a2713aSLionel Sambuc return self; 818f4a2713aSLionel Sambuc} 819f4a2713aSLionel Sambuc- (Test30_helper*) initHelper { 820f4a2713aSLionel Sambuc// CHECK: define internal [[TEST30_HELPER]]* @"\01-[Test30 initHelper]"( 821f4a2713aSLionel Sambuc// CHECK: alloca 822f4a2713aSLionel Sambuc// CHECK-NEXT: alloca 823f4a2713aSLionel Sambuc// CHECK-NEXT: store 824f4a2713aSLionel Sambuc// CHECK-NEXT: store 825f4a2713aSLionel Sambuc// CHECK-NEXT: ret [[TEST30_HELPER]]* null 826f4a2713aSLionel Sambuc return 0; 827f4a2713aSLionel Sambuc} 828f4a2713aSLionel Sambuc 829f4a2713aSLionel Sambuc@end 830f4a2713aSLionel Sambuc 831f4a2713aSLionel Sambuc__attribute__((ns_returns_retained)) id test32(void) { 832f4a2713aSLionel Sambuc// CHECK-LABEL: define i8* @test32() 833f4a2713aSLionel Sambuc// CHECK: [[CALL:%.*]] = call i8* @test32_helper() 834f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) 835f4a2713aSLionel Sambuc// CHECK-NEXT: ret i8* [[T0]] 836f4a2713aSLionel Sambuc extern id test32_helper(void); 837f4a2713aSLionel Sambuc return test32_helper(); 838f4a2713aSLionel Sambuc} 839f4a2713aSLionel Sambuc 840f4a2713aSLionel Sambuc@class Test33_a; 841f4a2713aSLionel Sambuc@interface Test33 842f4a2713aSLionel Sambuc- (void) give: (Test33_a **) x; 843f4a2713aSLionel Sambuc- (void) take: (Test33_a **) x; 844f4a2713aSLionel Sambuc- (void) giveStrong: (out __strong Test33_a **) x; 845f4a2713aSLionel Sambuc- (void) takeStrong: (inout __strong Test33_a **) x; 846f4a2713aSLionel Sambuc- (void) giveOut: (out Test33_a **) x; 847f4a2713aSLionel Sambuc@end 848f4a2713aSLionel Sambucvoid test33(Test33 *ptr) { 849f4a2713aSLionel Sambuc Test33_a *a; 850f4a2713aSLionel Sambuc [ptr give: &a]; 851f4a2713aSLionel Sambuc [ptr take: &a]; 852f4a2713aSLionel Sambuc [ptr giveStrong: &a]; 853f4a2713aSLionel Sambuc [ptr takeStrong: &a]; 854f4a2713aSLionel Sambuc [ptr giveOut: &a]; 855f4a2713aSLionel Sambuc 856f4a2713aSLionel Sambuc // CHECK: define void @test33([[TEST33:%.*]]* 857f4a2713aSLionel Sambuc // CHECK: [[PTR:%.*]] = alloca [[TEST33]]* 858f4a2713aSLionel Sambuc // CHECK-NEXT: [[A:%.*]] = alloca [[A_T:%.*]]* 859f4a2713aSLionel Sambuc // CHECK-NEXT: [[TEMP0:%.*]] = alloca [[A_T]]* 860f4a2713aSLionel Sambuc // CHECK-NEXT: [[TEMP1:%.*]] = alloca [[A_T]]* 861f4a2713aSLionel Sambuc // CHECK-NEXT: [[TEMP2:%.*]] = alloca [[A_T]]* 862f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 863f4a2713aSLionel Sambuc // CHECK-NEXT: objc_retain 864f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 865f4a2713aSLionel Sambuc // CHECK-NEXT: store 866f4a2713aSLionel Sambuc // CHECK-NEXT: store [[A_T]]* null, [[A_T]]** [[A]] 867f4a2713aSLionel Sambuc 868f4a2713aSLionel Sambuc // CHECK-NEXT: load [[TEST33]]** [[PTR]] 869f4a2713aSLionel Sambuc // CHECK-NEXT: [[W0:%.*]] = load [[A_T]]** [[A]] 870f4a2713aSLionel Sambuc // CHECK-NEXT: store [[A_T]]* [[W0]], [[A_T]]** [[TEMP0]] 871*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load i8** @OBJC_SELECTOR_REFERENCES_ 872f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 873f4a2713aSLionel Sambuc // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP0]]) 874f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP0]] 875f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8* 876f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) 877f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]* 878f4a2713aSLionel Sambuc // CHECK-NEXT: call void (...)* @clang.arc.use([[A_T]]* [[W0]]) [[NUW]] 879f4a2713aSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]] 880f4a2713aSLionel Sambuc // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]] 881f4a2713aSLionel Sambuc // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8* 882f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T5]]) 883f4a2713aSLionel Sambuc 884f4a2713aSLionel Sambuc // CHECK-NEXT: load [[TEST33]]** [[PTR]] 885f4a2713aSLionel Sambuc // CHECK-NEXT: [[W0:%.*]] = load [[A_T]]** [[A]] 886f4a2713aSLionel Sambuc // CHECK-NEXT: store [[A_T]]* [[W0]], [[A_T]]** [[TEMP1]] 887*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load i8** @OBJC_SELECTOR_REFERENCES_ 888f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 889f4a2713aSLionel Sambuc // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP1]]) 890f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP1]] 891f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8* 892f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) 893f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]* 894f4a2713aSLionel Sambuc // CHECK-NEXT: call void (...)* @clang.arc.use([[A_T]]* [[W0]]) [[NUW]] 895f4a2713aSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]] 896f4a2713aSLionel Sambuc // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]] 897f4a2713aSLionel Sambuc // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8* 898f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T5]]) 899f4a2713aSLionel Sambuc 900f4a2713aSLionel Sambuc // CHECK-NEXT: load [[TEST33]]** [[PTR]] 901*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load i8** @OBJC_SELECTOR_REFERENCES_ 902f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 903f4a2713aSLionel Sambuc // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[A]]) 904f4a2713aSLionel Sambuc 905f4a2713aSLionel Sambuc // CHECK-NEXT: load [[TEST33]]** [[PTR]] 906*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load i8** @OBJC_SELECTOR_REFERENCES_ 907f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 908f4a2713aSLionel Sambuc // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[A]]) 909f4a2713aSLionel Sambuc 910f4a2713aSLionel Sambuc // 'out' 911f4a2713aSLionel Sambuc // CHECK-NEXT: load [[TEST33]]** [[PTR]] 912f4a2713aSLionel Sambuc // CHECK-NEXT: store [[A_T]]* null, [[A_T]]** [[TEMP2]] 913*0a6a1f1dSLionel Sambuc // CHECK-NEXT: load i8** @OBJC_SELECTOR_REFERENCES_ 914f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 915f4a2713aSLionel Sambuc // CHECK-NEXT: objc_msgSend{{.*}}, [[A_T]]** [[TEMP2]]) 916f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[A_T]]** [[TEMP2]] 917f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[A_T]]* [[T0]] to i8* 918f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T1]]) 919f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A_T]]* 920f4a2713aSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = load [[A_T]]** [[A]] 921f4a2713aSLionel Sambuc // CHECK-NEXT: store [[A_T]]* [[T3]], [[A_T]]** [[A]] 922f4a2713aSLionel Sambuc // CHECK-NEXT: [[T5:%.*]] = bitcast [[A_T]]* [[T4]] to i8* 923f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T5]]) 924f4a2713aSLionel Sambuc 925f4a2713aSLionel Sambuc // CHECK-NEXT: load 926f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 927f4a2713aSLionel Sambuc // CHECK-NEXT: objc_release 928f4a2713aSLionel Sambuc // CHECK-NEXT: load 929f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast 930f4a2713aSLionel Sambuc // CHECK-NEXT: objc_release 931f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 932f4a2713aSLionel Sambuc} 933f4a2713aSLionel Sambuc 934f4a2713aSLionel Sambuc 935f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test36 936f4a2713aSLionel Sambucvoid test36(id x) { 937f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i8* 938f4a2713aSLionel Sambuc 939f4a2713aSLionel Sambuc // CHECK: call i8* @objc_retain 940f4a2713aSLionel Sambuc // CHECK: call i8* @objc_retain 941f4a2713aSLionel Sambuc // CHECK: call i8* @objc_retain 942f4a2713aSLionel Sambuc id array[3] = { @"A", x, @"y" }; 943f4a2713aSLionel Sambuc 944f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = load i8** [[X]] 945f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* null, i8** [[X]] 946f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T0]]) 947f4a2713aSLionel Sambuc x = 0; 948f4a2713aSLionel Sambuc 949f4a2713aSLionel Sambuc // CHECK: br label 950f4a2713aSLionel Sambuc // CHECK: call void @objc_release 951f4a2713aSLionel Sambuc // CHECK: br i1 952f4a2713aSLionel Sambuc 953f4a2713aSLionel Sambuc // CHECK: call void @objc_release 954f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 955f4a2713aSLionel Sambuc} 956f4a2713aSLionel Sambuc 957f4a2713aSLionel Sambuc@class Test37; 958f4a2713aSLionel Sambucvoid test37(void) { 959f4a2713aSLionel Sambuc extern void test37_helper(id *); 960f4a2713aSLionel Sambuc Test37 *var; 961f4a2713aSLionel Sambuc test37_helper(&var); 962f4a2713aSLionel Sambuc 963f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test37() 964f4a2713aSLionel Sambuc // CHECK: [[VAR:%.*]] = alloca [[TEST37:%.*]]*, 965f4a2713aSLionel Sambuc // CHECK-NEXT: [[TEMP:%.*]] = alloca i8* 966f4a2713aSLionel Sambuc // CHECK-NEXT: store [[TEST37]]* null, [[TEST37]]** [[VAR]] 967f4a2713aSLionel Sambuc 968f4a2713aSLionel Sambuc // CHECK-NEXT: [[W0:%.*]] = load [[TEST37]]** [[VAR]] 969f4a2713aSLionel Sambuc // CHECK-NEXT: [[W1:%.*]] = bitcast [[TEST37]]* [[W0]] to i8* 970f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[W1]], i8** [[TEMP]] 971f4a2713aSLionel Sambuc // CHECK-NEXT: call void @test37_helper(i8** [[TEMP]]) 972f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i8** [[TEMP]] 973f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[TEST37]]* 974f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST37]]* [[T1]] to i8* 975f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retain(i8* [[T2]]) 976f4a2713aSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to [[TEST37]]* 977f4a2713aSLionel Sambuc // CHECK-NEXT: call void (...)* @clang.arc.use(i8* [[W1]]) [[NUW]] 978f4a2713aSLionel Sambuc // CHECK-NEXT: [[T5:%.*]] = load [[TEST37]]** [[VAR]] 979f4a2713aSLionel Sambuc // CHECK-NEXT: store [[TEST37]]* [[T4]], [[TEST37]]** [[VAR]] 980f4a2713aSLionel Sambuc // CHECK-NEXT: [[T6:%.*]] = bitcast [[TEST37]]* [[T5]] to i8* 981f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T6]]) 982f4a2713aSLionel Sambuc 983f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[TEST37]]** [[VAR]] 984f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST37]]* [[T0]] to i8* 985f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) 986f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 987f4a2713aSLionel Sambuc} 988f4a2713aSLionel Sambuc 989f4a2713aSLionel Sambuc@interface Test43 @end 990f4a2713aSLionel Sambuc@implementation Test43 991f4a2713aSLionel Sambuc- (id) test __attribute__((ns_returns_retained)) { 992f4a2713aSLionel Sambuc extern id test43_produce(void); 993f4a2713aSLionel Sambuc return test43_produce(); 994f4a2713aSLionel Sambuc // CHECK: call i8* @test43_produce() 995f4a2713aSLionel Sambuc // CHECK-NEXT: call i8* @objc_retainAutoreleasedReturnValue( 996f4a2713aSLionel Sambuc // CHECK-NEXT: ret 997f4a2713aSLionel Sambuc} 998f4a2713aSLionel Sambuc@end 999f4a2713aSLionel Sambuc 1000f4a2713aSLionel Sambuc@interface Test45 1001f4a2713aSLionel Sambuc@property (retain) id x; 1002f4a2713aSLionel Sambuc@end 1003f4a2713aSLionel Sambuc@implementation Test45 1004f4a2713aSLionel Sambuc@synthesize x; 1005f4a2713aSLionel Sambuc@end 1006f4a2713aSLionel Sambuc// CHECK: define internal i8* @"\01-[Test45 x]"( 1007*0a6a1f1dSLionel Sambuc// CHECK: [[CALL:%.*]] = tail call i8* @objc_getProperty( 1008f4a2713aSLionel Sambuc// CHECK-NEXT: ret i8* [[CALL]] 1009f4a2713aSLionel Sambuc 1010f4a2713aSLionel Sambuc// rdar://problem/9315552 1011f4a2713aSLionel Sambucvoid test46(__weak id *wp, __weak volatile id *wvp) { 1012f4a2713aSLionel Sambuc extern id test46_helper(void); 1013f4a2713aSLionel Sambuc 1014f4a2713aSLionel Sambuc // TODO: this is sub-optimal, we should retain at the actual call site. 1015f4a2713aSLionel Sambuc 1016f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = call i8* @test46_helper() 1017f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) 1018f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = load i8*** {{%.*}}, align 8 1019f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]]) 1020f4a2713aSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retain(i8* [[T3]]) 1021f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T4]], i8** 1022f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) 1023f4a2713aSLionel Sambuc id x = *wp = test46_helper(); 1024f4a2713aSLionel Sambuc 1025f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = call i8* @test46_helper() 1026f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) 1027f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = load i8*** {{%.*}}, align 8 1028f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[T2]], i8* [[T1]]) 1029f4a2713aSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_retain(i8* [[T3]]) 1030f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T4]], i8** 1031f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) 1032f4a2713aSLionel Sambuc id y = *wvp = test46_helper(); 1033f4a2713aSLionel Sambuc} 1034f4a2713aSLionel Sambuc 1035f4a2713aSLionel Sambuc// rdar://problem/9378887 1036f4a2713aSLionel Sambucvoid test47(void) { 1037f4a2713aSLionel Sambuc extern id test47_helper(void); 1038f4a2713aSLionel Sambuc id x = x = test47_helper(); 1039f4a2713aSLionel Sambuc 1040f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test47() 1041f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i8* 1042f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* null, i8** [[X]] 1043f4a2713aSLionel Sambuc // CHECK-NEXT: [[CALL:%.*]] = call i8* @test47_helper() 1044f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) 1045f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] 1046f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T0]], i8** [[X]] 1047f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) 1048f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retain(i8* [[T0]]) 1049f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = load i8** [[X]] 1050f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T2]], i8** [[X]] 1051f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T3]]) 1052f4a2713aSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = load i8** [[X]] 1053f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T4]]) 1054f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 1055f4a2713aSLionel Sambuc} 1056f4a2713aSLionel Sambuc 1057f4a2713aSLionel Sambucvoid test48(void) { 1058f4a2713aSLionel Sambuc extern id test48_helper(void); 1059f4a2713aSLionel Sambuc __weak id x = x = test48_helper(); 1060f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test48() 1061f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i8* 1062f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_initWeak(i8** [[X]], i8* null) 1063f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = call i8* @test48_helper() 1064f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) 1065f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_storeWeak(i8** [[X]], i8* [[T2]]) 1066f4a2713aSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = call i8* @objc_storeWeak(i8** [[X]], i8* [[T3]]) 1067f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T2]]) 1068f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]]) 1069f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 1070f4a2713aSLionel Sambuc} 1071f4a2713aSLionel Sambuc 1072f4a2713aSLionel Sambucvoid test49(void) { 1073f4a2713aSLionel Sambuc extern id test49_helper(void); 1074f4a2713aSLionel Sambuc __autoreleasing id x = x = test49_helper(); 1075f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test49() 1076f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i8* 1077f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* null, i8** [[X]] 1078f4a2713aSLionel Sambuc // CHECK-NEXT: [[CALL:%.*]] = call i8* @test49_helper() 1079f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[CALL]]) 1080f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_autorelease(i8* [[T0]]) 1081f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T2]], i8** [[X]] 1082f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retainAutorelease(i8* [[T1]]) 1083f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T3]], i8** [[X]] 1084f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 1085f4a2713aSLionel Sambuc} 1086f4a2713aSLionel Sambuc 1087f4a2713aSLionel Sambuc// rdar://9380136 1088f4a2713aSLionel Sambucid x(); 1089f4a2713aSLionel Sambucvoid test50(id y) { 1090f4a2713aSLionel Sambuc ({x();}); 1091f4a2713aSLionel Sambuc// CHECK: [[T0:%.*]] = call i8* @objc_retain 1092f4a2713aSLionel Sambuc// CHECK: call void @objc_release 1093f4a2713aSLionel Sambuc} 1094f4a2713aSLionel Sambuc 1095f4a2713aSLionel Sambuc 1096f4a2713aSLionel Sambuc// rdar://9400762 1097f4a2713aSLionel Sambucstruct CGPoint { 1098f4a2713aSLionel Sambuc float x; 1099f4a2713aSLionel Sambuc float y; 1100f4a2713aSLionel Sambuc}; 1101f4a2713aSLionel Sambuctypedef struct CGPoint CGPoint; 1102f4a2713aSLionel Sambuc 1103f4a2713aSLionel Sambuc@interface Foo 1104f4a2713aSLionel Sambuc@property (assign) CGPoint point; 1105f4a2713aSLionel Sambuc@end 1106f4a2713aSLionel Sambuc 1107f4a2713aSLionel Sambuc@implementation Foo 1108f4a2713aSLionel Sambuc@synthesize point; 1109f4a2713aSLionel Sambuc@end 1110f4a2713aSLionel Sambuc 1111f4a2713aSLionel Sambuc// rdar://problem/9400398 1112f4a2713aSLionel Sambucid test52(void) { 1113f4a2713aSLionel Sambuc id test52_helper(int) __attribute__((ns_returns_retained)); 1114f4a2713aSLionel Sambuc return ({ int x = 5; test52_helper(x); }); 1115f4a2713aSLionel Sambuc 1116f4a2713aSLionel Sambuc// CHECK-LABEL: define i8* @test52() 1117f4a2713aSLionel Sambuc// CHECK: [[X:%.*]] = alloca i32 1118f4a2713aSLionel Sambuc// CHECK-NEXT: [[TMPALLOCA:%.*]] = alloca i8* 1119f4a2713aSLionel Sambuc// CHECK-NEXT: store i32 5, i32* [[X]], 1120f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load i32* [[X]], 1121f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = call i8* @test52_helper(i32 [[T0]]) 1122f4a2713aSLionel Sambuc// CHECK-NEXT: store i8* [[T1]], i8** [[TMPALLOCA]] 1123f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = load i8** [[TMPALLOCA]] 1124f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* [[T2]]) 1125f4a2713aSLionel Sambuc// CHECK-NEXT: ret i8* [[T3]] 1126f4a2713aSLionel Sambuc} 1127f4a2713aSLionel Sambuc 1128f4a2713aSLionel Sambuc// rdar://problem/9400644 1129f4a2713aSLionel Sambucvoid test53(void) { 1130f4a2713aSLionel Sambuc id test53_helper(void); 1131f4a2713aSLionel Sambuc id x = ({ id y = test53_helper(); y; }); 1132f4a2713aSLionel Sambuc (void) x; 1133f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test53() 1134f4a2713aSLionel Sambuc// CHECK: [[X:%.*]] = alloca i8*, 1135f4a2713aSLionel Sambuc// CHECK-NEXT: [[Y:%.*]] = alloca i8*, 1136f4a2713aSLionel Sambuc// CHECK-NEXT: [[TMPALLOCA:%.*]] = alloca i8*, 1137f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = call i8* @test53_helper() 1138f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) 1139f4a2713aSLionel Sambuc// CHECK-NEXT: store i8* [[T1]], i8** [[Y]], 1140f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]], 1141f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) 1142f4a2713aSLionel Sambuc// CHECK-NEXT: store i8* [[T1]], i8** [[TMPALLOCA]] 1143f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = load i8** [[Y]] 1144f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_release(i8* [[T2]]) 1145f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = load i8** [[TMPALLOCA]] 1146f4a2713aSLionel Sambuc// CHECK-NEXT: store i8* [[T3]], i8** [[X]], 1147f4a2713aSLionel Sambuc// CHECK-NEXT: load i8** [[X]], 1148f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] 1149f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_release(i8* [[T0]]) 1150f4a2713aSLionel Sambuc// CHECK-NEXT: ret void 1151f4a2713aSLionel Sambuc} 1152f4a2713aSLionel Sambuc 1153f4a2713aSLionel Sambuc// <rdar://problem/9758798> 1154f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test54(i32 %first, ...) 1155f4a2713aSLionel Sambucvoid test54(int first, ...) { 1156f4a2713aSLionel Sambuc __builtin_va_list arglist; 1157f4a2713aSLionel Sambuc // CHECK: call void @llvm.va_start 1158f4a2713aSLionel Sambuc __builtin_va_start(arglist, first); 1159f4a2713aSLionel Sambuc // CHECK: call i8* @objc_retain 1160f4a2713aSLionel Sambuc id obj = __builtin_va_arg(arglist, id); 1161f4a2713aSLionel Sambuc // CHECK: call void @llvm.va_end 1162f4a2713aSLionel Sambuc __builtin_va_end(arglist); 1163f4a2713aSLionel Sambuc // CHECK: call void @objc_release 1164f4a2713aSLionel Sambuc // CHECK: ret void 1165f4a2713aSLionel Sambuc} 1166f4a2713aSLionel Sambuc 1167f4a2713aSLionel Sambuc// PR10228 1168f4a2713aSLionel Sambuc@interface Test55Base @end 1169f4a2713aSLionel Sambuc@interface Test55 : Test55Base @end 1170f4a2713aSLionel Sambuc@implementation Test55 (Category) 1171f4a2713aSLionel Sambuc- (void) dealloc {} 1172f4a2713aSLionel Sambuc@end 1173f4a2713aSLionel Sambuc// CHECK: define internal void @"\01-[Test55(Category) dealloc]"( 1174f4a2713aSLionel Sambuc// CHECK-NOT: ret 1175f4a2713aSLionel Sambuc// CHECK: call void bitcast (i8* ({{%.*}}*, i8*, ...)* @objc_msgSendSuper2 to void ({{%.*}}*, i8*)*)( 1176f4a2713aSLionel Sambuc 1177f4a2713aSLionel Sambuc// rdar://problem/8024350 1178f4a2713aSLionel Sambuc@protocol Test56Protocol 1179f4a2713aSLionel Sambuc+ (id) make __attribute__((ns_returns_retained)); 1180f4a2713aSLionel Sambuc@end 1181f4a2713aSLionel Sambuc@interface Test56<Test56Protocol> @end 1182f4a2713aSLionel Sambuc@implementation Test56 1183f4a2713aSLionel Sambuc// CHECK: define internal i8* @"\01+[Test56 make]"( 1184f4a2713aSLionel Sambuc+ (id) make { 1185f4a2713aSLionel Sambuc extern id test56_helper(void); 1186f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = call i8* @test56_helper() 1187f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) 1188f4a2713aSLionel Sambuc // CHECK-NEXT: ret i8* [[T1]] 1189f4a2713aSLionel Sambuc return test56_helper(); 1190f4a2713aSLionel Sambuc} 1191f4a2713aSLionel Sambuc@end 1192f4a2713aSLionel Sambucvoid test56_test(void) { 1193f4a2713aSLionel Sambuc id x = [Test56 make]; 1194f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test56_test() 1195f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i8*, align 8 1196f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*)*)( 1197f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T0]], i8** [[X]] 1198f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] 1199f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T0]]) 1200f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 1201f4a2713aSLionel Sambuc} 1202f4a2713aSLionel Sambuc 1203f4a2713aSLionel Sambuc// rdar://problem/9784964 1204f4a2713aSLionel Sambuc@interface Test57 1205f4a2713aSLionel Sambuc@property (nonatomic, strong) id strong; 1206f4a2713aSLionel Sambuc@property (nonatomic, weak) id weak; 1207f4a2713aSLionel Sambuc@property (nonatomic, unsafe_unretained) id unsafe; 1208f4a2713aSLionel Sambuc@end 1209f4a2713aSLionel Sambuc@implementation Test57 1210f4a2713aSLionel Sambuc@synthesize strong, weak, unsafe; 1211f4a2713aSLionel Sambuc@end 1212f4a2713aSLionel Sambuc// CHECK: define internal i8* @"\01-[Test57 strong]"( 1213f4a2713aSLionel Sambuc// CHECK: [[T0:%.*]] = load [[TEST57:%.*]]** {{%.*}} 1214f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_Test57.strong" 1215f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST57]]* [[T0]] to i8* 1216f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]] 1217f4a2713aSLionel Sambuc// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8** 1218f4a2713aSLionel Sambuc// CHECK-NEXT: [[T5:%.*]] = load i8** [[T4]] 1219f4a2713aSLionel Sambuc// CHECK-NEXT: ret i8* [[T5]] 1220f4a2713aSLionel Sambuc 1221f4a2713aSLionel Sambuc// CHECK: define internal i8* @"\01-[Test57 weak]"( 1222f4a2713aSLionel Sambuc// CHECK: [[T0:%.*]] = load [[TEST57]]** {{%.*}} 1223f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_Test57.weak" 1224f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST57]]* [[T0]] to i8* 1225f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]] 1226f4a2713aSLionel Sambuc// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8** 1227f4a2713aSLionel Sambuc// CHECK-NEXT: [[T5:%.*]] = call i8* @objc_loadWeakRetained(i8** [[T4]]) 1228f4a2713aSLionel Sambuc// CHECK-NEXT: [[T6:%.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* [[T5]]) 1229f4a2713aSLionel Sambuc// CHECK-NEXT: ret i8* [[T6]] 1230f4a2713aSLionel Sambuc 1231f4a2713aSLionel Sambuc// CHECK: define internal i8* @"\01-[Test57 unsafe]"( 1232f4a2713aSLionel Sambuc// CHECK: [[T0:%.*]] = load [[TEST57]]** {{%.*}} 1233f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_Test57.unsafe" 1234f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST57]]* [[T0]] to i8* 1235f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = getelementptr inbounds i8* [[T2]], i64 [[T1]] 1236f4a2713aSLionel Sambuc// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to i8** 1237f4a2713aSLionel Sambuc// CHECK-NEXT: [[T5:%.*]] = load i8** [[T4]] 1238f4a2713aSLionel Sambuc// CHECK-NEXT: ret i8* [[T5]] 1239f4a2713aSLionel Sambuc 1240f4a2713aSLionel Sambuc// rdar://problem/9842343 1241f4a2713aSLionel Sambucvoid test59(void) { 1242f4a2713aSLionel Sambuc extern id test59_getlock(void); 1243f4a2713aSLionel Sambuc extern void test59_body(void); 1244f4a2713aSLionel Sambuc @synchronized (test59_getlock()) { 1245f4a2713aSLionel Sambuc test59_body(); 1246f4a2713aSLionel Sambuc } 1247f4a2713aSLionel Sambuc 1248f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test59() 1249f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = call i8* @test59_getlock() 1250f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) 1251f4a2713aSLionel Sambuc // CHECK-NEXT: call i32 @objc_sync_enter(i8* [[T1]]) 1252f4a2713aSLionel Sambuc // CHECK-NEXT: call void @test59_body() 1253f4a2713aSLionel Sambuc // CHECK-NEXT: call i32 @objc_sync_exit(i8* [[T1]]) 1254f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) 1255f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 1256f4a2713aSLionel Sambuc} 1257f4a2713aSLionel Sambuc 1258f4a2713aSLionel Sambuc// Verify that we don't try to reclaim the result of performSelector. 1259f4a2713aSLionel Sambuc// rdar://problem/9887545 1260f4a2713aSLionel Sambuc@interface Test61 1261f4a2713aSLionel Sambuc- (id) performSelector: (SEL) selector; 1262f4a2713aSLionel Sambuc- (void) test61_void; 1263f4a2713aSLionel Sambuc- (id) test61_id; 1264f4a2713aSLionel Sambuc@end 1265f4a2713aSLionel Sambucvoid test61(void) { 1266f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test61() 1267f4a2713aSLionel Sambuc // CHECK: [[Y:%.*]] = alloca i8*, align 8 1268f4a2713aSLionel Sambuc 1269f4a2713aSLionel Sambuc extern id test61_make(void); 1270f4a2713aSLionel Sambuc 1271f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = call i8* @test61_make() 1272f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) 1273*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = load i8** @OBJC_SELECTOR_REFERENCES_ 1274*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = load i8** @OBJC_SELECTOR_REFERENCES_ 1275f4a2713aSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T1]], i8* [[T3]], i8* [[T2]]) 1276f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) 1277f4a2713aSLionel Sambuc [test61_make() performSelector: @selector(test61_void)]; 1278f4a2713aSLionel Sambuc 1279f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = call i8* @test61_make() 1280f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) 1281*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = load i8** @OBJC_SELECTOR_REFERENCES_ 1282*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = load i8** @OBJC_SELECTOR_REFERENCES_ 1283f4a2713aSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*, i8*)*)(i8* [[T1]], i8* [[T3]], i8* [[T2]]) 1284f4a2713aSLionel Sambuc // CHECK-NEXT: [[T5:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T4]]) 1285f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T5]], i8** [[Y]] 1286f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) 1287f4a2713aSLionel Sambuc id y = [test61_make() performSelector: @selector(test61_id)]; 1288f4a2713aSLionel Sambuc 1289f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i8** [[Y]] 1290f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T0]]) 1291f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 1292f4a2713aSLionel Sambuc} 1293f4a2713aSLionel Sambuc 1294f4a2713aSLionel Sambuc// rdar://problem/9891815 1295f4a2713aSLionel Sambucvoid test62(void) { 1296f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test62() 1297f4a2713aSLionel Sambuc // CHECK: [[I:%.*]] = alloca i32, align 4 1298f4a2713aSLionel Sambuc // CHECK-NEXT: [[CLEANUP_VALUE:%.*]] = alloca i8* 1299f4a2713aSLionel Sambuc // CHECK-NEXT: [[CLEANUP_REQUIRED:%.*]] = alloca i1 1300f4a2713aSLionel Sambuc extern id test62_make(void); 1301f4a2713aSLionel Sambuc extern void test62_body(void); 1302f4a2713aSLionel Sambuc 1303f4a2713aSLionel Sambuc // CHECK-NEXT: store i32 0, i32* [[I]], align 4 1304f4a2713aSLionel Sambuc // CHECK-NEXT: br label 1305f4a2713aSLionel Sambuc 1306f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = load i32* [[I]], align 4 1307f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 20 1308f4a2713aSLionel Sambuc // CHECK-NEXT: br i1 [[T1]], 1309f4a2713aSLionel Sambuc 1310f4a2713aSLionel Sambuc for (unsigned i = 0; i != 20; ++i) { 1311f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = load i32* [[I]], align 4 1312f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = icmp ne i32 [[T0]], 0 1313f4a2713aSLionel Sambuc // CHECK-NEXT: store i1 false, i1* [[CLEANUP_REQUIRED]] 1314f4a2713aSLionel Sambuc // CHECK-NEXT: br i1 [[T1]], 1315f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = call i8* @test62_make() 1316f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) 1317f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T1]], i8** [[CLEANUP_VALUE]] 1318f4a2713aSLionel Sambuc // CHECK-NEXT: store i1 true, i1* [[CLEANUP_REQUIRED]] 1319f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = icmp ne i8* [[T1]], null 1320f4a2713aSLionel Sambuc // CHECK-NEXT: br label 1321f4a2713aSLionel Sambuc // CHECK: [[COND:%.*]] = phi i1 [ false, {{%.*}} ], [ [[T2]], {{%.*}} ] 1322f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i1* [[CLEANUP_REQUIRED]] 1323f4a2713aSLionel Sambuc // CHECK-NEXT: br i1 [[T0]], 1324f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = load i8** [[CLEANUP_VALUE]] 1325f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T0]]) 1326f4a2713aSLionel Sambuc // CHECK-NEXT: br label 1327f4a2713aSLionel Sambuc // CHECK: br i1 [[COND]] 1328f4a2713aSLionel Sambuc // CHECK: call void @test62_body() 1329f4a2713aSLionel Sambuc // CHECK-NEXT: br label 1330f4a2713aSLionel Sambuc // CHECK: br label 1331f4a2713aSLionel Sambuc if (i != 0 && test62_make() != 0) 1332f4a2713aSLionel Sambuc test62_body(); 1333f4a2713aSLionel Sambuc } 1334f4a2713aSLionel Sambuc 1335f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = load i32* [[I]], align 4 1336f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = add i32 [[T0]], 1 1337f4a2713aSLionel Sambuc // CHECK-NEXT: store i32 [[T1]], i32* [[I]] 1338f4a2713aSLionel Sambuc // CHECK-NEXT: br label 1339f4a2713aSLionel Sambuc 1340f4a2713aSLionel Sambuc // CHECK: ret void 1341f4a2713aSLionel Sambuc} 1342f4a2713aSLionel Sambuc 1343f4a2713aSLionel Sambuc// rdar://9971982 1344f4a2713aSLionel Sambuc@class NSString; 1345f4a2713aSLionel Sambuc 1346f4a2713aSLionel Sambuc@interface Person { 1347f4a2713aSLionel Sambuc NSString *name; 1348f4a2713aSLionel Sambuc} 1349f4a2713aSLionel Sambuc@property NSString *address; 1350f4a2713aSLionel Sambuc@end 1351f4a2713aSLionel Sambuc 1352f4a2713aSLionel Sambuc@implementation Person 1353f4a2713aSLionel Sambuc@synthesize address; 1354f4a2713aSLionel Sambuc@end 1355*0a6a1f1dSLionel Sambuc// CHECK: tail call i8* @objc_getProperty 1356f4a2713aSLionel Sambuc// CHECK: call void @objc_setProperty 1357f4a2713aSLionel Sambuc 1358f4a2713aSLionel Sambuc// Verify that we successfully parse and preserve this attribute in 1359f4a2713aSLionel Sambuc// this position. 1360f4a2713aSLionel Sambuc@interface Test66 1361f4a2713aSLionel Sambuc- (void) consume: (id __attribute__((ns_consumed))) ptr; 1362f4a2713aSLionel Sambuc@end 1363f4a2713aSLionel Sambucvoid test66(void) { 1364f4a2713aSLionel Sambuc extern Test66 *test66_receiver(void); 1365f4a2713aSLionel Sambuc extern id test66_arg(void); 1366f4a2713aSLionel Sambuc [test66_receiver() consume: test66_arg()]; 1367f4a2713aSLionel Sambuc} 1368f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test66() 1369f4a2713aSLionel Sambuc// CHECK: [[T0:%.*]] = call [[TEST66:%.*]]* @test66_receiver() 1370f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST66]]* [[T0]] to i8* 1371f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) 1372f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST66]]* 1373f4a2713aSLionel Sambuc// CHECK-NEXT: [[T4:%.*]] = call i8* @test66_arg() 1374f4a2713aSLionel Sambuc// CHECK-NEXT: [[T5:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T4]]) 1375*0a6a1f1dSLionel Sambuc// CHECK-NEXT: [[T6:%.*]] = load i8** @OBJC_SELECTOR_REFERENCES 1376f4a2713aSLionel Sambuc// CHECK-NEXT: [[T7:%.*]] = bitcast [[TEST66]]* [[T3]] to i8* 1377f4a2713aSLionel Sambuc// CHECK-NEXT: [[SIX:%.*]] = icmp eq i8* [[T7]], null 1378f4a2713aSLionel Sambuc// CHECK-NEXT: br i1 [[SIX]], label [[NULINIT:%.*]], label [[CALL:%.*]] 1379f4a2713aSLionel Sambuc// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i8*)*)(i8* [[T7]], i8* [[T6]], i8* [[T5]]) 1380f4a2713aSLionel Sambuc// CHECK-NEXT: br label [[CONT:%.*]] 1381f4a2713aSLionel Sambuc// CHECK: call void @objc_release(i8* [[T5]]) [[NUW]] 1382f4a2713aSLionel Sambuc// CHECK-NEXT: br label [[CONT:%.*]] 1383f4a2713aSLionel Sambuc// CHECK: [[T8:%.*]] = bitcast [[TEST66]]* [[T3]] to i8* 1384f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_release(i8* [[T8]]) 1385f4a2713aSLionel Sambuc// CHECK-NEXT: ret void 1386f4a2713aSLionel Sambuc 1387f4a2713aSLionel Sambuc// rdar://problem/9953540 1388f4a2713aSLionel SambucClass test67_helper(void); 1389f4a2713aSLionel Sambucvoid test67(void) { 1390f4a2713aSLionel Sambuc Class cl = test67_helper(); 1391f4a2713aSLionel Sambuc} 1392f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test67() 1393f4a2713aSLionel Sambuc// CHECK: [[CL:%.*]] = alloca i8*, align 8 1394f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = call i8* @test67_helper() 1395f4a2713aSLionel Sambuc// CHECK-NEXT: store i8* [[T0]], i8** [[CL]], align 8 1396f4a2713aSLionel Sambuc// CHECK-NEXT: ret void 1397f4a2713aSLionel Sambuc 1398f4a2713aSLionel SambucClass test68_helper(void); 1399f4a2713aSLionel Sambucvoid test68(void) { 1400f4a2713aSLionel Sambuc __strong Class cl = test67_helper(); 1401f4a2713aSLionel Sambuc} 1402f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test68() 1403f4a2713aSLionel Sambuc// CHECK: [[CL:%.*]] = alloca i8*, align 8 1404f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = call i8* @test67_helper() 1405f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]]) 1406f4a2713aSLionel Sambuc// CHECK-NEXT: store i8* [[T1]], i8** [[CL]], align 8 1407f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = load i8** [[CL]] 1408f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_release(i8* [[T2]]) 1409f4a2713aSLionel Sambuc// CHECK-NEXT: ret void 1410f4a2713aSLionel Sambuc 1411f4a2713aSLionel Sambuc// rdar://problem/10564852 1412f4a2713aSLionel Sambuc@interface Test69 @end 1413f4a2713aSLionel Sambuc@implementation Test69 1414f4a2713aSLionel Sambuc- (id) foo { return self; } 1415f4a2713aSLionel Sambuc@end 1416f4a2713aSLionel Sambuc// CHECK: define internal i8* @"\01-[Test69 foo]"( 1417f4a2713aSLionel Sambuc// CHECK: [[SELF:%.*]] = alloca [[TEST69:%.*]]*, align 8 1418f4a2713aSLionel Sambuc// CHECK: [[T0:%.*]] = load [[TEST69]]** [[SELF]], align 8 1419f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST69]]* [[T0]] to i8* 1420f4a2713aSLionel Sambuc// CHECK-NEXT: ret i8* [[T1]] 1421f4a2713aSLionel Sambuc 1422f4a2713aSLionel Sambuc// rdar://problem/10907547 1423f4a2713aSLionel Sambucvoid test70(id i) { 1424f4a2713aSLionel Sambuc // CHECK-LABEL: define void @test70 1425f4a2713aSLionel Sambuc // CHECK: store i8* null, i8** 1426f4a2713aSLionel Sambuc // CHECK: store i8* null, i8** 1427f4a2713aSLionel Sambuc // CHECK: [[ID:%.*]] = call i8* @objc_retain(i8* 1428f4a2713aSLionel Sambuc // CHECK: store i8* [[ID]], i8** 1429f4a2713aSLionel Sambuc id x[3] = { 1430f4a2713aSLionel Sambuc [2] = i 1431f4a2713aSLionel Sambuc }; 1432f4a2713aSLionel Sambuc} 1433f4a2713aSLionel Sambuc 1434f4a2713aSLionel Sambuc// ARC-ALIEN: attributes [[NLB]] = { nonlazybind } 1435f4a2713aSLionel Sambuc// ARC-NATIVE: attributes [[NLB]] = { nonlazybind } 1436f4a2713aSLionel Sambuc// CHECK: attributes [[NUW]] = { nounwind } 1437