1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fobjc-dispatch-method=mixed -fobjc-runtime-has-weak -fexceptions -o - %s | FileCheck %s 2 3 @interface NSObject 4 - (id) new; 5 @end 6 7 @interface MyObject : NSObject 8 - (char)isEqual:(id) __attribute__((ns_consumed)) object; 9 - (_Complex float) asComplexWithArg: (id) __attribute__((ns_consumed)) object; 10 @end 11 12 MyObject *x; 13 14 // rdar://10444476 15 void test0(void) { 16 id obj = [NSObject new]; 17 [x isEqual : obj]; 18 } 19 // CHECK: define void @test0() 20 // CHECK: [[FIVE:%.*]] = call i8* @objc_retain 21 // CHECK-NEXT: [[SIX:%.*]] = bitcast 22 // CHECK-NEXT: [[SEVEN:%.*]] = icmp eq i8* [[SIX]], null 23 // CHECK-NEXT: br i1 [[SEVEN]], label [[NULLINIT:%.*]], label [[CALL_LABEL:%.*]] 24 // CHECK: [[FN:%.*]] = load i8** getelementptr inbounds 25 // CHECK-NEXT: [[EIGHT:%.*]] = bitcast i8* [[FN]] 26 // CHECK-NEXT: [[CALL:%.*]] = call signext i8 [[EIGHT]] 27 // CHECK-NEXT: br label [[CONT:%.*]] 28 // CHECK: call void @objc_release(i8* [[FIVE]]) [[NUW:#[0-9]+]] 29 // CHECK-NEXT: br label [[CONT]] 30 // CHECK: phi i8 [ [[CALL]], {{%.*}} ], [ 0, {{%.*}} ] 31 32 // Ensure that we build PHIs correctly in the presence of cleanups. 33 // rdar://12046763 34 void test1(void) { 35 id obj = [NSObject new]; 36 __weak id weakObj = obj; 37 _Complex float result = [x asComplexWithArg: obj]; 38 } 39 // CHECK: define void @test1() 40 // CHECK: [[OBJ:%.*]] = alloca i8*, align 8 41 // CHECK-NEXT: [[WEAKOBJ:%.*]] = alloca i8*, align 8 42 // CHECK-NEXT: [[RESULT:%.*]] = alloca { float, float }, align 4 43 // Various initializations. 44 // CHECK: [[T0:%.*]] = call i8* bitcast ( 45 // CHECK-NEXT: store i8* [[T0]], i8** [[OBJ]] 46 // CHECK-NEXT: [[T0:%.*]] = load i8** [[OBJ]] 47 // CHECK-NEXT: call i8* @objc_initWeak(i8** [[WEAKOBJ]], i8* [[T0]]) [[NUW]] 48 // Okay, start the message-send. 49 // CHECK-NEXT: [[T0:%.*]] = load [[MYOBJECT:%.*]]** @x 50 // CHECK-NEXT: [[ARG:%.*]] = load i8** [[OBJ]] 51 // CHECK-NEXT: [[ARG_RETAINED:%.*]] = call i8* @objc_retain(i8* [[ARG]]) 52 // CHECK-NEXT: load i8** @ 53 // CHECK-NEXT: [[SELF:%.*]] = bitcast [[MYOBJECT]]* [[T0]] to i8* 54 // Null check. 55 // CHECK-NEXT: [[T0:%.*]] = icmp eq i8* [[SELF]], null 56 // CHECK-NEXT: br i1 [[T0]], label [[FORNULL:%.*]], label [[FORCALL:%.*]] 57 // Invoke and produce the return values. 58 // CHECK: [[CALL:%.*]] = invoke <2 x float> bitcast 59 // CHECK-NEXT: to label [[INVOKE_CONT:%.*]] unwind label {{%.*}} 60 // CHECK: [[T0:%.*]] = bitcast { float, float }* [[COERCE:%.*]] to <2 x float>* 61 // CHECK-NEXT: store <2 x float> [[CALL]], <2 x float>* [[T0]], 62 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds { float, float }* [[COERCE]], i32 0, i32 0 63 // CHECK-NEXT: [[REALCALL:%.*]] = load float* [[T0]] 64 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds { float, float }* [[COERCE]], i32 0, i32 1 65 // CHECK-NEXT: [[IMAGCALL:%.*]] = load float* [[T0]] 66 // CHECK-NEXT: br label [[CONT:%.*]]{{$}} 67 // Null path. 68 // CHECK: call void @objc_release(i8* [[ARG_RETAINED]]) [[NUW]] 69 // CHECK-NEXT: br label [[CONT]] 70 // Join point. 71 // CHECK: [[REAL:%.*]] = phi float [ [[REALCALL]], [[INVOKE_CONT]] ], [ 0.000000e+00, [[FORNULL]] ] 72 // CHECK-NEXT: [[IMAG:%.*]] = phi float [ [[IMAGCALL]], [[INVOKE_CONT]] ], [ 0.000000e+00, [[FORNULL]] ] 73 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds { float, float }* [[RESULT]], i32 0, i32 0 74 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds { float, float }* [[RESULT]], i32 0, i32 1 75 // CHECK-NEXT: store float [[REAL]], float* [[T0]] 76 // CHECK-NEXT: store float [[IMAG]], float* [[T1]] 77 // Epilogue. 78 // CHECK-NEXT: call void @objc_destroyWeak(i8** [[WEAKOBJ]]) [[NUW]] 79 // CHECK-NEXT: call void @objc_storeStrong(i8** [[OBJ]], i8* null) [[NUW]] 80 // CHECK-NEXT: ret void 81 // Cleanup. 82 // CHECK: landingpad 83 // CHECK: call void @objc_destroyWeak(i8** [[WEAKOBJ]]) [[NUW]] 84 85 // CHECK: attributes [[NUW]] = { nounwind } 86