1 // RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fobjc-dispatch-method=mixed -fobjc-runtime-has-weak -fexceptions -fobjc-exceptions -o - %s | FileCheck %s
7 @interface MyObject : NSObject
8 - (char)isEqual:(id) __attribute__((ns_consumed)) object;
9 - (_Complex float) asComplexWithArg: (id) __attribute__((ns_consumed)) object;
10 +(instancetype)m0:(id) __attribute__((ns_consumed)) object;
17 id obj = [NSObject new];
20 // CHECK-LABEL: define{{.*}} void @test0()
21 // CHECK: [[FIVE:%.*]] = call i8* @llvm.objc.retain
22 // CHECK-NEXT: [[SIX:%.*]] = bitcast
23 // CHECK-NEXT: [[SEVEN:%.*]] = icmp eq i8* [[SIX]], null
24 // CHECK-NEXT: br i1 [[SEVEN]], label [[NULLINIT:%.*]], label [[CALL_LABEL:%.*]]
25 // CHECK: [[FN:%.*]] = load i8*, i8** getelementptr inbounds
26 // CHECK-NEXT: [[EIGHT:%.*]] = bitcast i8* [[FN]]
27 // CHECK-NEXT: [[CALL:%.*]] = call signext i8 [[EIGHT]]
28 // CHECK-NEXT: br label [[CONT:%.*]]
29 // CHECK: call void @llvm.objc.release(i8* [[FIVE]]) [[NUW:#[0-9]+]]
30 // CHECK-NEXT: br label [[CONT]]
31 // CHECK: phi i8 [ [[CALL]], {{%.*}} ], [ 0, {{%.*}} ]
33 // Ensure that we build PHIs correctly in the presence of cleanups.
36 id obj = [NSObject new];
37 __weak id weakObj = obj;
38 _Complex float result = [x asComplexWithArg: obj];
40 // CHECK-LABEL: define{{.*}} void @test1()
41 // CHECK: [[OBJ:%.*]] = alloca i8*, align 8
42 // CHECK-NEXT: [[WEAKOBJ:%.*]] = alloca i8*, align 8
43 // CHECK-NEXT: [[RESULT:%.*]] = alloca { float, float }, align 4
44 // Various initializations.
45 // CHECK: [[T0:%.*]] = call i8* bitcast (
46 // CHECK-NEXT: store i8* [[T0]], i8** [[OBJ]]
47 // CHECK-NEXT: [[T0:%.*]] = load i8*, i8** [[OBJ]]
48 // CHECK-NEXT: call i8* @llvm.objc.initWeak(i8** [[WEAKOBJ]], i8* [[T0]]) [[NUW]]
49 // Okay, start the message-send.
50 // CHECK-NEXT: [[T0:%.*]] = load [[MYOBJECT:%.*]]*, [[MYOBJECT:%.*]]** @x
51 // CHECK-NEXT: [[ARG:%.*]] = load i8*, i8** [[OBJ]]
52 // CHECK-NEXT: [[ARG_RETAINED:%.*]] = call i8* @llvm.objc.retain(i8* [[ARG]])
53 // CHECK-NEXT: [[SELF:%.*]] = bitcast [[MYOBJECT]]* [[T0]] to i8*
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: [[FORCALL]]:
59 // CHECK-NEXT: load i8*, i8** @OBJC_SELECTOR_REFERENCES_
60 // CHECK-NEXT: [[CALL:%.*]] = invoke <2 x float> bitcast
61 // CHECK-NEXT: to label [[INVOKE_CONT:%.*]] unwind label {{%.*}}
62 // CHECK: [[T0:%.*]] = bitcast { float, float }* [[COERCE:%.*]] to <2 x float>*
63 // CHECK-NEXT: store <2 x float> [[CALL]], <2 x float>* [[T0]],
64 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds { float, float }, { float, float }* [[COERCE]], i32 0, i32 0
65 // CHECK-NEXT: [[REALCALL:%.*]] = load float, float* [[T0]]
66 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds { float, float }, { float, float }* [[COERCE]], i32 0, i32 1
67 // CHECK-NEXT: [[IMAGCALL:%.*]] = load float, float* [[T0]]
68 // CHECK-NEXT: br label [[CONT:%.*]]{{$}}
70 // CHECK: call void @llvm.objc.release(i8* [[ARG_RETAINED]]) [[NUW]]
71 // CHECK-NEXT: br label [[CONT]]
73 // CHECK: [[REAL:%.*]] = phi float [ [[REALCALL]], [[INVOKE_CONT]] ], [ 0.000000e+00, [[FORNULL]] ]
74 // CHECK-NEXT: [[IMAG:%.*]] = phi float [ [[IMAGCALL]], [[INVOKE_CONT]] ], [ 0.000000e+00, [[FORNULL]] ]
75 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds { float, float }, { float, float }* [[RESULT]], i32 0, i32 0
76 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds { float, float }, { float, float }* [[RESULT]], i32 0, i32 1
77 // CHECK-NEXT: store float [[REAL]], float* [[T0]]
78 // CHECK-NEXT: store float [[IMAG]], float* [[T1]]
80 // CHECK-NEXT: call void @llvm.objc.destroyWeak(i8** [[WEAKOBJ]]) [[NUW]]
81 // CHECK-NEXT: call void @llvm.objc.storeStrong(i8** [[OBJ]], i8* null) [[NUW]]
82 // CHECK-NEXT: ret void
85 // CHECK: call void @llvm.objc.destroyWeak(i8** [[WEAKOBJ]]) [[NUW]]
88 id obj = [MyObject m0:a];
91 // CHECK-LABEL: define{{.*}} void @test2(
92 // CHECK: %[[CALL:.*]] = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
93 // CHECK-NEXT: %[[V6:.*]] = {{.*}}call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL]])
95 // CHECK: phi i8* [ %[[V6]], %{{.*}} ], [ null, %{{.*}} ]
99 id obj = [MyObject m0:a];
104 // CHECK-LABEL: define{{.*}} void @test3(
105 // CHECK: %[[CALL:.*]] = invoke i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
106 // CHECK: %[[V6:.*]] = {{.*}}call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[CALL]])
108 // CHECK: phi i8* [ %[[V6]], %{{.*}} ], [ null, %{{.*}} ]
110 // CHECK: attributes [[NUW]] = { nounwind }