1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals
2 ; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,TUNIT
3 ; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,CGSCC
6 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
7 ; CHECK-LABEL: define {{[^@]+}}@leaf
8 ; CHECK-SAME: () #[[ATTR0:[0-9]+]] {
9 ; CHECK-NEXT: ret i32 1
14 define i32 @self_rec() {
15 ; CHECK: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
16 ; CHECK-LABEL: define {{[^@]+}}@self_rec
17 ; CHECK-SAME: () #[[ATTR1:[0-9]+]] {
18 ; CHECK-NEXT: ret i32 4
20 %a = call i32 @self_rec()
24 define i32 @indirect_rec() {
25 ; TUNIT: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
26 ; TUNIT-LABEL: define {{[^@]+}}@indirect_rec
27 ; TUNIT-SAME: () #[[ATTR1]] {
28 ; TUNIT-NEXT: ret i32 undef
30 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
31 ; CGSCC-LABEL: define {{[^@]+}}@indirect_rec
32 ; CGSCC-SAME: () #[[ATTR0]] {
33 ; CGSCC-NEXT: ret i32 undef
35 %a = call i32 @indirect_rec2()
38 define i32 @indirect_rec2() {
39 ; TUNIT: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
40 ; TUNIT-LABEL: define {{[^@]+}}@indirect_rec2
41 ; TUNIT-SAME: () #[[ATTR1]] {
42 ; TUNIT-NEXT: ret i32 undef
44 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
45 ; CGSCC-LABEL: define {{[^@]+}}@indirect_rec2
46 ; CGSCC-SAME: () #[[ATTR0]] {
47 ; CGSCC-NEXT: ret i32 undef
49 %a = call i32 @indirect_rec()
53 define i32 @extern() {
54 ; CHECK: Function Attrs: nosync memory(none)
55 ; CHECK-LABEL: define {{[^@]+}}@extern
56 ; CHECK-SAME: () #[[ATTR2:[0-9]+]] {
57 ; CHECK-NEXT: [[A:%.*]] = call i32 @k() #[[ATTR9:[0-9]+]]
58 ; CHECK-NEXT: ret i32 [[A]]
64 ; CHECK: Function Attrs
65 ; CHECK-NEXT: declare i32 @k()
66 declare i32 @k() readnone
68 define void @intrinsic(ptr %dest, ptr %src, i32 %len) {
69 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite)
70 ; CHECK-LABEL: define {{[^@]+}}@intrinsic
71 ; CHECK-SAME: (ptr nocapture nofree writeonly [[DEST:%.*]], ptr nocapture nofree readonly [[SRC:%.*]], i32 [[LEN:%.*]]) #[[ATTR4:[0-9]+]] {
72 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr nocapture nofree writeonly [[DEST]], ptr nocapture nofree readonly [[SRC]], i32 [[LEN]], i1 noundef false) #[[ATTR10:[0-9]+]]
73 ; CHECK-NEXT: ret void
75 call void @llvm.memcpy.p0.p0.i32(ptr %dest, ptr %src, i32 %len, i1 false)
79 ; CHECK: Function Attrs
80 ; CHECK-NEXT: declare void @llvm.memcpy.p0.p0.i32
81 declare void @llvm.memcpy.p0.p0.i32(ptr, ptr, i32, i1)
83 define internal i32 @called_by_norecurse() {
84 ; CHECK: Function Attrs: norecurse nosync memory(none)
85 ; CHECK-LABEL: define {{[^@]+}}@called_by_norecurse
86 ; CHECK-SAME: () #[[ATTR6:[0-9]+]] {
87 ; CHECK-NEXT: [[A:%.*]] = call i32 @k() #[[ATTR9]]
88 ; CHECK-NEXT: ret i32 undef
93 define void @m() norecurse {
94 ; TUNIT: Function Attrs: norecurse nosync memory(none)
95 ; TUNIT-LABEL: define {{[^@]+}}@m
96 ; TUNIT-SAME: () #[[ATTR6]] {
97 ; TUNIT-NEXT: [[A:%.*]] = call i32 @called_by_norecurse() #[[ATTR2]]
98 ; TUNIT-NEXT: ret void
100 ; CGSCC: Function Attrs: norecurse nosync memory(none)
101 ; CGSCC-LABEL: define {{[^@]+}}@m
102 ; CGSCC-SAME: () #[[ATTR6]] {
103 ; CGSCC-NEXT: [[A:%.*]] = call i32 @called_by_norecurse() #[[ATTR9]]
104 ; CGSCC-NEXT: ret void
106 %a = call i32 @called_by_norecurse()
110 define internal i32 @called_by_norecurse_indirectly() {
111 ; TUNIT: Function Attrs: norecurse nosync memory(none)
112 ; TUNIT-LABEL: define {{[^@]+}}@called_by_norecurse_indirectly
113 ; TUNIT-SAME: () #[[ATTR6]] {
114 ; TUNIT-NEXT: [[A:%.*]] = call i32 @k() #[[ATTR9]]
115 ; TUNIT-NEXT: ret i32 [[A]]
117 ; CGSCC: Function Attrs: nosync memory(none)
118 ; CGSCC-LABEL: define {{[^@]+}}@called_by_norecurse_indirectly
119 ; CGSCC-SAME: () #[[ATTR2]] {
120 ; CGSCC-NEXT: [[A:%.*]] = call i32 @k() #[[ATTR9]]
121 ; CGSCC-NEXT: ret i32 [[A]]
126 define internal i32 @o() {
127 ; TUNIT: Function Attrs: norecurse nosync memory(none)
128 ; TUNIT-LABEL: define {{[^@]+}}@o
129 ; TUNIT-SAME: () #[[ATTR6]] {
130 ; TUNIT-NEXT: [[A:%.*]] = call i32 @called_by_norecurse_indirectly() #[[ATTR2]]
131 ; TUNIT-NEXT: ret i32 [[A]]
133 ; CGSCC: Function Attrs: norecurse nosync memory(none)
134 ; CGSCC-LABEL: define {{[^@]+}}@o
135 ; CGSCC-SAME: () #[[ATTR6]] {
136 ; CGSCC-NEXT: [[A:%.*]] = call i32 @called_by_norecurse_indirectly() #[[ATTR9]]
137 ; CGSCC-NEXT: ret i32 [[A]]
139 %a = call i32 @called_by_norecurse_indirectly()
142 define i32 @p() norecurse {
143 ; TUNIT: Function Attrs: norecurse nosync memory(none)
144 ; TUNIT-LABEL: define {{[^@]+}}@p
145 ; TUNIT-SAME: () #[[ATTR6]] {
146 ; TUNIT-NEXT: [[A:%.*]] = call i32 @o() #[[ATTR2]]
147 ; TUNIT-NEXT: ret i32 [[A]]
149 ; CGSCC: Function Attrs: norecurse nosync memory(none)
150 ; CGSCC-LABEL: define {{[^@]+}}@p
151 ; CGSCC-SAME: () #[[ATTR6]] {
152 ; CGSCC-NEXT: [[A:%.*]] = call i32 @o() #[[ATTR9]]
153 ; CGSCC-NEXT: ret i32 [[A]]
159 define void @f(i32 %x) {
160 ; TUNIT: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
161 ; TUNIT-LABEL: define {{[^@]+}}@f
162 ; TUNIT-SAME: (i32 [[X:%.*]]) #[[ATTR1]] {
164 ; TUNIT-NEXT: [[X_ADDR:%.*]] = alloca i32, align 4
165 ; TUNIT-NEXT: store i32 [[X]], ptr [[X_ADDR]], align 4
166 ; TUNIT-NEXT: [[TOBOOL:%.*]] = icmp ne i32 [[X]], 0
167 ; TUNIT-NEXT: br i1 [[TOBOOL]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
169 ; TUNIT-NEXT: br label [[IF_END]]
171 ; TUNIT-NEXT: ret void
173 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
174 ; CGSCC-LABEL: define {{[^@]+}}@f
175 ; CGSCC-SAME: (i32 [[X:%.*]]) #[[ATTR0]] {
177 ; CGSCC-NEXT: [[X_ADDR:%.*]] = alloca i32, align 4
178 ; CGSCC-NEXT: [[TOBOOL:%.*]] = icmp ne i32 [[X]], 0
179 ; CGSCC-NEXT: br i1 [[TOBOOL]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
181 ; CGSCC-NEXT: br label [[IF_END]]
183 ; CGSCC-NEXT: ret void
186 %x.addr = alloca i32, align 4
187 store i32 %x, ptr %x.addr, align 4
188 %0 = load i32, ptr %x.addr, align 4
189 %tobool = icmp ne i32 %0, 0
190 br i1 %tobool, label %if.then, label %if.end
193 call void @g() norecurse
200 define void @g() norecurse {
201 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
202 ; CHECK-LABEL: define {{[^@]+}}@g
203 ; CHECK-SAME: () #[[ATTR0]] {
205 ; CHECK-NEXT: ret void
212 define linkonce_odr i32 @leaf_redefinable() {
213 ; CHECK-LABEL: define {{[^@]+}}@leaf_redefinable() {
214 ; CHECK-NEXT: ret i32 1
219 ; Call through a function pointer
220 define i32 @eval_func1(ptr , i32) local_unnamed_addr {
221 ; CHECK-LABEL: define {{[^@]+}}@eval_func1
222 ; CHECK-SAME: (ptr nocapture nofree noundef nonnull [[TMP0:%.*]], i32 [[TMP1:%.*]]) local_unnamed_addr {
223 ; CHECK-NEXT: [[TMP3:%.*]] = tail call i32 [[TMP0]](i32 [[TMP1]])
224 ; CHECK-NEXT: ret i32 [[TMP3]]
226 %3 = tail call i32 %0(i32 %1) #2
230 define i32 @eval_func2(ptr , i32) local_unnamed_addr null_pointer_is_valid{
231 ; CHECK: Function Attrs: null_pointer_is_valid
232 ; CHECK-LABEL: define {{[^@]+}}@eval_func2
233 ; CHECK-SAME: (ptr nocapture nofree noundef [[TMP0:%.*]], i32 [[TMP1:%.*]]) local_unnamed_addr #[[ATTR7:[0-9]+]] {
234 ; CHECK-NEXT: [[TMP3:%.*]] = tail call i32 [[TMP0]](i32 [[TMP1]])
235 ; CHECK-NEXT: ret i32 [[TMP3]]
237 %3 = tail call i32 %0(i32 %1) #2
241 ; Call an unknown function in a dead block.
242 declare void @unknown()
243 define i32 @call_unknown_in_dead_block() local_unnamed_addr {
244 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
245 ; CHECK-LABEL: define {{[^@]+}}@call_unknown_in_dead_block
246 ; CHECK-SAME: () local_unnamed_addr #[[ATTR0]] {
247 ; CHECK-NEXT: ret i32 0
249 ; CHECK-NEXT: unreachable
253 tail call void @unknown()
257 define i1 @test_rec_neg(i1 %c) norecurse {
258 ; TUNIT: Function Attrs: norecurse
259 ; TUNIT-LABEL: define {{[^@]+}}@test_rec_neg
260 ; TUNIT-SAME: (i1 [[C:%.*]]) #[[ATTR8:[0-9]+]] {
261 ; TUNIT-NEXT: [[RC1:%.*]] = call i1 @rec(i1 noundef true)
262 ; TUNIT-NEXT: br i1 [[RC1]], label [[T:%.*]], label [[F:%.*]]
264 ; TUNIT-NEXT: [[RC2:%.*]] = call i1 @rec(i1 noundef [[C]])
265 ; TUNIT-NEXT: ret i1 [[RC2]]
267 ; TUNIT-NEXT: ret i1 [[RC1]]
269 ; CGSCC: Function Attrs: norecurse
270 ; CGSCC-LABEL: define {{[^@]+}}@test_rec_neg
271 ; CGSCC-SAME: (i1 [[C:%.*]]) #[[ATTR8:[0-9]+]] {
272 ; CGSCC-NEXT: [[RC1:%.*]] = call noundef i1 @rec(i1 noundef true)
273 ; CGSCC-NEXT: br i1 [[RC1]], label [[T:%.*]], label [[F:%.*]]
275 ; CGSCC-NEXT: [[RC2:%.*]] = call noundef i1 @rec(i1 noundef [[C]])
276 ; CGSCC-NEXT: ret i1 [[RC2]]
278 ; CGSCC-NEXT: ret i1 [[RC1]]
280 %rc1 = call i1 @rec(i1 true)
281 br i1 %rc1, label %t, label %f
283 %rc2 = call i1 @rec(i1 %c)
289 define internal i1 @rec(i1 %c1) {
290 ; CHECK-LABEL: define {{[^@]+}}@rec
291 ; CHECK-SAME: (i1 noundef [[C1:%.*]]) {
292 ; CHECK-NEXT: br i1 [[C1]], label [[T:%.*]], label [[F:%.*]]
294 ; CHECK-NEXT: ret i1 true
296 ; CHECK-NEXT: [[R:%.*]] = call i1 @rec(i1 noundef true)
297 ; CHECK-NEXT: call void @unknown()
298 ; CHECK-NEXT: ret i1 false
300 br i1 %c1, label %t, label %f
304 %r = call i1 @rec(i1 true)
310 ; CHECK: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
311 ; CHECK: attributes #[[ATTR1]] = { mustprogress nofree nosync nounwind willreturn memory(none) }
312 ; CHECK: attributes #[[ATTR2]] = { nosync memory(none) }
313 ; CHECK: attributes #[[ATTR3:[0-9]+]] = { memory(none) }
314 ; CHECK: attributes #[[ATTR4]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) }
315 ; CHECK: attributes #[[ATTR5:[0-9]+]] = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
316 ; CHECK: attributes #[[ATTR6]] = { norecurse nosync memory(none) }
317 ; CHECK: attributes #[[ATTR7]] = { null_pointer_is_valid }
318 ; CHECK: attributes #[[ATTR8:[0-9]+]] = { norecurse }
319 ; CHECK: attributes #[[ATTR9]] = { nosync }
320 ; CHECK: attributes #[[ATTR10]] = { nofree willreturn }