annotate clang/test/CodeGenObjC/noescape.m @ 206:f17a3b42b08b

Added tag before-12 for changeset b7591485f4cd
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 07 Jun 2021 21:25:57 +0900
parents 1d019706d866
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -fblocks -emit-llvm -o - %s | FileCheck -check-prefix CHECK -check-prefix CHECK-NOARC %s
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -triple x86_64-apple-darwin -fblocks -emit-llvm -fobjc-arc -o - %s | FileCheck -check-prefix CHECK -check-prefix CHECK-ARC %s
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 typedef void (^BlockTy)(void);
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 union U {
anatofuz
parents:
diff changeset
7 int *i;
anatofuz
parents:
diff changeset
8 long long *ll;
anatofuz
parents:
diff changeset
9 } __attribute__((transparent_union));
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 void escapingFunc0(BlockTy);
anatofuz
parents:
diff changeset
12 void noescapeFunc0(id, __attribute__((noescape)) BlockTy);
anatofuz
parents:
diff changeset
13 void noescapeFunc1(__attribute__((noescape)) int *);
anatofuz
parents:
diff changeset
14 void noescapeFunc2(__attribute__((noescape)) id);
anatofuz
parents:
diff changeset
15 void noescapeFunc3(__attribute__((noescape)) union U);
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 // Block descriptors of non-escaping blocks don't need pointers to copy/dispose
anatofuz
parents:
diff changeset
18 // helper functions.
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 // CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 // When the block is non-escaping, copy/dispose helpers aren't generated, so the
anatofuz
parents:
diff changeset
23 // block layout string must include information about __strong captures.
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 // CHECK-NOARC: %[[STRUCT_BLOCK_BYREF_B0:.*]] = type { i8*, %[[STRUCT_BLOCK_BYREF_B0]]*, i32, i32, i8*, %[[STRUCT_S0:.*]] }
anatofuz
parents:
diff changeset
26 // CHECK-ARC: %[[STRUCT_BLOCK_BYREF_B0:.*]] = type { i8*, %[[STRUCT_BLOCK_BYREF_B0]]*, i32, i32, i8*, i8*, i8*, %[[STRUCT_S0:.*]] }
anatofuz
parents:
diff changeset
27 // CHECK: %[[STRUCT_S0]] = type { i8*, i8* }
anatofuz
parents:
diff changeset
28 // CHECK: @[[BLOCK_DESCIPTOR_TMP_2:.*ls32l8"]] = linkonce_odr hidden unnamed_addr constant { i64, i64, i8*, i64 } { i64 0, i64 40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, align 8
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 // CHECK-LABEL: define void @test0(
anatofuz
parents:
diff changeset
31 // CHECK: call void @noescapeFunc0({{.*}}, {{.*}} nocapture {{.*}})
anatofuz
parents:
diff changeset
32 // CHECK: declare void @noescapeFunc0(i8*, {{.*}} nocapture)
anatofuz
parents:
diff changeset
33 void test0(BlockTy b) {
anatofuz
parents:
diff changeset
34 noescapeFunc0(0, b);
anatofuz
parents:
diff changeset
35 }
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 // CHECK-LABEL: define void @test1(
anatofuz
parents:
diff changeset
38 // CHECK: call void @noescapeFunc1({{.*}} nocapture {{.*}})
anatofuz
parents:
diff changeset
39 // CHECK: declare void @noescapeFunc1({{.*}} nocapture)
anatofuz
parents:
diff changeset
40 void test1(int *i) {
anatofuz
parents:
diff changeset
41 noescapeFunc1(i);
anatofuz
parents:
diff changeset
42 }
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 // CHECK-LABEL: define void @test2(
anatofuz
parents:
diff changeset
45 // CHECK: call void @noescapeFunc2({{.*}} nocapture {{.*}})
anatofuz
parents:
diff changeset
46 // CHECK: declare void @noescapeFunc2({{.*}} nocapture)
anatofuz
parents:
diff changeset
47 void test2(id i) {
anatofuz
parents:
diff changeset
48 noescapeFunc2(i);
anatofuz
parents:
diff changeset
49 }
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 // CHECK-LABEL: define void @test3(
anatofuz
parents:
diff changeset
52 // CHECK: call void @noescapeFunc3({{.*}} nocapture {{.*}})
anatofuz
parents:
diff changeset
53 // CHECK: declare void @noescapeFunc3({{.*}} nocapture)
anatofuz
parents:
diff changeset
54 void test3(union U u) {
anatofuz
parents:
diff changeset
55 noescapeFunc3(u);
anatofuz
parents:
diff changeset
56 }
anatofuz
parents:
diff changeset
57
anatofuz
parents:
diff changeset
58 // CHECK: define internal void @"\01-[C0 m0:]"({{.*}}, {{.*}}, {{.*}} nocapture {{.*}})
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 // CHECK-LABEL: define void @test4(
anatofuz
parents:
diff changeset
61 // CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, i32*)*)(i8* {{.*}}, i8* {{.*}}, i32* nocapture {{.*}})
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 @interface C0
anatofuz
parents:
diff changeset
64 -(void) m0:(int*)__attribute__((noescape)) p0;
anatofuz
parents:
diff changeset
65 @end
anatofuz
parents:
diff changeset
66
anatofuz
parents:
diff changeset
67 @implementation C0
anatofuz
parents:
diff changeset
68 -(void) m0:(int*)__attribute__((noescape)) p0 {
anatofuz
parents:
diff changeset
69 }
anatofuz
parents:
diff changeset
70 @end
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72 void test4(C0 *c0, int *p) {
anatofuz
parents:
diff changeset
73 [c0 m0:p];
anatofuz
parents:
diff changeset
74 }
anatofuz
parents:
diff changeset
75
anatofuz
parents:
diff changeset
76 // CHECK-LABEL: define void @test5(
anatofuz
parents:
diff changeset
77 // CHECK: call void {{.*}}(i8* bitcast ({ i8**, i32, i32, i8*, {{.*}} }* @{{.*}} to i8*), i32* nocapture {{.*}})
anatofuz
parents:
diff changeset
78 // CHECK: call void {{.*}}(i8* {{.*}}, i32* nocapture {{.*}})
anatofuz
parents:
diff changeset
79 // CHECK: define internal void @{{.*}}(i8* {{.*}}, i32* nocapture {{.*}})
anatofuz
parents:
diff changeset
80
anatofuz
parents:
diff changeset
81 typedef void (^BlockTy2)(__attribute__((noescape)) int *);
anatofuz
parents:
diff changeset
82
anatofuz
parents:
diff changeset
83 void test5(BlockTy2 b, int *p) {
anatofuz
parents:
diff changeset
84 ^(int *__attribute__((noescape)) p0){}(p);
anatofuz
parents:
diff changeset
85 b(p);
anatofuz
parents:
diff changeset
86 }
anatofuz
parents:
diff changeset
87
anatofuz
parents:
diff changeset
88 // If the block is non-escaping, set the BLOCK_IS_NOESCAPE and BLOCK_IS_GLOBAL
anatofuz
parents:
diff changeset
89 // bits of field 'flags' and set the 'isa' field to 'NSConcreteGlobalBlock'.
anatofuz
parents:
diff changeset
90
anatofuz
parents:
diff changeset
91 // CHECK: define void @test6(i8* %{{.*}}, i8* %[[B:.*]])
anatofuz
parents:
diff changeset
92 // CHECK: %{{.*}} = alloca i8*, align 8
anatofuz
parents:
diff changeset
93 // CHECK: %[[B_ADDR:.*]] = alloca i8*, align 8
anatofuz
parents:
diff changeset
94 // CHECK: %[[BLOCK:.*]] = alloca <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, align 8
anatofuz
parents:
diff changeset
95 // CHECK-NOARC: store i8* %[[B]], i8** %[[B_ADDR]], align 8
anatofuz
parents:
diff changeset
96 // CHECK-ARC: store i8* null, i8** %[[B_ADDR]], align 8
anatofuz
parents:
diff changeset
97 // CHECK-ARC: call void @llvm.objc.storeStrong(i8** %[[B_ADDR]], i8* %[[B]])
anatofuz
parents:
diff changeset
98 // CHECK-ARC: %[[V0:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* %[[BLOCK]], i32 0, i32 5
anatofuz
parents:
diff changeset
99 // CHECK: %[[BLOCK_ISA:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* %[[BLOCK]], i32 0, i32 0
anatofuz
parents:
diff changeset
100 // CHECK: store i8* bitcast (i8** @_NSConcreteGlobalBlock to i8*), i8** %[[BLOCK_ISA]], align 8
anatofuz
parents:
diff changeset
101 // CHECK: %[[BLOCK_FLAGS:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* %[[BLOCK]], i32 0, i32 1
anatofuz
parents:
diff changeset
102 // CHECK: store i32 -796917760, i32* %[[BLOCK_FLAGS]], align 8
anatofuz
parents:
diff changeset
103 // CHECK: %[[BLOCK_DESCRIPTOR:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* %[[BLOCK]], i32 0, i32 4
anatofuz
parents:
diff changeset
104 // CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i64 }* @[[BLOCK_DESCIPTOR_TMP_2]] to %[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR]], align 8
anatofuz
parents:
diff changeset
105 // CHECK: %[[BLOCK_CAPTURED:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* %[[BLOCK]], i32 0, i32 5
anatofuz
parents:
diff changeset
106 // CHECK-NOARC: %[[V1:.*]] = load i8*, i8** %[[B_ADDR]], align 8
anatofuz
parents:
diff changeset
107 // CHECK-NOARC: store i8* %[[V1]], i8** %[[BLOCK_CAPTURED]], align 8
anatofuz
parents:
diff changeset
108 // CHECK-ARC: %[[V2:.*]] = load i8*, i8** %[[B_ADDR]], align 8
anatofuz
parents:
diff changeset
109 // CHECK-ARC: %[[V3:.*]] = call i8* @llvm.objc.retain(i8* %[[V2]])
anatofuz
parents:
diff changeset
110 // CHECK-ARC: store i8* %[[V3]], i8** %[[BLOCK_CAPTURED]], align 8
anatofuz
parents:
diff changeset
111 // CHECK: call void @noescapeFunc0(
anatofuz
parents:
diff changeset
112 // CHECK-ARC: call void @llvm.objc.storeStrong(i8** %[[V0]], i8* null)
anatofuz
parents:
diff changeset
113 // CHECK-ARC: call void @llvm.objc.storeStrong(i8** %[[B_ADDR]], i8* null)
anatofuz
parents:
diff changeset
114
anatofuz
parents:
diff changeset
115 // Non-escaping blocks don't need copy/dispose helper functions.
anatofuz
parents:
diff changeset
116
anatofuz
parents:
diff changeset
117 // CHECK-NOT: define internal void @__copy_helper_block_
anatofuz
parents:
diff changeset
118 // CHECK-NOT: define internal void @__destroy_helper_block_
anatofuz
parents:
diff changeset
119
anatofuz
parents:
diff changeset
120 void func(id);
anatofuz
parents:
diff changeset
121
anatofuz
parents:
diff changeset
122 void test6(id a, id b) {
anatofuz
parents:
diff changeset
123 noescapeFunc0(a, ^{ func(b); });
anatofuz
parents:
diff changeset
124 }
anatofuz
parents:
diff changeset
125
anatofuz
parents:
diff changeset
126 // We don't need either the byref helper functions or the byref structs for
anatofuz
parents:
diff changeset
127 // __block variables that are not captured by escaping blocks.
anatofuz
parents:
diff changeset
128
anatofuz
parents:
diff changeset
129 // CHECK: define void @test7(
anatofuz
parents:
diff changeset
130 // CHECK: alloca i8*, align 8
anatofuz
parents:
diff changeset
131 // CHECK: %[[B0:.*]] = alloca i8*, align 8
anatofuz
parents:
diff changeset
132 // CHECK: %[[BLOCK:.*]] = alloca <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8** }>, align 8
anatofuz
parents:
diff changeset
133 // CHECK: %[[BLOCK_CAPTURED:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8** }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8** }>* %[[BLOCK]], i32 0, i32 5
anatofuz
parents:
diff changeset
134 // CHECK: store i8** %[[B0]], i8*** %[[BLOCK_CAPTURED]], align 8
anatofuz
parents:
diff changeset
135
anatofuz
parents:
diff changeset
136 // CHECK-ARC-NOT: define internal void @__Block_byref_object_copy_
anatofuz
parents:
diff changeset
137 // CHECK-ARC-NOT: define internal void @__Block_byref_object_dispose_
anatofuz
parents:
diff changeset
138
anatofuz
parents:
diff changeset
139 void test7() {
anatofuz
parents:
diff changeset
140 id a;
anatofuz
parents:
diff changeset
141 __block id b0;
anatofuz
parents:
diff changeset
142 noescapeFunc0(a, ^{ (void)b0; });
anatofuz
parents:
diff changeset
143 }
anatofuz
parents:
diff changeset
144
anatofuz
parents:
diff changeset
145 // __block variables captured by escaping blocks need byref helper functions.
anatofuz
parents:
diff changeset
146
anatofuz
parents:
diff changeset
147 // CHECK: define void @test8(
anatofuz
parents:
diff changeset
148 // CHECK: %[[A:.*]] = alloca i8*, align 8
anatofuz
parents:
diff changeset
149 // CHECK: %[[B0:.*]] = alloca %[[STRUCT_BLOCK_BYREF_B0]], align 8
anatofuz
parents:
diff changeset
150 // CHECK: alloca <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, align 8
anatofuz
parents:
diff changeset
151 // CHECK: %[[BLOCK1:.*]] = alloca <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, align 8
anatofuz
parents:
diff changeset
152 // CHECK: %[[BLOCK_CAPTURED7:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* %[[BLOCK1]], i32 0, i32 5
anatofuz
parents:
diff changeset
153 // CHECK: %[[V3:.*]] = bitcast %[[STRUCT_BLOCK_BYREF_B0]]* %[[B0]] to i8*
anatofuz
parents:
diff changeset
154 // CHECK: store i8* %[[V3]], i8** %[[BLOCK_CAPTURED7]], align 8
anatofuz
parents:
diff changeset
155
anatofuz
parents:
diff changeset
156 // CHECK-ARC: define internal void @__Block_byref_object_copy_
anatofuz
parents:
diff changeset
157 // CHECK-ARC: define internal void @__Block_byref_object_dispose_
anatofuz
parents:
diff changeset
158 // CHECK: define linkonce_odr hidden void @__copy_helper_block_
anatofuz
parents:
diff changeset
159 // CHECK: define linkonce_odr hidden void @__destroy_helper_block_
anatofuz
parents:
diff changeset
160
anatofuz
parents:
diff changeset
161 struct S0 {
anatofuz
parents:
diff changeset
162 id a, b;
anatofuz
parents:
diff changeset
163 };
anatofuz
parents:
diff changeset
164
anatofuz
parents:
diff changeset
165 void test8() {
anatofuz
parents:
diff changeset
166 id a;
anatofuz
parents:
diff changeset
167 __block struct S0 b0;
anatofuz
parents:
diff changeset
168 noescapeFunc0(a, ^{ (void)b0; });
anatofuz
parents:
diff changeset
169 escapingFunc0(^{ (void)b0; });
anatofuz
parents:
diff changeset
170 }