1 // RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O2 -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,CHECK-O2
2 // RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O0 | FileCheck %s --check-prefixes=CHECK,CHECK-O0
3 // RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -O2 -disable-llvm-passes | FileCheck %s --check-prefix=CHECK-MRR
5 // Make sure we emit clang.arc.use before calling objc_release as part of the
6 // cleanup. This way we make sure the object will not be released until the
7 // end of the full expression.
17 extern __attribute__((visibility("default"))) NSString *GenString(void);
18 void os_log_pack_send(void *);
20 // CHECK-LABEL: define{{.*}} void @test_builtin_os_log1(
21 // CHECK: alloca ptr, align 8
22 // CHECK: %[[A_ADDR:.*]] = alloca ptr, align 8
23 // CHECK: %[[OS_LOG_ARG:.*]] = alloca ptr, align 8
24 // CHECK-O2: %[[V0:.*]] = call ptr @llvm.objc.retain(
25 // CHECK-O2: store ptr %[[V0]], ptr %[[A_ADDR]], align 8,
26 // CHECK-O0: call void @llvm.objc.storeStrong(ptr %[[A_ADDR]], ptr %{{.*}})
27 // CHECK-O2: %[[V3:.*]] = call ptr @GenString() [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
28 // CHECK-O0: %[[CALL:.*]] = call ptr @GenString()
29 // CHECK-O0: %[[V3:.*]] = notail call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %[[CALL]])
30 // CHECK: %[[V6:.*]] = call ptr @llvm.objc.retain(ptr %[[V3]])
31 // CHECK: store ptr %[[V6]], ptr %[[OS_LOG_ARG]],
32 // CHECK: %[[V8:.*]] = ptrtoint ptr %[[V6]] to i64
33 // CHECK: %[[V9:.*]] = load ptr, ptr %[[A_ADDR]], align 8
34 // CHECK: %[[V10:.*]] = ptrtoint ptr %[[V9]] to i64
35 // CHECK: call void @__os_log_helper_1_2_2_8_64_8_64(ptr noundef %{{.*}}, i64 noundef %[[V8]], i64 noundef %[[V10]])
36 // CHECK: call void @llvm.objc.release(ptr %[[V3]])
37 // CHECK: call void @os_log_pack_send(ptr noundef %{{.*}})
38 // CHECK-O2: call void (...) @llvm.objc.clang.arc.use(ptr %[[V6]])
39 // CHECK-O2: %[[V13:.*]] = load ptr, ptr %[[OS_LOG_ARG]], align 8
40 // CHECK-O2: call void @llvm.objc.release(ptr %[[V13]])
41 // CHECK-O2: %[[V15:.*]] = load ptr, ptr %[[A_ADDR]], align 8
42 // CHECK-O2: call void @llvm.objc.release(ptr %[[V15]])
43 // CHECK-O0: call void @llvm.objc.storeStrong(ptr %[[OS_LOG_ARG]], ptr null)
44 // CHECK-O0: call void @llvm.objc.storeStrong(ptr %[[A_ADDR]], ptr null)
46 // CHECK-MRR-LABEL: define{{.*}} void @test_builtin_os_log1(
47 // CHECK-MRR-NOT: call {{.*}} @llvm.objc
48 // CHECK-MRR: ret void
50 void test_builtin_os_log1(void *buf, id a) {
51 __builtin_os_log_format(buf, "capabilities: %@ %@", GenString(), a);
52 os_log_pack_send(buf);
55 // CHECK: define{{.*}} void @test_builtin_os_log2(
56 // CHECK-NOT: @llvm.objc.retain(
58 void test_builtin_os_log2(void *buf, id __unsafe_unretained a) {
59 __builtin_os_log_format(buf, "capabilities: %@", a);
60 os_log_pack_send(buf);
63 // CHECK-LABEL: define{{.*}} void @test_builtin_os_log3(
64 // CHECK: alloca ptr, align 8
65 // CHECK: %[[OS_LOG_ARG:.*]] = alloca ptr, align 8
66 // CHECK-O2: %[[V2:.*]] = call ptr @GenString() [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
67 // CHECK-O0: %[[CALL:.*]] = call ptr @GenString()
68 // CHECK-O0: %[[V2:.*]] = notail call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %[[CALL]])
69 // CHECK: %[[V5:.*]] = call ptr @llvm.objc.retain(ptr %[[V2]])
70 // CHECK: store ptr %[[V5]], ptr %[[OS_LOG_ARG]], align 8
71 // CHECK: %[[V6:.*]] = ptrtoint ptr %[[V5]] to i64
72 // CHECK: call void @__os_log_helper_1_2_1_8_64(ptr noundef %{{.*}}, i64 noundef %[[V6]])
73 // CHECK: call void @llvm.objc.release(ptr %[[V2]])
74 // CHECK: call void @os_log_pack_send(ptr noundef %{{.*}})
75 // CHECK-O2: call void (...) @llvm.objc.clang.arc.use(ptr %[[V5]])
76 // CHECK-O2: %[[V9:.*]] = load ptr, ptr %[[OS_LOG_ARG]], align 8
77 // CHECK-O2: call void @llvm.objc.release(ptr %[[V9]])
78 // CHECK-O0: call void @llvm.objc.storeStrong(ptr %[[OS_LOG_ARG]], ptr null)
80 void test_builtin_os_log3(void *buf) {
81 __builtin_os_log_format(buf, "capabilities: %@", (id)GenString());
82 os_log_pack_send(buf);
85 // CHECK-LABEL: define{{.*}} void @test_builtin_os_log4(
86 // CHECK: alloca ptr, align 8
87 // CHECK: %[[OS_LOG_ARG:.*]] = alloca ptr, align 8
88 // CHECK: %[[OS_LOG_ARG2:.*]] = alloca ptr, align 8
89 // CHECK-O2: %[[V4:.*]] = call {{.*}} @objc_msgSend{{.*}} [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
90 // CHECK-O0: %[[CALL:.*]] = call {{.*}} @objc_msgSend
91 // CHECK-O0: %[[V4:.*]] = notail call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %[[CALL]])
92 // CHECK: %[[V5:.*]] = call ptr @llvm.objc.retain(ptr %[[V4]])
93 // CHECK: store ptr %[[V5]], ptr %[[OS_LOG_ARG]], align 8
94 // CHECK: %[[V6:.*]] = ptrtoint ptr %[[V5]] to i64
95 // CHECK-O2: %[[V10:.*]] = call {{.*}} @objc_msgSend{{.*}} [ "clang.arc.attachedcall"(ptr @llvm.objc.retainAutoreleasedReturnValue) ]
96 // CHECK-O0: %[[CALL1:.*]] = call {{.*}} @objc_msgSend
97 // CHECK-O0: %[[V10:.*]] = notail call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %[[CALL1]])
98 // CHECK: %[[V11:.*]] = call ptr @llvm.objc.retain(ptr %[[V10]])
99 // CHECK: store ptr %[[V11]], ptr %[[OS_LOG_ARG2]], align 8
100 // CHECK: %[[V12:.*]] = ptrtoint ptr %[[V11]] to i64
101 // CHECK: call void @__os_log_helper_1_2_2_8_64_8_64(ptr noundef %{{.*}}, i64 noundef %[[V6]], i64 noundef %[[V12]])
102 // CHECK: call void @llvm.objc.release(ptr %[[V10]])
103 // CHECK: call void @llvm.objc.release(ptr %[[V4]])
104 // CHECK: call void @os_log_pack_send(ptr noundef %{{.*}})
105 // CHECK-O2: call void (...) @llvm.objc.clang.arc.use(ptr %[[V11]])
106 // CHECK-O2: %[[V14:.*]] = load ptr, ptr %[[OS_LOG_ARG2]], align 8
107 // CHECK-O2: call void @llvm.objc.release(ptr %[[V14]])
108 // CHECK-O2: call void (...) @llvm.objc.clang.arc.use(ptr %[[V5]])
109 // CHECK-O2: %[[V15:.*]] = load ptr, ptr %[[OS_LOG_ARG]], align 8
110 // CHECK-O2: call void @llvm.objc.release(ptr %[[V15]])
112 void test_builtin_os_log4(void *buf) {
113 __builtin_os_log_format(buf, "capabilities: %@ %@", [c m0], [C m1]);
114 os_log_pack_send(buf);
117 // FIXME: Lifetime of GenString's return should be extended in this case too.
118 // CHECK-LABEL: define{{.*}} void @test_builtin_os_log5(
119 // CHECK: call void @os_log_pack_send(
120 // CHECK-NOT: call void @llvm.objc.release(
122 void test_builtin_os_log5(void *buf) {
123 __builtin_os_log_format(buf, "capabilities: %@", (0, GenString()));
124 os_log_pack_send(buf);