1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-runtime-has-weak -fblocks -fobjc-arc -o - %s | FileCheck %s 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc// A test to ensure that we generate fused calls at -O0. 4*f4a2713aSLionel Sambuc 5*f4a2713aSLionel Sambuc@class Test0; 6*f4a2713aSLionel SambucTest0 *test0(void) { 7*f4a2713aSLionel Sambuc extern Test0 *test0_helper; 8*f4a2713aSLionel Sambuc return test0_helper; 9*f4a2713aSLionel Sambuc 10*f4a2713aSLionel Sambuc // CHECK: [[LD:%.*]] = load [[TEST0:%.*]]** @test0_helper 11*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = bitcast [[TEST0]]* [[LD]] to i8* 12*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = tail call i8* @objc_retainAutoreleaseReturnValue(i8* [[T0]]) 13*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = bitcast i8* [[T1]] to [[TEST0]]* 14*f4a2713aSLionel Sambuc // CHECK-NEXT: ret [[TEST0]]* [[T2]] 15*f4a2713aSLionel Sambuc} 16*f4a2713aSLionel Sambuc 17*f4a2713aSLionel Sambucid test1(void) { 18*f4a2713aSLionel Sambuc extern id test1_helper; 19*f4a2713aSLionel Sambuc return test1_helper; 20*f4a2713aSLionel Sambuc 21*f4a2713aSLionel Sambuc // CHECK: [[LD:%.*]] = load i8** @test1_helper 22*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = tail call i8* @objc_retainAutoreleaseReturnValue(i8* [[LD]]) 23*f4a2713aSLionel Sambuc // CHECK-NEXT: ret i8* [[T0]] 24*f4a2713aSLionel Sambuc} 25*f4a2713aSLionel Sambuc 26*f4a2713aSLionel Sambucvoid test2(void) { 27*f4a2713aSLionel Sambuc // CHECK: [[X:%.*]] = alloca i8* 28*f4a2713aSLionel Sambuc // CHECK-NEXT: store i8* null, i8** [[X]] 29*f4a2713aSLionel Sambuc // CHECK-NEXT: call void @objc_destroyWeak(i8** [[X]]) 30*f4a2713aSLionel Sambuc // CHECK-NEXT: ret void 31*f4a2713aSLionel Sambuc __weak id x; 32*f4a2713aSLionel Sambuc} 33*f4a2713aSLionel Sambuc 34*f4a2713aSLionel Sambucid test3(void) { 35*f4a2713aSLionel Sambuc extern id test3_helper(void); 36*f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = call i8* @test3_helper() 37*f4a2713aSLionel Sambuc // CHECK-NEXT: ret i8* [[T0]] 38*f4a2713aSLionel Sambuc return test3_helper(); 39*f4a2713aSLionel Sambuc} 40*f4a2713aSLionel Sambuc 41*f4a2713aSLionel Sambuc@interface Test4 { id x; } @end 42*f4a2713aSLionel Sambuc@interface Test4_sub : Test4 { id y; } @end 43*f4a2713aSLionel SambucTest4 *test4(void) { 44*f4a2713aSLionel Sambuc extern Test4_sub *test4_helper(void); 45*f4a2713aSLionel Sambuc // CHECK: [[T0:%.*]] = call [[TEST4S:%.*]]* @test4_helper() 46*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST4S]]* [[T0]] to [[TEST4:%.*]]* 47*f4a2713aSLionel Sambuc // CHECK-NEXT: ret [[TEST4]]* [[T1]] 48*f4a2713aSLionel Sambuc return test4_helper(); 49*f4a2713aSLionel Sambuc} 50*f4a2713aSLionel Sambuc 51*f4a2713aSLionel Sambuc// rdar://problem/9418404 52*f4a2713aSLionel Sambuc@class Test5; 53*f4a2713aSLionel Sambucvoid test5(void) { 54*f4a2713aSLionel Sambuc Test5 *x, *y; 55*f4a2713aSLionel Sambuc if ((x = y)) 56*f4a2713aSLionel Sambuc y = 0; 57*f4a2713aSLionel Sambuc 58*f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test5() 59*f4a2713aSLionel Sambuc// CHECK: [[X:%.*]] = alloca [[TEST5:%.*]]*, 60*f4a2713aSLionel Sambuc// CHECK-NEXT: [[Y:%.*]] = alloca [[TEST5:%.*]]*, 61*f4a2713aSLionel Sambuc// CHECK-NEXT: store [[TEST5]]* null, [[TEST5]]** [[X]], 62*f4a2713aSLionel Sambuc// CHECK-NEXT: store [[TEST5]]* null, [[TEST5]]** [[Y]], 63*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load [[TEST5]]** [[Y]], 64*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST5]]** [[X]] to i8** 65*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast [[TEST5]]* [[T0]] to i8* 66*f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_storeStrong(i8** [[T1]], i8* [[T2]]) 67*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = icmp ne [[TEST5]]* [[T0]], null 68*f4a2713aSLionel Sambuc// CHECK-NEXT: br i1 [[T3]], 69*f4a2713aSLionel Sambuc} 70