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 3f4a2713aSLionel Sambuc#define PRECISE_LIFETIME __attribute__((objc_precise_lifetime)) 4f4a2713aSLionel Sambuc 5f4a2713aSLionel Sambucid test0_helper(void) __attribute__((ns_returns_retained)); 6f4a2713aSLionel Sambucvoid test0() { 7f4a2713aSLionel Sambuc PRECISE_LIFETIME id x = test0_helper(); 8f4a2713aSLionel Sambuc x = 0; 9f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i8* 10f4a2713aSLionel Sambuc // CHECK-NEXT: [[CALL:%.*]] = call i8* @test0_helper() 11f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[CALL]], i8** [[X]] 12f4a2713aSLionel Sambuc 13f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] 14f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* null, i8** [[X]] 15f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW:#[0-9]+]] 16f4a2713aSLionel Sambuc // CHECK-NOT: clang.imprecise_release 17f4a2713aSLionel Sambuc 18f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = load i8** [[X]] 19f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW:#[0-9]+]] 20f4a2713aSLionel Sambuc // CHECK-NOT: clang.imprecise_release 21f4a2713aSLionel Sambuc 22f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 23f4a2713aSLionel Sambuc} 24f4a2713aSLionel Sambuc 25f4a2713aSLionel Sambuc// rdar://problem/9821110 26f4a2713aSLionel Sambuc@interface Test1 27f4a2713aSLionel Sambuc- (char*) interior __attribute__((objc_returns_inner_pointer)); 28f4a2713aSLionel Sambuc// Should we allow this on properties? Yes! see // rdar://14990439 29f4a2713aSLionel Sambuc@property (nonatomic, readonly) char * PropertyReturnsInnerPointer __attribute__((objc_returns_inner_pointer)); 30f4a2713aSLionel Sambuc@end 31f4a2713aSLionel Sambucextern Test1 *test1_helper(void); 32f4a2713aSLionel Sambuc 33f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test1a() 34f4a2713aSLionel Sambucvoid test1a(void) { 35f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = call [[TEST1:%.*]]* @test1_helper() 36f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST1]]* [[T0]] to i8* 37f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) 38f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST1]]* 39f4a2713aSLionel Sambuc // CHECK-NEXT: store [[TEST1]]* [[T3]] 40f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[TEST1]]** 41f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST1]]* [[T0]] to i8* 42f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutorelease(i8* [[T1]]) 43f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST1]]* 44*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = load i8** @OBJC_SELECTOR_REFERENCES_ 45f4a2713aSLionel Sambuc // CHECK-NEXT: [[T5:%.*]] = bitcast [[TEST1]]* [[T3]] to i8* 46f4a2713aSLionel Sambuc // CHECK-NEXT: [[T6:%.*]] = call i8* bitcast 47f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T6]], i8** 48f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[TEST1]]** 49f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST1]]* [[T0]] to i8* 50f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release 51f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 52f4a2713aSLionel Sambuc Test1 *ptr = test1_helper(); 53f4a2713aSLionel Sambuc char *c = [(ptr) interior]; 54f4a2713aSLionel Sambuc} 55f4a2713aSLionel Sambuc 56f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test1b() 57f4a2713aSLionel Sambucvoid test1b(void) { 58f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = call [[TEST1:%.*]]* @test1_helper() 59f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST1]]* [[T0]] to i8* 60f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) 61f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST1]]* 62f4a2713aSLionel Sambuc // CHECK-NEXT: store [[TEST1]]* [[T3]] 63f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[TEST1]]** 64*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = load i8** @OBJC_SELECTOR_REFERENCES_ 65f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST1]]* [[T0]] to i8* 66f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = call i8* bitcast 67f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T3]], i8** 68f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[TEST1]]** 69f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST1]]* [[T0]] to i8* 70f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]] 71f4a2713aSLionel Sambuc // CHECK-NOT: clang.imprecise_release 72f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 73f4a2713aSLionel Sambuc __attribute__((objc_precise_lifetime)) Test1 *ptr = test1_helper(); 74f4a2713aSLionel Sambuc char *c = [ptr interior]; 75f4a2713aSLionel Sambuc} 76f4a2713aSLionel Sambuc 77f4a2713aSLionel Sambucvoid test1c(void) { 78f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = call [[TEST1:%.*]]* @test1_helper() 79f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST1]]* [[T0]] to i8* 80f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) 81f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST1]]* 82f4a2713aSLionel Sambuc // CHECK-NEXT: store [[TEST1]]* [[T3]] 83f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[TEST1]]** 84f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST1]]* [[T0]] to i8* 85f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutorelease(i8* [[T1]]) 86f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST1]]* 87*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = load i8** @OBJC_SELECTOR_REFERENCES_ 88f4a2713aSLionel Sambuc // CHECK-NEXT: [[T5:%.*]] = bitcast [[TEST1]]* [[T3]] to i8* 89f4a2713aSLionel Sambuc // CHECK-NEXT: [[T6:%.*]] = call i8* bitcast 90f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T6]], i8** 91f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[TEST1]]** 92f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST1]]* [[T0]] to i8* 93f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release 94f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 95f4a2713aSLionel Sambuc Test1 *ptr = test1_helper(); 96f4a2713aSLionel Sambuc char *pc = ptr.PropertyReturnsInnerPointer; 97f4a2713aSLionel Sambuc} 98f4a2713aSLionel Sambuc 99f4a2713aSLionel Sambucvoid test1d(void) { 100f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = call [[TEST1:%.*]]* @test1_helper() 101f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST1]]* [[T0]] to i8* 102f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T1]]) 103f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[TEST1]]* 104f4a2713aSLionel Sambuc // CHECK-NEXT: store [[TEST1]]* [[T3]] 105f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[TEST1]]** 106f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST1]]* [[T0]] to i8* 107f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retainAutorelease 108f4a2713aSLionel Sambuc // CHECK-NEXT: [[SIX:%.*]] = bitcast i8* [[T3]] to [[TEST1]]* 109*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[SEVEN:%.*]] = load i8** @OBJC_SELECTOR_REFERENCES_ 110f4a2713aSLionel Sambuc // CHECK-NEXT: [[EIGHT:%.*]] = bitcast [[TEST1]]* [[SIX]] to i8* 111f4a2713aSLionel Sambuc // CHECK-NEXT: [[CALL1:%.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*)*)(i8* [[EIGHT]], i8* [[SEVEN]]) 112f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[CALL1]], i8** 113f4a2713aSLionel Sambuc // CHECK-NEXT: [[NINE:%.*]] = load [[TEST1]]** 114f4a2713aSLionel Sambuc // CHECK-NEXT: [[TEN:%.*]] = bitcast [[TEST1]]* [[NINE]] to i8* 115f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[TEN]]) 116f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 117f4a2713aSLionel Sambuc __attribute__((objc_precise_lifetime)) Test1 *ptr = test1_helper(); 118f4a2713aSLionel Sambuc char *pc = ptr.PropertyReturnsInnerPointer; 119f4a2713aSLionel Sambuc} 120f4a2713aSLionel Sambuc 121f4a2713aSLionel Sambuc@interface Test2 { 122f4a2713aSLionel Sambuc@public 123f4a2713aSLionel Sambuc id ivar; 124f4a2713aSLionel Sambuc} 125f4a2713aSLionel Sambuc@end 126f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test2( 127f4a2713aSLionel Sambucvoid test2(Test2 *x) { 128f4a2713aSLionel Sambuc x->ivar = 0; 129f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca [[TEST2:%.*]]* 130f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST2]]* {{%.*}} to i8* 131f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retain(i8* [[T0]]) [[NUW]] 132f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[TEST2]]* 133f4a2713aSLionel Sambuc // CHECK-NEXT: store [[TEST2]]* [[T2]], [[TEST2]]** [[X]], 134f4a2713aSLionel Sambuc 135f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[TEST2]]** [[X]], 136f4a2713aSLionel Sambuc // CHECK-NEXT: [[OFFSET:%.*]] = load i64* @"OBJC_IVAR_$_Test2.ivar" 137f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST2]]* [[T0]] to i8* 138f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds i8* [[T1]], i64 [[OFFSET]] 139f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to i8** 140f4a2713aSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = load i8** [[T3]], 141f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* null, i8** [[T3]], 142f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T4]]) [[NUW]] 143f4a2713aSLionel Sambuc // CHECK-NOT: imprecise 144f4a2713aSLionel Sambuc 145f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load [[TEST2]]** [[X]] 146f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST2]]* [[T0]] to i8* 147f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T1]]) [[NUW]], !clang.imprecise_release 148f4a2713aSLionel Sambuc 149f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 150f4a2713aSLionel Sambuc} 151f4a2713aSLionel Sambuc 152f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test3(i8* 153f4a2713aSLionel Sambucvoid test3(PRECISE_LIFETIME id x) { 154f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i8*, 155f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = call i8* @objc_retain(i8* {{%.*}}) [[NUW]] 156f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* [[T0]], i8** [[X]], 157f4a2713aSLionel Sambuc 158f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = load i8** [[X]] 159f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_release(i8* [[T0]]) [[NUW]] 160f4a2713aSLionel Sambuc // CHECK-NOT: imprecise_release 161f4a2713aSLionel Sambuc 162f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 163f4a2713aSLionel Sambuc} 164f4a2713aSLionel Sambuc 165f4a2713aSLionel Sambuc// CHECK: attributes [[NUW]] = { nounwind } 166