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:[a-zA-Z0-9_$"\\.-]+]] = internal global ptr undef, align 4
39 ; CHECK: @[[GTL:[a-zA-Z0-9_$"\\.-]+]] = 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
455 ; CHECK-NEXT: [[I1:%.*]] = alloca ptr, align 8
456 ; CHECK-NEXT: store i32 [[ARG]], ptr [[I]], align 4
457 ; CHECK-NEXT: br label [[BB2:%.*]]
459 ; CHECK-NEXT: [[I3:%.*]] = load i32, ptr [[I]], align 4
460 ; CHECK-NEXT: [[I4:%.*]] = add nsw i32 [[I3]], -1
461 ; CHECK-NEXT: store i32 [[I4]], ptr [[I]], align 4
462 ; CHECK-NEXT: [[I5:%.*]] = icmp sgt i32 [[I4]], 0
463 ; CHECK-NEXT: br i1 [[I5]], label [[BB6:%.*]], label [[BB9:%.*]]
465 ; CHECK-NEXT: [[I7:%.*]] = call noalias ptr @malloc(i64 noundef 4)
466 ; CHECK-NEXT: br label [[BB2]]
468 ; CHECK-NEXT: ret i32 5
471 %i = alloca i32, align 4
472 %i1 = alloca ptr, align 8
473 store i32 %arg, ptr %i, align 4
477 %i3 = load i32, ptr %i, align 4
478 %i4 = add nsw i32 %i3, -1
479 store i32 %i4, ptr %i, align 4
480 %i5 = icmp sgt i32 %i4, 0
481 br i1 %i5, label %bb6, label %bb9
484 %i7 = call noalias ptr @malloc(i64 4)
485 store i32 1, ptr %i7, align 8
492 ; Malloc/Calloc too large
493 define i32 @test13() {
494 ; CHECK-LABEL: define {{[^@]+}}@test13() {
496 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 256)
497 ; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nocapture nofree [[I]])
498 ; CHECK-NEXT: store i32 10, ptr [[I]], align 4
499 ; CHECK-NEXT: [[I2:%.*]] = load i32, ptr [[I]], align 4
500 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture nonnull align 4 dereferenceable(4) [[I]])
501 ; CHECK-NEXT: ret i32 [[I2]]
504 %i = tail call noalias ptr @malloc(i64 256)
505 tail call void @no_sync_func(ptr %i)
506 store i32 10, ptr %i, align 4
507 %i2 = load i32, ptr %i, align 4
508 tail call void @free(ptr %i)
512 define i32 @test_sle() {
513 ; CHECK-LABEL: define {{[^@]+}}@test_sle() {
515 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef -1)
516 ; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nocapture nofree [[I]])
517 ; CHECK-NEXT: store i32 10, ptr [[I]], align 4
518 ; CHECK-NEXT: [[I2:%.*]] = load i32, ptr [[I]], align 4
519 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture nonnull align 4 dereferenceable(4) [[I]])
520 ; CHECK-NEXT: ret i32 [[I2]]
523 %i = tail call noalias ptr @malloc(i64 -1)
524 tail call void @no_sync_func(ptr %i)
525 store i32 10, ptr %i, align 4
526 %i2 = load i32, ptr %i, align 4
527 tail call void @free(ptr %i)
531 define i32 @test_overflow() {
532 ; CHECK-LABEL: define {{[^@]+}}@test_overflow() {
534 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @calloc(i64 noundef 65537, i64 noundef 65537)
535 ; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nocapture nofree [[I]])
536 ; CHECK-NEXT: store i32 10, ptr [[I]], align 4
537 ; CHECK-NEXT: [[I2:%.*]] = load i32, ptr [[I]], align 4
538 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture nonnull align 4 dereferenceable(4) [[I]])
539 ; CHECK-NEXT: ret i32 [[I2]]
542 %i = tail call noalias ptr @calloc(i64 65537, i64 65537)
543 tail call void @no_sync_func(ptr %i)
544 store i32 10, ptr %i, align 4
545 %i2 = load i32, ptr %i, align 4
546 tail call void @free(ptr %i)
550 define void @test14() {
551 ; CHECK-LABEL: define {{[^@]+}}@test14() {
553 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @calloc(i64 noundef 64, i64 noundef 4)
554 ; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nocapture nofree [[I]])
555 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture [[I]])
556 ; CHECK-NEXT: ret void
559 %i = tail call noalias ptr @calloc(i64 64, i64 4)
560 tail call void @no_sync_func(ptr %i)
561 tail call void @free(ptr %i)
565 define void @test15(i64 %S) {
566 ; CHECK-LABEL: define {{[^@]+}}@test15
567 ; CHECK-SAME: (i64 [[S:%.*]]) {
569 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 [[S]])
570 ; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nocapture nofree [[I]])
571 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture [[I]])
572 ; CHECK-NEXT: ret void
575 %i = tail call noalias ptr @malloc(i64 %S)
576 tail call void @no_sync_func(ptr %i)
577 tail call void @free(ptr %i)
581 define void @test16a(i8 %v, ptr %P) {
582 ; CHECK-LABEL: define {{[^@]+}}@test16a
583 ; CHECK-SAME: (i8 [[V:%.*]], ptr nocapture nofree readnone [[P:%.*]]) {
585 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
586 ; CHECK-NEXT: store i8 [[V]], ptr [[I]], align 1
587 ; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nocapture nofree noundef nonnull dereferenceable(1) [[I]])
588 ; CHECK-NEXT: tail call void @free(ptr noalias nocapture noundef nonnull dereferenceable(1) [[I]])
589 ; CHECK-NEXT: ret void
592 %i = tail call noalias ptr @malloc(i64 4)
593 store i8 %v, ptr %i, align 1
594 tail call void @no_sync_func(ptr %i)
595 tail call void @free(ptr nonnull dereferenceable(1) %i)
599 define void @test16b(i8 %v, ptr %P) {
600 ; CHECK-LABEL: define {{[^@]+}}@test16b
601 ; CHECK-SAME: (i8 [[V:%.*]], ptr nocapture nofree writeonly [[P:%.*]]) {
603 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
604 ; CHECK-NEXT: store ptr [[I]], ptr [[P]], align 8
605 ; CHECK-NEXT: tail call void @no_sync_func(ptr nocapture nofree [[I]])
606 ; CHECK-NEXT: tail call void @free(ptr nocapture [[I]])
607 ; CHECK-NEXT: ret void
610 %i = tail call noalias ptr @malloc(i64 4)
611 store ptr %i, ptr %P, align 8
612 tail call void @no_sync_func(ptr %i)
613 tail call void @free(ptr %i)
617 define void @test16c(i8 %v, ptr %P) {
618 ; CHECK-LABEL: define {{[^@]+}}@test16c
619 ; CHECK-SAME: (i8 [[V:%.*]], ptr nocapture nofree writeonly [[P:%.*]]) {
621 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
622 ; CHECK-NEXT: store ptr [[I]], ptr [[P]], align 8
623 ; CHECK-NEXT: tail call void @no_sync_func(ptr nocapture nofree [[I]]) #[[ATTR6]]
624 ; CHECK-NEXT: tail call void @free(ptr nocapture [[I]])
625 ; CHECK-NEXT: ret void
628 %i = tail call noalias ptr @malloc(i64 4)
629 store ptr %i, ptr %P, align 8
630 tail call void @no_sync_func(ptr %i) nounwind
631 tail call void @free(ptr %i)
635 define void @test16d(i8 %v, ptr %P) {
636 ; CHECK-LABEL: define {{[^@]+}}@test16d
637 ; CHECK-SAME: (i8 [[V:%.*]], ptr nocapture nofree writeonly [[P:%.*]]) {
639 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4)
640 ; CHECK-NEXT: store ptr [[I]], ptr [[P]], align 8
641 ; CHECK-NEXT: ret void
644 %i = tail call noalias ptr @malloc(i64 4)
645 store ptr %i, ptr %P, align 8
649 declare ptr @__kmpc_alloc_shared(i64)
650 declare void @__kmpc_free_shared(ptr nocapture, i64)
652 define void @test17() {
653 ; CHECK-LABEL: define {{[^@]+}}@test17() {
655 ; CHECK-NEXT: [[I_H2S:%.*]] = alloca i8, i64 4, align 1, addrspace(5)
656 ; CHECK-NEXT: [[MALLOC_CAST:%.*]] = addrspacecast ptr addrspace(5) [[I_H2S]] to ptr
657 ; CHECK-NEXT: tail call void @usei8(ptr noalias nocapture nofree [[MALLOC_CAST]]) #[[ATTR7:[0-9]+]]
658 ; CHECK-NEXT: ret void
661 %i = tail call noalias ptr @__kmpc_alloc_shared(i64 4)
662 tail call void @usei8(ptr nocapture nofree %i) nosync nounwind willreturn
663 tail call void @__kmpc_free_shared(ptr %i, i64 4)
667 define void @test17b() {
668 ; CHECK-LABEL: define {{[^@]+}}@test17b() {
670 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @__kmpc_alloc_shared(i64 noundef 4)
671 ; CHECK-NEXT: tail call void @usei8(ptr nofree [[I]]) #[[ATTR7]]
672 ; CHECK-NEXT: tail call void @__kmpc_free_shared(ptr nocapture [[I]], i64 noundef 4)
673 ; CHECK-NEXT: ret void
676 %i = tail call noalias ptr @__kmpc_alloc_shared(i64 4)
677 tail call void @usei8(ptr nofree %i) nosync nounwind willreturn
678 tail call void @__kmpc_free_shared(ptr %i, i64 4)
682 define void @move_alloca() {
683 ; CHECK-LABEL: define {{[^@]+}}@move_alloca() {
685 ; CHECK-NEXT: [[I_H2S:%.*]] = alloca i8, i64 4, align 1, addrspace(5)
686 ; CHECK-NEXT: br label [[NOT_ENTRY:%.*]]
688 ; CHECK-NEXT: [[MALLOC_CAST:%.*]] = addrspacecast ptr addrspace(5) [[I_H2S]] to ptr
689 ; CHECK-NEXT: tail call void @usei8(ptr noalias nocapture nofree [[MALLOC_CAST]]) #[[ATTR7]]
690 ; CHECK-NEXT: ret void
696 %i = tail call noalias ptr @__kmpc_alloc_shared(i64 4)
697 tail call void @usei8(ptr nocapture nofree %i) nosync nounwind willreturn
698 tail call void @__kmpc_free_shared(ptr %i, i64 4)
702 @G = internal global ptr undef, align 4
703 define void @test16e(i8 %v) norecurse {
704 ; CHECK: Function Attrs: norecurse
705 ; CHECK-LABEL: define {{[^@]+}}@test16e
706 ; CHECK-SAME: (i8 [[V:%.*]]) #[[ATTR5:[0-9]+]] {
708 ; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @__kmpc_alloc_shared(i64 noundef 4)
709 ; CHECK-NEXT: store ptr [[I]], ptr @G, align 8
710 ; CHECK-NEXT: call void @usei8(ptr nocapture nofree [[I]]) #[[ATTR8:[0-9]+]]
711 ; CHECK-NEXT: tail call void @__kmpc_free_shared(ptr noalias nocapture [[I]], i64 noundef 4)
712 ; CHECK-NEXT: ret void
715 %i = tail call noalias ptr @__kmpc_alloc_shared(i64 4)
716 store ptr %i, ptr @G, align 8
717 %i1 = load ptr, ptr @G, align 8
718 call void @usei8(ptr nocapture nofree %i1) nocallback nosync nounwind willreturn
719 tail call void @__kmpc_free_shared(ptr %i, i64 4)
723 @Gtl = internal thread_local global ptr undef, align 4
724 define void @test16f(i8 %v) norecurse {
725 ; CHECK: Function Attrs: norecurse
726 ; CHECK-LABEL: define {{[^@]+}}@test16f
727 ; CHECK-SAME: (i8 [[V:%.*]]) #[[ATTR5]] {
729 ; CHECK-NEXT: [[I_H2S:%.*]] = alloca i8, i64 4, align 1, addrspace(5)
730 ; CHECK-NEXT: [[MALLOC_CAST:%.*]] = addrspacecast ptr addrspace(5) [[I_H2S]] to ptr
731 ; CHECK-NEXT: store ptr [[MALLOC_CAST]], ptr @Gtl, align 8
732 ; CHECK-NEXT: call void @usei8(ptr nocapture nofree [[MALLOC_CAST]]) #[[ATTR8]]
733 ; CHECK-NEXT: ret void
736 %i = tail call noalias ptr @__kmpc_alloc_shared(i64 4)
737 store ptr %i, ptr @Gtl, align 8
738 %i1 = load ptr, ptr @Gtl, align 8
739 call void @usei8(ptr nocapture nofree %i1) nocallback nosync nounwind willreturn
740 tail call void @__kmpc_free_shared(ptr %i, i64 4)
744 define void @convert_large_kmpc_alloc_shared() {
745 ; CHECK-LABEL: define {{[^@]+}}@convert_large_kmpc_alloc_shared() {
747 ; CHECK-NEXT: [[I_H2S:%.*]] = alloca i8, i64 256, align 1, addrspace(5)
748 ; CHECK-NEXT: [[MALLOC_CAST:%.*]] = addrspacecast ptr addrspace(5) [[I_H2S]] to ptr
749 ; CHECK-NEXT: tail call void @usei8(ptr noalias nocapture nofree [[MALLOC_CAST]]) #[[ATTR7]]
750 ; CHECK-NEXT: ret void
753 %i = tail call noalias ptr @__kmpc_alloc_shared(i64 256)
754 tail call void @usei8(ptr nocapture nofree %i) nosync nounwind willreturn
755 tail call void @__kmpc_free_shared(ptr %i, i64 256)
761 ; CHECK: attributes #[[ATTR0:[0-9]+]] = { nounwind willreturn }
762 ; CHECK: attributes #[[ATTR1:[0-9]+]] = { nofree nosync willreturn }
763 ; CHECK: attributes #[[ATTR2:[0-9]+]] = { nofree nounwind }
764 ; CHECK: attributes #[[ATTR3]] = { noreturn }
765 ; CHECK: attributes #[[ATTR4:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
766 ; CHECK: attributes #[[ATTR5]] = { norecurse }
767 ; CHECK: attributes #[[ATTR6]] = { nounwind }
768 ; CHECK: attributes #[[ATTR7]] = { nosync nounwind willreturn }
769 ; CHECK: attributes #[[ATTR8]] = { nocallback nosync nounwind willreturn }
771 ;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line: