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
5 ; FIXME: amdgpu doesn't claim malloc is a thing, so the test is somewhat
6 ; useless except the __kmpc_alloc_shared part which now also covers the important
7 ; part this test was initially designed for, make sure the "is freed" check is
8 ; not sufficient on a GPU.
9 target triple = "amdgcn-amd-amdhsa"
10 target datalayout = "A5"
12 declare noalias ptr @malloc(i64)
14 declare void @nocapture_func_frees_pointer(ptr nocapture)
16 declare void @func_throws(...)
18 declare void @sync_func(ptr %p)
20 declare void @sync_will_return(ptr %p) willreturn nounwind
22 declare void @no_sync_func(ptr nocapture %p) nofree nosync willreturn
24 declare void @nofree_func(ptr nocapture %p) nofree nosync willreturn
26 declare void @usei8(ptr %p)
27 declare void @foo(ptr %p)
29 declare void @foo_nounw(ptr %p) nounwind nofree
31 declare i32 @no_return_call() noreturn
33 declare void @free(ptr nocapture)
35 declare void @llvm.lifetime.start.p0(i64, ptr nocapture) nounwind
38 ; CHECK: @G = internal global ptr undef, align 4
39 ; CHECK: @Gtl = internal thread_local global ptr undef, align 4
41 define void @nofree_arg_only(ptr %p1, ptr %p2) {
42 ; CHECK-LABEL: define {{[^@]+}}@nofree_arg_only
43 ; CHECK-SAME: (ptr nocapture nofree [[P1:%.*]], ptr nocapture [[P2:%.*]]) {
45 ; CHECK-NEXT: tail call void @free(ptr nocapture [[P2]])
46 ; CHECK-NEXT: tail call void @nofree_func(ptr nocapture nofree [[P1]])
47 ; CHECK-NEXT: ret void
50 tail call void @free(ptr %p2)
51 tail call void @nofree_func(ptr %p1)
55 ; TEST 1 - negative, pointer freed in another function.
57 define void @test1() {
58 ; CHECK-LABEL: define {{[^@]+}}@test1() {
60 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
61 ; CHECK-NEXT: tail call void @nocapture_func_frees_pointer(ptr noalias nocapture [[I]])
62 ; CHECK-NEXT: tail call void (...) @func_throws()
63 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture [[I]])
64 ; CHECK-NEXT: ret void
67 %i = tail call noalias ptr @malloc(i64 4)
68 tail call void @nocapture_func_frees_pointer(ptr %i)
69 tail call void (...) @func_throws()
70 tail call void @free(ptr %i)
74 ; TEST 2 - negative, call to a sync function.
76 define void @test2() {
77 ; CHECK-LABEL: define {{[^@]+}}@test2() {
79 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
80 ; CHECK-NEXT: tail call void @sync_func(ptr [[I]])
81 ; CHECK-NEXT: tail call void @free(ptr nocapture [[I]])
82 ; CHECK-NEXT: ret void
85 %i = tail call noalias ptr @malloc(i64 4)
86 tail call void @sync_func(ptr %i)
87 tail call void @free(ptr %i)
91 ; TEST 3 - 1 malloc, 1 free
93 define void @test3() {
94 ; CHECK-LABEL: define {{[^@]+}}@test3() {
96 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
97 ; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nocapture nofree [[I]])
98 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture [[I]])
99 ; CHECK-NEXT: ret void
102 %i = tail call noalias ptr @malloc(i64 4)
103 tail call void @no_sync_func(ptr %i)
104 tail call void @free(ptr %i)
108 define void @test3a(ptr %p) {
109 ; CHECK-LABEL: define {{[^@]+}}@test3a
110 ; CHECK-SAME: (ptr nocapture [[P:%.*]]) {
112 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
113 ; CHECK-NEXT: tail call void @nofree_arg_only(ptr noalias nocapture nofree [[I]], ptr nocapture [[P]])
114 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture [[I]])
115 ; CHECK-NEXT: ret void
118 %i = tail call noalias ptr @malloc(i64 4)
119 tail call void @nofree_arg_only(ptr %i, ptr %p)
120 tail call void @free(ptr %i)
124 declare noalias ptr @aligned_alloc(i64, i64)
126 define void @test3b(ptr %p) {
127 ; CHECK-LABEL: define {{[^@]+}}@test3b
128 ; CHECK-SAME: (ptr nocapture [[P:%.*]]) {
130 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @aligned_alloc(i64 noundef 32, i64 noundef 128)
131 ; CHECK-NEXT: tail call void @nofree_arg_only(ptr noalias nocapture nofree [[I]], ptr nocapture [[P]])
132 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture [[I]])
133 ; CHECK-NEXT: ret void
136 %i = tail call noalias ptr @aligned_alloc(i64 32, i64 128)
137 tail call void @nofree_arg_only(ptr %i, ptr %p)
138 tail call void @free(ptr %i)
142 ; leave alone non-constant alignments.
143 define void @test3c(i64 %alignment) {
144 ; CHECK-LABEL: define {{[^@]+}}@test3c
145 ; CHECK-SAME: (i64 [[ALIGNMENT:%.*]]) {
147 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @aligned_alloc(i64 [[ALIGNMENT]], i64 noundef 128)
148 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture [[I]])
149 ; CHECK-NEXT: ret void
152 %i = tail call noalias ptr @aligned_alloc(i64 %alignment, i64 128)
153 tail call void @free(ptr %i)
157 declare noalias ptr @calloc(i64, i64)
159 define void @test0() {
160 ; CHECK-LABEL: define {{[^@]+}}@test0() {
162 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @calloc(i64 noundef 2, i64 noundef 4)
163 ; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nocapture nofree [[I]])
164 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture [[I]])
165 ; CHECK-NEXT: ret void
168 %i = tail call noalias ptr @calloc(i64 2, i64 4)
169 tail call void @no_sync_func(ptr %i)
170 tail call void @free(ptr %i)
175 define void @test4() {
176 ; CHECK-LABEL: define {{[^@]+}}@test4() {
178 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
179 ; CHECK-NEXT: tail call void @nofree_func(ptr noalias nocapture nofree [[I]])
180 ; CHECK-NEXT: ret void
183 %i = tail call noalias ptr @malloc(i64 4)
184 tail call void @nofree_func(ptr %i)
188 ; TEST 5 - not all exit paths have a call to free, but all uses of malloc
189 ; are in nofree functions and are not captured
191 define void @test5(i32 %arg, ptr %p) {
192 ; CHECK-LABEL: define {{[^@]+}}@test5
193 ; CHECK-SAME: (i32 [[ARG:%.*]], ptr nocapture [[P:%.*]]) {
195 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
196 ; CHECK-NEXT: [[I1:%.*]] = icmp eq i32 [[ARG]], 0
197 ; CHECK-NEXT: br i1 [[I1]], label [[BB3:%.*]], label [[BB2:%.*]]
199 ; CHECK-NEXT: tail call void @nofree_func(ptr noalias nocapture nofree [[I]])
200 ; CHECK-NEXT: br label [[BB4:%.*]]
202 ; CHECK-NEXT: tail call void @nofree_arg_only(ptr noalias nocapture nofree [[I]], ptr nocapture [[P]])
203 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture [[I]])
204 ; CHECK-NEXT: br label [[BB4]]
206 ; CHECK-NEXT: ret void
209 %i = tail call noalias ptr @malloc(i64 4)
210 %i1 = icmp eq i32 %arg, 0
211 br i1 %i1, label %bb3, label %bb2
214 tail call void @nofree_func(ptr %i)
218 tail call void @nofree_arg_only(ptr %i, ptr %p)
219 tail call void @free(ptr %i)
226 ; TEST 6 - all exit paths have a call to free
228 define void @test6(i32 %arg) {
229 ; CHECK-LABEL: define {{[^@]+}}@test6
230 ; CHECK-SAME: (i32 [[ARG:%.*]]) {
232 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
233 ; CHECK-NEXT: [[I1:%.*]] = icmp eq i32 [[ARG]], 0
234 ; CHECK-NEXT: br i1 [[I1]], label [[BB3:%.*]], label [[BB2:%.*]]
236 ; CHECK-NEXT: tail call void @nofree_func(ptr noalias nocapture nofree [[I]])
237 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture [[I]])
238 ; CHECK-NEXT: br label [[BB4:%.*]]
240 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture [[I]])
241 ; CHECK-NEXT: br label [[BB4]]
243 ; CHECK-NEXT: ret void
246 %i = tail call noalias ptr @malloc(i64 4)
247 %i1 = icmp eq i32 %arg, 0
248 br i1 %i1, label %bb3, label %bb2
251 tail call void @nofree_func(ptr %i)
252 tail call void @free(ptr %i)
256 tail call void @free(ptr %i)
263 ; TEST 7 - free is dead.
265 define void @test7() {
266 ; CHECK-LABEL: define {{[^@]+}}@test7() {
268 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
269 ; CHECK-NEXT: [[I1:%.*]] = tail call i32 @no_return_call() #[[ATTR3:[0-9]+]]
270 ; CHECK-NEXT: unreachable
273 %i = tail call noalias ptr @malloc(i64 4)
274 %i1 = tail call i32 @no_return_call()
275 tail call void @free(ptr %i)
279 ; TEST 8 - Negative: bitcast pointer used in capture function
281 define void @test8() {
282 ; CHECK-LABEL: define {{[^@]+}}@test8() {
284 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
285 ; CHECK-NEXT: tail call void @no_sync_func(ptr nocapture nofree [[I]])
286 ; CHECK-NEXT: store i32 10, ptr [[I]], align 4
287 ; CHECK-NEXT: tail call void @foo(ptr nonnull align 4 dereferenceable(4) [[I]])
288 ; CHECK-NEXT: tail call void @free(ptr nocapture nonnull align 4 dereferenceable(4) [[I]])
289 ; CHECK-NEXT: ret void
292 %i = tail call noalias ptr @malloc(i64 4)
293 tail call void @no_sync_func(ptr %i)
294 store i32 10, ptr %i, align 4
295 %i2 = load i32, ptr %i, align 4
296 tail call void @foo(ptr %i)
297 tail call void @free(ptr %i)
301 ; TEST 9 - FIXME: malloc should be converted.
302 define void @test9() {
303 ; CHECK-LABEL: define {{[^@]+}}@test9() {
305 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
306 ; CHECK-NEXT: tail call void @no_sync_func(ptr nocapture nofree [[I]])
307 ; CHECK-NEXT: store i32 10, ptr [[I]], align 4
308 ; CHECK-NEXT: tail call void @foo_nounw(ptr nofree nonnull align 4 dereferenceable(4) [[I]]) #[[ATTR6:[0-9]+]]
309 ; CHECK-NEXT: tail call void @free(ptr nocapture nonnull align 4 dereferenceable(4) [[I]])
310 ; CHECK-NEXT: ret void
313 %i = tail call noalias ptr @malloc(i64 4)
314 tail call void @no_sync_func(ptr %i)
315 store i32 10, ptr %i, align 4
316 %i2 = load i32, ptr %i, align 4
317 tail call void @foo_nounw(ptr %i)
318 tail call void @free(ptr %i)
322 ; TEST 10 - 1 malloc, 1 free
324 define i32 @test10() {
325 ; CHECK-LABEL: define {{[^@]+}}@test10() {
327 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
328 ; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nocapture nofree [[I]])
329 ; CHECK-NEXT: store i32 10, ptr [[I]], align 4
330 ; CHECK-NEXT: [[I2:%.*]] = load i32, ptr [[I]], align 4
331 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture nonnull align 4 dereferenceable(4) [[I]])
332 ; CHECK-NEXT: ret i32 [[I2]]
335 %i = tail call noalias ptr @malloc(i64 4)
336 tail call void @no_sync_func(ptr %i)
337 store i32 10, ptr %i, align 4
338 %i2 = load i32, ptr %i, align 4
339 tail call void @free(ptr %i)
343 define i32 @test_lifetime() {
344 ; CHECK-LABEL: define {{[^@]+}}@test_lifetime() {
346 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
347 ; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nocapture nofree [[I]])
348 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 noundef 4, ptr noalias nocapture nofree nonnull align 4 dereferenceable(4) [[I]])
349 ; CHECK-NEXT: store i32 10, ptr [[I]], align 4
350 ; CHECK-NEXT: [[I2:%.*]] = load i32, ptr [[I]], align 4
351 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture nonnull align 4 dereferenceable(4) [[I]])
352 ; CHECK-NEXT: ret i32 [[I2]]
355 %i = tail call noalias ptr @malloc(i64 4)
356 tail call void @no_sync_func(ptr %i)
357 call void @llvm.lifetime.start.p0(i64 4, ptr %i)
358 store i32 10, ptr %i, align 4
359 %i2 = load i32, ptr %i, align 4
360 tail call void @free(ptr %i)
366 define void @test11() {
367 ; CHECK-LABEL: define {{[^@]+}}@test11() {
369 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
370 ; CHECK-NEXT: tail call void @sync_will_return(ptr [[I]]) #[[ATTR6]]
371 ; CHECK-NEXT: tail call void @free(ptr nocapture [[I]])
372 ; CHECK-NEXT: ret void
375 %i = tail call noalias ptr @malloc(i64 4)
376 tail call void @sync_will_return(ptr %i)
377 tail call void @free(ptr %i)
382 define i32 @irreducible_cfg(i32 %arg) {
383 ; CHECK-LABEL: define {{[^@]+}}@irreducible_cfg
384 ; CHECK-SAME: (i32 [[ARG:%.*]]) {
386 ; CHECK-NEXT: [[I:%.*]] = call noalias ptr @malloc(i64 noundef 4)
387 ; CHECK-NEXT: store i32 10, ptr [[I]], align 4
388 ; CHECK-NEXT: [[I2:%.*]] = icmp eq i32 [[ARG]], 1
389 ; CHECK-NEXT: br i1 [[I2]], label [[BB3:%.*]], label [[BB5:%.*]]
391 ; CHECK-NEXT: [[I4:%.*]] = add nsw i32 [[ARG]], 5
392 ; CHECK-NEXT: br label [[BB11:%.*]]
394 ; CHECK-NEXT: br label [[BB6:%.*]]
396 ; CHECK-NEXT: [[DOT0:%.*]] = phi i32 [ [[I12:%.*]], [[BB11]] ], [ 1, [[BB5]] ]
397 ; CHECK-NEXT: [[I7:%.*]] = load i32, ptr [[I]], align 4
398 ; CHECK-NEXT: [[I8:%.*]] = add nsw i32 [[I7]], -1
399 ; CHECK-NEXT: store i32 [[I8]], ptr [[I]], align 4
400 ; CHECK-NEXT: [[I9:%.*]] = icmp ne i32 [[I7]], 0
401 ; CHECK-NEXT: br i1 [[I9]], label [[BB10:%.*]], label [[BB13:%.*]]
403 ; CHECK-NEXT: br label [[BB11]]
405 ; CHECK-NEXT: [[DOT1:%.*]] = phi i32 [ [[I4]], [[BB3]] ], [ [[DOT0]], [[BB10]] ]
406 ; CHECK-NEXT: [[I12]] = add nsw i32 [[DOT1]], 1
407 ; CHECK-NEXT: br label [[BB6]]
409 ; CHECK-NEXT: call void @free(ptr noalias nocapture noundef nonnull align 4 dereferenceable(4) [[I]])
410 ; CHECK-NEXT: [[I16:%.*]] = load i32, ptr [[I]], align 4
411 ; CHECK-NEXT: ret i32 [[I16]]
414 %i = call noalias ptr @malloc(i64 4)
415 store i32 10, ptr %i, align 4
416 %i2 = icmp eq i32 %arg, 1
417 br i1 %i2, label %bb3, label %bb5
420 %i4 = add nsw i32 %arg, 5
427 %.0 = phi i32 [ %i12, %bb11 ], [ 1, %bb5 ]
428 %i7 = load i32, ptr %i, align 4
429 %i8 = add nsw i32 %i7, -1
430 store i32 %i8, ptr %i, align 4
431 %i9 = icmp ne i32 %i7, 0
432 br i1 %i9, label %bb10, label %bb13
438 %.1 = phi i32 [ %i4, %bb3 ], [ %.0, %bb10 ]
439 %i12 = add nsw i32 %.1, 1
443 %i14 = load i32, ptr %i, align 4
444 call void @free(ptr %i)
445 %i16 = load i32, ptr %i, align 4
450 define i32 @malloc_in_loop(i32 %arg) {
451 ; CHECK-LABEL: define {{[^@]+}}@malloc_in_loop
452 ; CHECK-SAME: (i32 [[ARG:%.*]]) {
454 ; CHECK-NEXT: [[I:%.*]] = alloca i32, align 4, addrspace(5)
455 ; CHECK-NEXT: [[I1:%.*]] = alloca ptr, align 8, addrspace(5)
456 ; CHECK-NEXT: [[I11:%.*]] = alloca i8, i32 0, align 8, addrspace(5)
457 ; CHECK-NEXT: store i32 [[ARG]], ptr addrspace(5) [[I]], align 4
458 ; CHECK-NEXT: br label [[BB2:%.*]]
460 ; CHECK-NEXT: [[I3:%.*]] = load i32, ptr addrspace(5) [[I]], align 4
461 ; CHECK-NEXT: [[I4:%.*]] = add nsw i32 [[I3]], -1
462 ; CHECK-NEXT: store i32 [[I4]], ptr addrspace(5) [[I]], align 4
463 ; CHECK-NEXT: [[I5:%.*]] = icmp sgt i32 [[I4]], 0
464 ; CHECK-NEXT: br i1 [[I5]], label [[BB6:%.*]], label [[BB9:%.*]]
466 ; CHECK-NEXT: [[I7:%.*]] = call noalias ptr @malloc(i64 noundef 4)
467 ; CHECK-NEXT: br label [[BB2]]
469 ; CHECK-NEXT: ret i32 5
472 %i = alloca i32, align 4, addrspace(5)
473 %i1 = alloca ptr, align 8, addrspace(5)
474 store i32 %arg, ptr addrspace(5) %i, align 4
478 %i3 = load i32, ptr addrspace(5) %i, align 4
479 %i4 = add nsw i32 %i3, -1
480 store i32 %i4, ptr addrspace(5) %i, align 4
481 %i5 = icmp sgt i32 %i4, 0
482 br i1 %i5, label %bb6, label %bb9
485 %i7 = call noalias ptr @malloc(i64 4)
486 store i32 1, ptr %i7, align 8
493 ; Malloc/Calloc too large
494 define i32 @test13() {
495 ; CHECK-LABEL: define {{[^@]+}}@test13() {
497 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 256)
498 ; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nocapture nofree [[I]])
499 ; CHECK-NEXT: store i32 10, ptr [[I]], align 4
500 ; CHECK-NEXT: [[I2:%.*]] = load i32, ptr [[I]], align 4
501 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture nonnull align 4 dereferenceable(4) [[I]])
502 ; CHECK-NEXT: ret i32 [[I2]]
505 %i = tail call noalias ptr @malloc(i64 256)
506 tail call void @no_sync_func(ptr %i)
507 store i32 10, ptr %i, align 4
508 %i2 = load i32, ptr %i, align 4
509 tail call void @free(ptr %i)
513 define i32 @test_sle() {
514 ; CHECK-LABEL: define {{[^@]+}}@test_sle() {
516 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef -1)
517 ; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nocapture nofree [[I]])
518 ; CHECK-NEXT: store i32 10, ptr [[I]], align 4
519 ; CHECK-NEXT: [[I2:%.*]] = load i32, ptr [[I]], align 4
520 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture nonnull align 4 dereferenceable(4) [[I]])
521 ; CHECK-NEXT: ret i32 [[I2]]
524 %i = tail call noalias ptr @malloc(i64 -1)
525 tail call void @no_sync_func(ptr %i)
526 store i32 10, ptr %i, align 4
527 %i2 = load i32, ptr %i, align 4
528 tail call void @free(ptr %i)
532 define i32 @test_overflow() {
533 ; CHECK-LABEL: define {{[^@]+}}@test_overflow() {
535 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @calloc(i64 noundef 65537, i64 noundef 65537)
536 ; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nocapture nofree [[I]])
537 ; CHECK-NEXT: store i32 10, ptr [[I]], align 4
538 ; CHECK-NEXT: [[I2:%.*]] = load i32, ptr [[I]], align 4
539 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture nonnull align 4 dereferenceable(4) [[I]])
540 ; CHECK-NEXT: ret i32 [[I2]]
543 %i = tail call noalias ptr @calloc(i64 65537, i64 65537)
544 tail call void @no_sync_func(ptr %i)
545 store i32 10, ptr %i, align 4
546 %i2 = load i32, ptr %i, align 4
547 tail call void @free(ptr %i)
551 define void @test14() {
552 ; CHECK-LABEL: define {{[^@]+}}@test14() {
554 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @calloc(i64 noundef 64, i64 noundef 4)
555 ; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nocapture nofree [[I]])
556 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture [[I]])
557 ; CHECK-NEXT: ret void
560 %i = tail call noalias ptr @calloc(i64 64, i64 4)
561 tail call void @no_sync_func(ptr %i)
562 tail call void @free(ptr %i)
566 define void @test15(i64 %S) {
567 ; CHECK-LABEL: define {{[^@]+}}@test15
568 ; CHECK-SAME: (i64 [[S:%.*]]) {
570 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 [[S]])
571 ; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nocapture nofree [[I]])
572 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture [[I]])
573 ; CHECK-NEXT: ret void
576 %i = tail call noalias ptr @malloc(i64 %S)
577 tail call void @no_sync_func(ptr %i)
578 tail call void @free(ptr %i)
582 define void @test16a(i8 %v, ptr %P) {
583 ; CHECK-LABEL: define {{[^@]+}}@test16a
584 ; CHECK-SAME: (i8 [[V:%.*]], ptr nocapture nofree readnone [[P:%.*]]) {
586 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
587 ; CHECK-NEXT: store i8 [[V]], ptr [[I]], align 1
588 ; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nocapture nofree noundef nonnull dereferenceable(1) [[I]])
589 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture noundef nonnull dereferenceable(1) [[I]])
590 ; CHECK-NEXT: ret void
593 %i = tail call noalias ptr @malloc(i64 4)
594 store i8 %v, ptr %i, align 1
595 tail call void @no_sync_func(ptr %i)
596 tail call void @free(ptr nonnull dereferenceable(1) %i)
600 define void @test16b(i8 %v, ptr %P) {
601 ; CHECK-LABEL: define {{[^@]+}}@test16b
602 ; CHECK-SAME: (i8 [[V:%.*]], ptr nocapture nofree writeonly [[P:%.*]]) {
604 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
605 ; CHECK-NEXT: store ptr [[I]], ptr [[P]], align 8
606 ; CHECK-NEXT: tail call void @no_sync_func(ptr nocapture nofree [[I]])
607 ; CHECK-NEXT: tail call void @free(ptr nocapture [[I]])
608 ; CHECK-NEXT: ret void
611 %i = tail call noalias ptr @malloc(i64 4)
612 store ptr %i, ptr %P, align 8
613 tail call void @no_sync_func(ptr %i)
614 tail call void @free(ptr %i)
618 define void @test16c(i8 %v, ptr %P) {
619 ; CHECK-LABEL: define {{[^@]+}}@test16c
620 ; CHECK-SAME: (i8 [[V:%.*]], ptr nocapture nofree writeonly [[P:%.*]]) {
622 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
623 ; CHECK-NEXT: store ptr [[I]], ptr [[P]], align 8
624 ; CHECK-NEXT: tail call void @no_sync_func(ptr nocapture nofree [[I]]) #[[ATTR6]]
625 ; CHECK-NEXT: tail call void @free(ptr nocapture [[I]])
626 ; CHECK-NEXT: ret void
629 %i = tail call noalias ptr @malloc(i64 4)
630 store ptr %i, ptr %P, align 8
631 tail call void @no_sync_func(ptr %i) nounwind
632 tail call void @free(ptr %i)
636 define void @test16d(i8 %v, ptr %P) {
637 ; CHECK-LABEL: define {{[^@]+}}@test16d
638 ; CHECK-SAME: (i8 [[V:%.*]], ptr nocapture nofree writeonly [[P:%.*]]) {
640 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
641 ; CHECK-NEXT: store ptr [[I]], ptr [[P]], align 8
642 ; CHECK-NEXT: ret void
645 %i = tail call noalias ptr @malloc(i64 4)
646 store ptr %i, ptr %P, align 8
650 declare ptr @__kmpc_alloc_shared(i64)
651 declare void @__kmpc_free_shared(ptr nocapture, i64)
653 define void @test17() {
654 ; CHECK-LABEL: define {{[^@]+}}@test17() {
656 ; CHECK-NEXT: [[I_H2S:%.*]] = alloca i8, i64 4, align 1, addrspace(5)
657 ; CHECK-NEXT: [[MALLOC_CAST:%.*]] = addrspacecast ptr addrspace(5) [[I_H2S]] to ptr
658 ; CHECK-NEXT: tail call void @usei8(ptr noalias nocapture nofree [[MALLOC_CAST]]) #[[ATTR7:[0-9]+]]
659 ; CHECK-NEXT: ret void
662 %i = tail call noalias ptr @__kmpc_alloc_shared(i64 4)
663 tail call void @usei8(ptr nocapture nofree %i) nosync nounwind willreturn
664 tail call void @__kmpc_free_shared(ptr %i, i64 4)
668 define void @test17b() {
669 ; CHECK-LABEL: define {{[^@]+}}@test17b() {
671 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @__kmpc_alloc_shared(i64 noundef 4)
672 ; CHECK-NEXT: tail call void @usei8(ptr nofree [[I]]) #[[ATTR7]]
673 ; CHECK-NEXT: tail call void @__kmpc_free_shared(ptr nocapture [[I]], i64 noundef 4)
674 ; CHECK-NEXT: ret void
677 %i = tail call noalias ptr @__kmpc_alloc_shared(i64 4)
678 tail call void @usei8(ptr nofree %i) nosync nounwind willreturn
679 tail call void @__kmpc_free_shared(ptr %i, i64 4)
683 define void @move_alloca() {
684 ; CHECK-LABEL: define {{[^@]+}}@move_alloca() {
686 ; CHECK-NEXT: [[I_H2S:%.*]] = alloca i8, i64 4, align 1, addrspace(5)
687 ; CHECK-NEXT: br label [[NOT_ENTRY:%.*]]
689 ; CHECK-NEXT: [[MALLOC_CAST:%.*]] = addrspacecast ptr addrspace(5) [[I_H2S]] to ptr
690 ; CHECK-NEXT: tail call void @usei8(ptr noalias nocapture nofree [[MALLOC_CAST]]) #[[ATTR7]]
691 ; CHECK-NEXT: ret void
697 %i = tail call noalias ptr @__kmpc_alloc_shared(i64 4)
698 tail call void @usei8(ptr nocapture nofree %i) nosync nounwind willreturn
699 tail call void @__kmpc_free_shared(ptr %i, i64 4)
703 @G = internal global ptr undef, align 4
704 define void @test16e(i8 %v) norecurse {
705 ; CHECK: Function Attrs: norecurse
706 ; CHECK-LABEL: define {{[^@]+}}@test16e
707 ; CHECK-SAME: (i8 [[V:%.*]]) #[[ATTR5:[0-9]+]] {
709 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @__kmpc_alloc_shared(i64 noundef 4)
710 ; CHECK-NEXT: store ptr [[I]], ptr @G, align 8
711 ; CHECK-NEXT: call void @usei8(ptr nocapture nofree [[I]]) #[[ATTR8:[0-9]+]]
712 ; CHECK-NEXT: tail call void @__kmpc_free_shared(ptr noalias nocapture [[I]], i64 noundef 4)
713 ; CHECK-NEXT: ret void
716 %i = tail call noalias ptr @__kmpc_alloc_shared(i64 4)
717 store ptr %i, ptr @G, align 8
718 %i1 = load ptr, ptr @G, align 8
719 call void @usei8(ptr nocapture nofree %i1) nocallback nosync nounwind willreturn
720 tail call void @__kmpc_free_shared(ptr %i, i64 4)
724 @Gtl = internal thread_local global ptr undef, align 4
725 define void @test16f(i8 %v) norecurse {
726 ; CHECK: Function Attrs: norecurse
727 ; CHECK-LABEL: define {{[^@]+}}@test16f
728 ; CHECK-SAME: (i8 [[V:%.*]]) #[[ATTR5]] {
730 ; CHECK-NEXT: [[I_H2S:%.*]] = alloca i8, i64 4, align 1, addrspace(5)
731 ; CHECK-NEXT: [[MALLOC_CAST:%.*]] = addrspacecast ptr addrspace(5) [[I_H2S]] to ptr
732 ; CHECK-NEXT: store ptr [[MALLOC_CAST]], ptr @Gtl, align 8
733 ; CHECK-NEXT: call void @usei8(ptr nocapture nofree [[MALLOC_CAST]]) #[[ATTR8]]
734 ; CHECK-NEXT: ret void
737 %i = tail call noalias ptr @__kmpc_alloc_shared(i64 4)
738 store ptr %i, ptr @Gtl, align 8
739 %i1 = load ptr, ptr @Gtl, align 8
740 call void @usei8(ptr nocapture nofree %i1) nocallback nosync nounwind willreturn
741 tail call void @__kmpc_free_shared(ptr %i, i64 4)
745 define void @convert_large_kmpc_alloc_shared() {
746 ; CHECK-LABEL: define {{[^@]+}}@convert_large_kmpc_alloc_shared() {
748 ; CHECK-NEXT: [[I_H2S:%.*]] = alloca i8, i64 256, align 1, addrspace(5)
749 ; CHECK-NEXT: [[MALLOC_CAST:%.*]] = addrspacecast ptr addrspace(5) [[I_H2S]] to ptr
750 ; CHECK-NEXT: tail call void @usei8(ptr noalias nocapture nofree [[MALLOC_CAST]]) #[[ATTR7]]
751 ; CHECK-NEXT: ret void
754 %i = tail call noalias ptr @__kmpc_alloc_shared(i64 256)
755 tail call void @usei8(ptr nocapture nofree %i) nosync nounwind willreturn
756 tail call void @__kmpc_free_shared(ptr %i, i64 256)
762 ; CHECK: attributes #[[ATTR0:[0-9]+]] = { nounwind willreturn }
763 ; CHECK: attributes #[[ATTR1:[0-9]+]] = { nofree nosync willreturn }
764 ; CHECK: attributes #[[ATTR2:[0-9]+]] = { nofree nounwind }
765 ; CHECK: attributes #[[ATTR3]] = { noreturn }
766 ; CHECK: attributes #[[ATTR4:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
767 ; CHECK: attributes #[[ATTR5]] = { norecurse }
768 ; CHECK: attributes #[[ATTR6]] = { nounwind }
769 ; CHECK: attributes #[[ATTR7]] = { nosync nounwind willreturn }
770 ; CHECK: attributes #[[ATTR8]] = { nocallback nosync nounwind willreturn }
772 ;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line: