1 // RUN: %clang_cc1 -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;
16 id obj = [NSObject new];
19 // CHECK-LABEL: define{{.*}} void @test0()
20 // CHECK: [[FIVE:%.*]] = call ptr @llvm.objc.retain
21 // CHECK-NEXT: [[SEVEN:%.*]] = icmp eq ptr {{.*}}, null
22 // CHECK-NEXT: br i1 [[SEVEN]], label [[NULLINIT:%.*]], label [[CALL_LABEL:%.*]]
23 // CHECK: [[FN:%.*]] = load ptr, ptr
24 // CHECK-NEXT: [[CALL:%.*]] = call signext i8 [[FN]]
25 // CHECK-NEXT: br label [[CONT:%.*]]
26 // CHECK: call void @llvm.objc.release(ptr [[FIVE]]) [[NUW:#[0-9]+]]
27 // CHECK-NEXT: br label [[CONT]]
28 // CHECK: phi i8 [ [[CALL]], {{%.*}} ], [ 0, {{%.*}} ]
30 // Ensure that we build PHIs correctly in the presence of cleanups.
32 id obj = [NSObject new];
33 __weak id weakObj = obj;
34 _Complex float result = [x asComplexWithArg: obj];
36 // CHECK-LABEL: define{{.*}} void @test1()
37 // CHECK: [[OBJ:%.*]] = alloca ptr, align 8
38 // CHECK-NEXT: [[WEAKOBJ:%.*]] = alloca ptr, align 8
39 // CHECK-NEXT: [[RESULT:%.*]] = alloca { float, float }, align 4
40 // Various initializations.
41 // CHECK: [[T0:%.*]] = call ptr
42 // CHECK-NEXT: store ptr [[T0]], ptr [[OBJ]]
43 // CHECK-NEXT: [[T0:%.*]] = load ptr, ptr [[OBJ]]
44 // CHECK-NEXT: call ptr @llvm.objc.initWeak(ptr [[WEAKOBJ]], ptr [[T0]]) [[NUW]]
45 // Okay, start the message-send.
46 // CHECK-NEXT: [[T0:%.*]] = load ptr, ptr @x
47 // CHECK-NEXT: [[ARG:%.*]] = load ptr, ptr [[OBJ]]
48 // CHECK-NEXT: [[ARG_RETAINED:%.*]] = call ptr @llvm.objc.retain(ptr [[ARG]])
50 // CHECK-NEXT: [[T1:%.*]] = icmp eq ptr [[T0]], null
51 // CHECK-NEXT: br i1 [[T1]], label [[FORNULL:%.*]], label %[[FORCALL:.*]]
52 // Invoke and produce the return values.
53 // CHECK: [[FORCALL]]:
54 // CHECK-NEXT: load ptr, ptr @OBJC_SELECTOR_REFERENCES_
55 // CHECK-NEXT: [[CALL:%.*]] = invoke <2 x float>
56 // CHECK-NEXT: to label [[INVOKE_CONT:%.*]] unwind label {{%.*}}
57 // CHECK: store <2 x float> [[CALL]], ptr [[COERCE:%.*]],
58 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[COERCE]], i32 0, i32 0
59 // CHECK-NEXT: [[REALCALL:%.*]] = load float, ptr [[T0]]
60 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[COERCE]], i32 0, i32 1
61 // CHECK-NEXT: [[IMAGCALL:%.*]] = load float, ptr [[T0]]
62 // CHECK-NEXT: br label [[CONT:%.*]]{{$}}
64 // CHECK: call void @llvm.objc.release(ptr [[ARG_RETAINED]]) [[NUW]]
65 // CHECK-NEXT: br label [[CONT]]
67 // CHECK: [[REAL:%.*]] = phi float [ [[REALCALL]], [[INVOKE_CONT]] ], [ 0.000000e+00, [[FORNULL]] ]
68 // CHECK-NEXT: [[IMAG:%.*]] = phi float [ [[IMAGCALL]], [[INVOKE_CONT]] ], [ 0.000000e+00, [[FORNULL]] ]
69 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[RESULT]], i32 0, i32 0
70 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds nuw { float, float }, ptr [[RESULT]], i32 0, i32 1
71 // CHECK-NEXT: store float [[REAL]], ptr [[T0]]
72 // CHECK-NEXT: store float [[IMAG]], ptr [[T1]]
74 // CHECK-NEXT: call void @llvm.objc.destroyWeak(ptr [[WEAKOBJ]]) [[NUW]]
75 // CHECK-NEXT: call void @llvm.objc.storeStrong(ptr [[OBJ]], ptr null) [[NUW]]
76 // CHECK-NEXT: ret void
79 // CHECK: call void @llvm.objc.destroyWeak(ptr [[WEAKOBJ]]) [[NUW]]
82 id obj = [MyObject m0:a];
85 // CHECK-LABEL: define{{.*}} void @test2(
86 // CHECK: %[[CALL:.*]] = call ptr @objc_msgSend
87 // CHECK-NEXT: %[[V6:.*]] = {{.*}}call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %[[CALL]])
89 // CHECK: phi ptr [ %[[V6]], %{{.*}} ], [ null, %{{.*}} ]
93 id obj = [MyObject m0:a];
98 // CHECK-LABEL: define{{.*}} void @test3(
99 // CHECK: %[[CALL:.*]] = invoke ptr @objc_msgSend
100 // CHECK: %[[V6:.*]] = {{.*}}call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %[[CALL]])
102 // CHECK: phi ptr [ %[[V6]], %{{.*}} ], [ null, %{{.*}} ]
104 // CHECK: attributes [[NUW]] = { nounwind }