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 4 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. 9target triple = "amdgcn-amd-amdhsa" 10target datalayout = "A5" 11 12declare noalias ptr @malloc(i64) 13 14declare void @nocapture_func_frees_pointer(ptr nocapture) 15 16declare void @func_throws(...) 17 18declare void @sync_func(ptr %p) 19 20declare void @sync_will_return(ptr %p) willreturn nounwind 21 22declare void @no_sync_func(ptr nocapture %p) nofree nosync willreturn 23 24declare void @nofree_func(ptr nocapture %p) nofree nosync willreturn 25 26declare void @usei8(ptr %p) 27declare void @foo(ptr %p) 28 29declare void @foo_nounw(ptr %p) nounwind nofree 30 31declare i32 @no_return_call() noreturn 32 33declare void @free(ptr nocapture) 34 35declare void @llvm.lifetime.start.p0(i64, ptr nocapture) nounwind 36 37;. 38; CHECK: @G = internal global ptr undef, align 4 39; CHECK: @Gtl = internal thread_local global ptr undef, align 4 40;. 41define void @nofree_arg_only(ptr %p1, ptr %p2) { 42; CHECK-LABEL: define {{[^@]+}}@nofree_arg_only 43; CHECK-SAME: (ptr nofree captures(none) [[P1:%.*]], ptr captures(none) [[P2:%.*]]) { 44; CHECK-NEXT: bb: 45; CHECK-NEXT: tail call void @free(ptr captures(none) [[P2]]) 46; CHECK-NEXT: tail call void @nofree_func(ptr nofree captures(none) [[P1]]) 47; CHECK-NEXT: ret void 48; 49bb: 50 tail call void @free(ptr %p2) 51 tail call void @nofree_func(ptr %p1) 52 ret void 53} 54 55; TEST 1 - negative, pointer freed in another function. 56 57define void @test1() { 58; CHECK-LABEL: define {{[^@]+}}@test1() { 59; CHECK-NEXT: bb: 60; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4) 61; CHECK-NEXT: tail call void @nocapture_func_frees_pointer(ptr noalias captures(none) [[I]]) 62; CHECK-NEXT: tail call void (...) @func_throws() 63; CHECK-NEXT: tail call void @free(ptr noalias captures(none) [[I]]) 64; CHECK-NEXT: ret void 65; 66bb: 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) 71 ret void 72} 73 74; TEST 2 - negative, call to a sync function. 75 76define void @test2() { 77; CHECK-LABEL: define {{[^@]+}}@test2() { 78; CHECK-NEXT: bb: 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 captures(none) [[I]]) 82; CHECK-NEXT: ret void 83; 84bb: 85 %i = tail call noalias ptr @malloc(i64 4) 86 tail call void @sync_func(ptr %i) 87 tail call void @free(ptr %i) 88 ret void 89} 90 91; TEST 3 - 1 malloc, 1 free 92 93define void @test3() { 94; CHECK-LABEL: define {{[^@]+}}@test3() { 95; CHECK-NEXT: bb: 96; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4) 97; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nofree captures(none) [[I]]) 98; CHECK-NEXT: tail call void @free(ptr noalias captures(none) [[I]]) 99; CHECK-NEXT: ret void 100; 101bb: 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) 105 ret void 106} 107 108define void @test3a(ptr %p) { 109; CHECK-LABEL: define {{[^@]+}}@test3a 110; CHECK-SAME: (ptr captures(none) [[P:%.*]]) { 111; CHECK-NEXT: bb: 112; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4) 113; CHECK-NEXT: tail call void @nofree_arg_only(ptr noalias nofree captures(none) [[I]], ptr captures(none) [[P]]) 114; CHECK-NEXT: tail call void @free(ptr noalias captures(none) [[I]]) 115; CHECK-NEXT: ret void 116; 117bb: 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) 121 ret void 122} 123 124declare noalias ptr @aligned_alloc(i64, i64) 125 126define void @test3b(ptr %p) { 127; CHECK-LABEL: define {{[^@]+}}@test3b 128; CHECK-SAME: (ptr captures(none) [[P:%.*]]) { 129; CHECK-NEXT: bb: 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 nofree captures(none) [[I]], ptr captures(none) [[P]]) 132; CHECK-NEXT: tail call void @free(ptr noalias captures(none) [[I]]) 133; CHECK-NEXT: ret void 134; 135bb: 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) 139 ret void 140} 141 142; leave alone non-constant alignments. 143define void @test3c(i64 %alignment) { 144; CHECK-LABEL: define {{[^@]+}}@test3c 145; CHECK-SAME: (i64 [[ALIGNMENT:%.*]]) { 146; CHECK-NEXT: bb: 147; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @aligned_alloc(i64 [[ALIGNMENT]], i64 noundef 128) 148; CHECK-NEXT: tail call void @free(ptr noalias captures(none) [[I]]) 149; CHECK-NEXT: ret void 150; 151bb: 152 %i = tail call noalias ptr @aligned_alloc(i64 %alignment, i64 128) 153 tail call void @free(ptr %i) 154 ret void 155} 156 157declare noalias ptr @calloc(i64, i64) 158 159define void @test0() { 160; CHECK-LABEL: define {{[^@]+}}@test0() { 161; CHECK-NEXT: bb: 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 nofree captures(none) [[I]]) 164; CHECK-NEXT: tail call void @free(ptr noalias captures(none) [[I]]) 165; CHECK-NEXT: ret void 166; 167bb: 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) 171 ret void 172} 173 174; TEST 4 175define void @test4() { 176; CHECK-LABEL: define {{[^@]+}}@test4() { 177; CHECK-NEXT: bb: 178; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4) 179; CHECK-NEXT: tail call void @nofree_func(ptr noalias nofree captures(none) [[I]]) 180; CHECK-NEXT: ret void 181; 182bb: 183 %i = tail call noalias ptr @malloc(i64 4) 184 tail call void @nofree_func(ptr %i) 185 ret void 186} 187 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 190 191define void @test5(i32 %arg, ptr %p) { 192; CHECK-LABEL: define {{[^@]+}}@test5 193; CHECK-SAME: (i32 [[ARG:%.*]], ptr captures(none) [[P:%.*]]) { 194; CHECK-NEXT: bb: 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:%.*]] 198; CHECK: bb2: 199; CHECK-NEXT: tail call void @nofree_func(ptr noalias nofree captures(none) [[I]]) 200; CHECK-NEXT: br label [[BB4:%.*]] 201; CHECK: bb3: 202; CHECK-NEXT: tail call void @nofree_arg_only(ptr noalias nofree captures(none) [[I]], ptr captures(none) [[P]]) 203; CHECK-NEXT: tail call void @free(ptr noalias captures(none) [[I]]) 204; CHECK-NEXT: br label [[BB4]] 205; CHECK: bb4: 206; CHECK-NEXT: ret void 207; 208bb: 209 %i = tail call noalias ptr @malloc(i64 4) 210 %i1 = icmp eq i32 %arg, 0 211 br i1 %i1, label %bb3, label %bb2 212 213bb2: 214 tail call void @nofree_func(ptr %i) 215 br label %bb4 216 217bb3: 218 tail call void @nofree_arg_only(ptr %i, ptr %p) 219 tail call void @free(ptr %i) 220 br label %bb4 221 222bb4: 223 ret void 224} 225 226; TEST 6 - all exit paths have a call to free 227 228define void @test6(i32 %arg) { 229; CHECK-LABEL: define {{[^@]+}}@test6 230; CHECK-SAME: (i32 [[ARG:%.*]]) { 231; CHECK-NEXT: bb: 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:%.*]] 235; CHECK: bb2: 236; CHECK-NEXT: tail call void @nofree_func(ptr noalias nofree captures(none) [[I]]) 237; CHECK-NEXT: tail call void @free(ptr noalias captures(none) [[I]]) 238; CHECK-NEXT: br label [[BB4:%.*]] 239; CHECK: bb3: 240; CHECK-NEXT: tail call void @free(ptr noalias captures(none) [[I]]) 241; CHECK-NEXT: br label [[BB4]] 242; CHECK: bb4: 243; CHECK-NEXT: ret void 244; 245bb: 246 %i = tail call noalias ptr @malloc(i64 4) 247 %i1 = icmp eq i32 %arg, 0 248 br i1 %i1, label %bb3, label %bb2 249 250bb2: 251 tail call void @nofree_func(ptr %i) 252 tail call void @free(ptr %i) 253 br label %bb4 254 255bb3: 256 tail call void @free(ptr %i) 257 br label %bb4 258 259bb4: 260 ret void 261} 262 263; TEST 7 - free is dead. 264 265define void @test7() { 266; CHECK-LABEL: define {{[^@]+}}@test7() { 267; CHECK-NEXT: bb: 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 271; 272bb: 273 %i = tail call noalias ptr @malloc(i64 4) 274 %i1 = tail call i32 @no_return_call() 275 tail call void @free(ptr %i) 276 ret void 277} 278 279; TEST 8 - Negative: bitcast pointer used in capture function 280 281define void @test8() { 282; CHECK-LABEL: define {{[^@]+}}@test8() { 283; CHECK-NEXT: bb: 284; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4) 285; CHECK-NEXT: tail call void @no_sync_func(ptr nofree captures(none) [[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 nonnull align 4 captures(none) dereferenceable(4) [[I]]) 289; CHECK-NEXT: ret void 290; 291bb: 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) 298 ret void 299} 300 301; TEST 9 - FIXME: malloc should be converted. 302define void @test9() { 303; CHECK-LABEL: define {{[^@]+}}@test9() { 304; CHECK-NEXT: bb: 305; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4) 306; CHECK-NEXT: tail call void @no_sync_func(ptr nofree captures(none) [[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 nonnull align 4 captures(none) dereferenceable(4) [[I]]) 310; CHECK-NEXT: ret void 311; 312bb: 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) 319 ret void 320} 321 322; TEST 10 - 1 malloc, 1 free 323 324define i32 @test10() { 325; CHECK-LABEL: define {{[^@]+}}@test10() { 326; CHECK-NEXT: bb: 327; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4) 328; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nofree captures(none) [[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 nonnull align 4 captures(none) dereferenceable(4) [[I]]) 332; CHECK-NEXT: ret i32 [[I2]] 333; 334bb: 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) 340 ret i32 %i2 341} 342 343define i32 @test_lifetime() { 344; CHECK-LABEL: define {{[^@]+}}@test_lifetime() { 345; CHECK-NEXT: bb: 346; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 4) 347; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nofree captures(none) [[I]]) 348; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 noundef 4, ptr noalias nofree nonnull align 4 captures(none) 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 nonnull align 4 captures(none) dereferenceable(4) [[I]]) 352; CHECK-NEXT: ret i32 [[I2]] 353; 354bb: 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) 361 ret i32 %i2 362} 363 364; TEST 11 365 366define void @test11() { 367; CHECK-LABEL: define {{[^@]+}}@test11() { 368; CHECK-NEXT: bb: 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 captures(none) [[I]]) 372; CHECK-NEXT: ret void 373; 374bb: 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) 378 ret void 379} 380 381; TEST 12 382define i32 @irreducible_cfg(i32 %arg) { 383; CHECK-LABEL: define {{[^@]+}}@irreducible_cfg 384; CHECK-SAME: (i32 [[ARG:%.*]]) { 385; CHECK-NEXT: bb: 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:%.*]] 390; CHECK: bb3: 391; CHECK-NEXT: [[I4:%.*]] = add nsw i32 [[ARG]], 5 392; CHECK-NEXT: br label [[BB11:%.*]] 393; CHECK: bb5: 394; CHECK-NEXT: br label [[BB6:%.*]] 395; CHECK: 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:%.*]] 402; CHECK: bb10: 403; CHECK-NEXT: br label [[BB11]] 404; CHECK: 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]] 408; CHECK: bb13: 409; CHECK-NEXT: call void @free(ptr noalias noundef nonnull align 4 captures(none) dereferenceable(4) [[I]]) 410; CHECK-NEXT: [[I16:%.*]] = load i32, ptr [[I]], align 4 411; CHECK-NEXT: ret i32 [[I16]] 412; 413bb: 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 418 419bb3: 420 %i4 = add nsw i32 %arg, 5 421 br label %bb11 422 423bb5: 424 br label %bb6 425 426bb6: 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 433 434bb10: 435 br label %bb11 436 437bb11: 438 %.1 = phi i32 [ %i4, %bb3 ], [ %.0, %bb10 ] 439 %i12 = add nsw i32 %.1, 1 440 br label %bb6 441 442bb13: 443 %i14 = load i32, ptr %i, align 4 444 call void @free(ptr %i) 445 %i16 = load i32, ptr %i, align 4 446 ret i32 %i16 447} 448 449 450define i32 @malloc_in_loop(i32 %arg) { 451; CHECK-LABEL: define {{[^@]+}}@malloc_in_loop 452; CHECK-SAME: (i32 [[ARG:%.*]]) { 453; CHECK-NEXT: bb: 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:%.*]] 459; CHECK: 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:%.*]] 465; CHECK: bb6: 466; CHECK-NEXT: [[I7:%.*]] = call noalias ptr @malloc(i64 noundef 4) 467; CHECK-NEXT: br label [[BB2]] 468; CHECK: bb9: 469; CHECK-NEXT: ret i32 5 470; 471bb: 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 475 br label %bb2 476 477bb2: 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 483 484bb6: 485 %i7 = call noalias ptr @malloc(i64 4) 486 store i32 1, ptr %i7, align 8 487 br label %bb2 488 489bb9: 490 ret i32 5 491} 492 493; Malloc/Calloc too large 494define i32 @test13() { 495; CHECK-LABEL: define {{[^@]+}}@test13() { 496; CHECK-NEXT: bb: 497; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef 256) 498; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nofree captures(none) [[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 nonnull align 4 captures(none) dereferenceable(4) [[I]]) 502; CHECK-NEXT: ret i32 [[I2]] 503; 504bb: 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) 510 ret i32 %i2 511} 512 513define i32 @test_sle() { 514; CHECK-LABEL: define {{[^@]+}}@test_sle() { 515; CHECK-NEXT: bb: 516; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 noundef -1) 517; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nofree captures(none) [[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 nonnull align 4 captures(none) dereferenceable(4) [[I]]) 521; CHECK-NEXT: ret i32 [[I2]] 522; 523bb: 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) 529 ret i32 %i2 530} 531 532define i32 @test_overflow() { 533; CHECK-LABEL: define {{[^@]+}}@test_overflow() { 534; CHECK-NEXT: bb: 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 nofree captures(none) [[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 nonnull align 4 captures(none) dereferenceable(4) [[I]]) 540; CHECK-NEXT: ret i32 [[I2]] 541; 542bb: 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) 548 ret i32 %i2 549} 550 551define void @test14() { 552; CHECK-LABEL: define {{[^@]+}}@test14() { 553; CHECK-NEXT: bb: 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 nofree captures(none) [[I]]) 556; CHECK-NEXT: tail call void @free(ptr noalias captures(none) [[I]]) 557; CHECK-NEXT: ret void 558; 559bb: 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) 563 ret void 564} 565 566define void @test15(i64 %S) { 567; CHECK-LABEL: define {{[^@]+}}@test15 568; CHECK-SAME: (i64 [[S:%.*]]) { 569; CHECK-NEXT: bb: 570; CHECK-NEXT: [[I:%.*]] = tail call noalias ptr @malloc(i64 [[S]]) 571; CHECK-NEXT: tail call void @no_sync_func(ptr noalias nofree captures(none) [[I]]) 572; CHECK-NEXT: tail call void @free(ptr noalias captures(none) [[I]]) 573; CHECK-NEXT: ret void 574; 575bb: 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) 579 ret void 580} 581 582define void @test16a(i8 %v, ptr %P) { 583; CHECK-LABEL: define {{[^@]+}}@test16a 584; CHECK-SAME: (i8 [[V:%.*]], ptr nofree readnone captures(none) [[P:%.*]]) { 585; CHECK-NEXT: bb: 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 nofree noundef nonnull captures(none) dereferenceable(1) [[I]]) 589; CHECK-NEXT: tail call void @free(ptr noalias noundef nonnull captures(none) dereferenceable(1) [[I]]) 590; CHECK-NEXT: ret void 591; 592bb: 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) 597 ret void 598} 599 600define void @test16b(i8 %v, ptr %P) { 601; CHECK-LABEL: define {{[^@]+}}@test16b 602; CHECK-SAME: (i8 [[V:%.*]], ptr nofree writeonly captures(none) [[P:%.*]]) { 603; CHECK-NEXT: bb: 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 nofree captures(none) [[I]]) 607; CHECK-NEXT: tail call void @free(ptr captures(none) [[I]]) 608; CHECK-NEXT: ret void 609; 610bb: 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) 615 ret void 616} 617 618define void @test16c(i8 %v, ptr %P) { 619; CHECK-LABEL: define {{[^@]+}}@test16c 620; CHECK-SAME: (i8 [[V:%.*]], ptr nofree writeonly captures(none) [[P:%.*]]) { 621; CHECK-NEXT: bb: 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 nofree captures(none) [[I]]) #[[ATTR6]] 625; CHECK-NEXT: tail call void @free(ptr captures(none) [[I]]) 626; CHECK-NEXT: ret void 627; 628bb: 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) 633 ret void 634} 635 636define void @test16d(i8 %v, ptr %P) { 637; CHECK-LABEL: define {{[^@]+}}@test16d 638; CHECK-SAME: (i8 [[V:%.*]], ptr nofree writeonly captures(none) [[P:%.*]]) { 639; CHECK-NEXT: bb: 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 643; 644bb: 645 %i = tail call noalias ptr @malloc(i64 4) 646 store ptr %i, ptr %P, align 8 647 ret void 648} 649 650declare ptr @__kmpc_alloc_shared(i64) 651declare void @__kmpc_free_shared(ptr nocapture, i64) 652 653define void @test17() { 654; CHECK-LABEL: define {{[^@]+}}@test17() { 655; CHECK-NEXT: bb: 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 nofree captures(none) [[MALLOC_CAST]]) #[[ATTR7:[0-9]+]] 659; CHECK-NEXT: ret void 660; 661bb: 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) 665 ret void 666} 667 668define void @test17b() { 669; CHECK-LABEL: define {{[^@]+}}@test17b() { 670; CHECK-NEXT: bb: 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 captures(none) [[I]], i64 noundef 4) 674; CHECK-NEXT: ret void 675; 676bb: 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) 680 ret void 681} 682 683define void @move_alloca() { 684; CHECK-LABEL: define {{[^@]+}}@move_alloca() { 685; CHECK-NEXT: entry: 686; CHECK-NEXT: [[I_H2S:%.*]] = alloca i8, i64 4, align 1, addrspace(5) 687; CHECK-NEXT: br label [[NOT_ENTRY:%.*]] 688; CHECK: not_entry: 689; CHECK-NEXT: [[MALLOC_CAST:%.*]] = addrspacecast ptr addrspace(5) [[I_H2S]] to ptr 690; CHECK-NEXT: tail call void @usei8(ptr noalias nofree captures(none) [[MALLOC_CAST]]) #[[ATTR7]] 691; CHECK-NEXT: ret void 692; 693entry: 694 br label %not_entry 695 696not_entry: 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) 700 ret void 701} 702 703@G = internal global ptr undef, align 4 704define void @test16e(i8 %v) norecurse { 705; CHECK: Function Attrs: norecurse 706; CHECK-LABEL: define {{[^@]+}}@test16e 707; CHECK-SAME: (i8 [[V:%.*]]) #[[ATTR5:[0-9]+]] { 708; CHECK-NEXT: bb: 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 nofree captures(none) [[I]]) #[[ATTR8:[0-9]+]] 712; CHECK-NEXT: tail call void @__kmpc_free_shared(ptr noalias captures(none) [[I]], i64 noundef 4) 713; CHECK-NEXT: ret void 714; 715bb: 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) 721 ret void 722} 723 724@Gtl = internal thread_local global ptr undef, align 4 725define void @test16f(i8 %v) norecurse { 726; CHECK: Function Attrs: norecurse 727; CHECK-LABEL: define {{[^@]+}}@test16f 728; CHECK-SAME: (i8 [[V:%.*]]) #[[ATTR5]] { 729; CHECK-NEXT: bb: 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 nofree captures(none) [[MALLOC_CAST]]) #[[ATTR8]] 734; CHECK-NEXT: ret void 735; 736bb: 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) 742 ret void 743} 744 745define void @convert_large_kmpc_alloc_shared() { 746; CHECK-LABEL: define {{[^@]+}}@convert_large_kmpc_alloc_shared() { 747; CHECK-NEXT: bb: 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 nofree captures(none) [[MALLOC_CAST]]) #[[ATTR7]] 751; CHECK-NEXT: ret void 752; 753bb: 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) 757 ret void 758} 759 760 761;. 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 } 771;. 772;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line: 773; CGSCC: {{.*}} 774; TUNIT: {{.*}} 775