1 // RUN: %clang_cc1 -fobjc-arc -fobjc-runtime-has-weak -fblocks -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=UNOPT
2 // RUN: %clang_cc1 -fobjc-arc -fobjc-runtime-has-weak -fblocks -triple x86_64-apple-darwin10.0.0 -emit-llvm -o - %s -O -disable-llvm-passes | FileCheck %s -check-prefix=CHECK -check-prefix=OPT
4 typedef __strong id strong_id;
5 typedef __weak id weak_id;
7 // CHECK-LABEL: define{{.*}} void @_Z8test_newP11objc_object
8 void test_new(id invalue) {
9 // CHECK: [[INVALUEADDR:%.*]] = alloca ptr
10 // UNOPT-NEXT: store ptr null, ptr [[INVALUEADDR]]
11 // UNOPT-NEXT: call void @llvm.objc.storeStrong(ptr [[INVALUEADDR]], ptr [[INVALUE:%.*]])
12 // OPT-NEXT: [[T0:%.*]] = call ptr @llvm.objc.retain(ptr [[INVALUE:%.*]])
13 // OPT-NEXT: store ptr [[T0]], ptr [[INVALUEADDR]]
15 // CHECK: [[CALL:%.*]] = call noalias noundef nonnull ptr @_Znwm
16 // CHECK-NEXT: store ptr null, ptr
18 // CHECK: [[CALL:%.*]] = call noalias noundef nonnull ptr @_Znwm
19 // UNOPT-NEXT: store ptr null, ptr
20 // OPT-NEXT: call ptr @llvm.objc.initWeak(ptr {{.*}}, ptr null)
23 // CHECK: [[CALL:%.*]] = call noalias noundef nonnull ptr @_Znwm
24 // CHECK-NEXT: store ptr null, ptr
26 // CHECK: [[CALL:%.*]] = call noalias noundef nonnull ptr @_Znwm
27 // UNOPT-NEXT: store ptr null, ptr
28 // OPT-NEXT: call ptr @llvm.objc.initWeak(ptr {{.*}}, ptr null)
31 // CHECK: [[CALL:%.*]] = call noalias noundef nonnull ptr @_Znwm
32 // CHECK: call ptr @llvm.objc.retain
34 new __strong id(invalue);
36 // CHECK: [[CALL:%.*]] = call noalias noundef nonnull ptr @_Znwm
37 // CHECK: call ptr @llvm.objc.initWeak
38 new __weak id(invalue);
40 // UNOPT: call void @llvm.objc.storeStrong
41 // OPT: call void @llvm.objc.release
45 // CHECK-LABEL: define{{.*}} void @_Z14test_array_new
46 void test_array_new() {
47 // CHECK: call noalias noundef nonnull ptr @_Znam
48 // CHECK: store i64 17, ptr
49 // CHECK: call void @llvm.memset.p0.i64
52 // CHECK: call noalias noundef nonnull ptr @_Znam
53 // CHECK: store i64 17, ptr
54 // CHECK: call void @llvm.memset.p0.i64
59 // CHECK-LABEL: define{{.*}} void @_Z11test_deletePU8__strongP11objc_objectPU6__weakS0_
60 void test_delete(__strong id *sptr, __weak id *wptr) {
62 // UNOPT: call void @llvm.objc.storeStrong(ptr {{.*}}, ptr null)
64 // OPT-NEXT: call void @llvm.objc.release
65 // CHECK: call void @_ZdlPv
68 // CHECK: call void @llvm.objc.destroyWeak
69 // CHECK: call void @_ZdlPv
75 // CHECK-LABEL: define{{.*}} void @_Z17test_array_deletePU8__strongP11objc_objectPU6__weakS0_
76 void test_array_delete(__strong id *sptr, __weak id *wptr) {
77 // CHECK: icmp eq ptr [[BEGIN:%.*]], null
78 // CHECK: [[LEN:%.*]] = load i64, ptr {{%.*}}
79 // CHECK: [[END:%.*]] = getelementptr inbounds ptr, ptr [[BEGIN]], i64 [[LEN]]
80 // CHECK-NEXT: icmp eq ptr [[BEGIN]], [[END]]
81 // CHECK: [[PAST:%.*]] = phi ptr [ [[END]], {{%.*}} ], [ [[CUR:%.*]],
82 // CHECK-NEXT: [[CUR]] = getelementptr inbounds ptr, ptr [[PAST]], i64 -1
83 // UNOPT-NEXT: call void @llvm.objc.storeStrong(ptr [[CUR]], ptr null)
84 // OPT-NEXT: [[T0:%.*]] = load ptr, ptr [[CUR]]
85 // OPT-NEXT: llvm.objc.release(ptr [[T0]])
86 // CHECK-NEXT: icmp eq ptr [[CUR]], [[BEGIN]]
87 // CHECK: call void @_ZdaPv
90 // CHECK: icmp eq ptr [[BEGIN:%.*]], null
91 // CHECK: [[LEN:%.*]] = load i64, ptr {{%.*}}
92 // CHECK: [[END:%.*]] = getelementptr inbounds ptr, ptr [[BEGIN]], i64 [[LEN]]
93 // CHECK-NEXT: icmp eq ptr [[BEGIN]], [[END]]
94 // CHECK: [[PAST:%.*]] = phi ptr [ [[END]], {{%.*}} ], [ [[CUR:%.*]],
95 // CHECK-NEXT: [[CUR]] = getelementptr inbounds ptr, ptr [[PAST]], i64 -1
96 // CHECK-NEXT: call void @llvm.objc.destroyWeak(ptr [[CUR]])
97 // CHECK-NEXT: icmp eq ptr [[CUR]], [[BEGIN]]
98 // CHECK: call void @_ZdaPv