1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes 2; RUN: opt -attributor -enable-new-pm=0 -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=5 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_NPM,NOT_CGSCC_OPM,NOT_TUNIT_NPM,IS__TUNIT____,IS________OPM,IS__TUNIT_OPM 3; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=5 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_OPM,NOT_CGSCC_NPM,NOT_TUNIT_OPM,IS__TUNIT____,IS________NPM,IS__TUNIT_NPM 4; RUN: opt -attributor-cgscc -enable-new-pm=0 -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_NPM,IS__CGSCC____,IS________OPM,IS__CGSCC_OPM 5; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_OPM,IS__CGSCC____,IS________NPM,IS__CGSCC_NPM 6 7target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 8 9; Test cases specifically designed for the "undefined behavior" abstract function attribute. 10; We want to verify that whenever undefined behavior is assumed, the code becomes unreachable. 11; We use FIXME's to indicate problems and missing attributes. 12 13; -- Load tests -- 14 15define void @load_wholly_unreachable() { 16; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 17; IS__TUNIT____-LABEL: define {{[^@]+}}@load_wholly_unreachable 18; IS__TUNIT____-SAME: () [[ATTR0:#.*]] { 19; IS__TUNIT____-NEXT: unreachable 20; 21; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 22; IS__CGSCC____-LABEL: define {{[^@]+}}@load_wholly_unreachable 23; IS__CGSCC____-SAME: () [[ATTR0:#.*]] { 24; IS__CGSCC____-NEXT: unreachable 25; 26 %a = load i32, i32* null 27 ret void 28} 29 30define void @loads_wholly_unreachable() { 31; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 32; IS__TUNIT____-LABEL: define {{[^@]+}}@loads_wholly_unreachable 33; IS__TUNIT____-SAME: () [[ATTR0]] { 34; IS__TUNIT____-NEXT: unreachable 35; 36; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 37; IS__CGSCC____-LABEL: define {{[^@]+}}@loads_wholly_unreachable 38; IS__CGSCC____-SAME: () [[ATTR0]] { 39; IS__CGSCC____-NEXT: unreachable 40; 41 %a = load i32, i32* null 42 %b = load i32, i32* null 43 ret void 44} 45 46 47define void @load_single_bb_unreachable(i1 %cond) { 48; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 49; IS__TUNIT____-LABEL: define {{[^@]+}}@load_single_bb_unreachable 50; IS__TUNIT____-SAME: (i1 [[COND:%.*]]) [[ATTR0]] { 51; IS__TUNIT____-NEXT: br i1 [[COND]], label [[T:%.*]], label [[E:%.*]] 52; IS__TUNIT____: t: 53; IS__TUNIT____-NEXT: unreachable 54; IS__TUNIT____: e: 55; IS__TUNIT____-NEXT: ret void 56; 57; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 58; IS__CGSCC____-LABEL: define {{[^@]+}}@load_single_bb_unreachable 59; IS__CGSCC____-SAME: (i1 [[COND:%.*]]) [[ATTR0]] { 60; IS__CGSCC____-NEXT: br i1 [[COND]], label [[T:%.*]], label [[E:%.*]] 61; IS__CGSCC____: t: 62; IS__CGSCC____-NEXT: unreachable 63; IS__CGSCC____: e: 64; IS__CGSCC____-NEXT: ret void 65; 66 br i1 %cond, label %t, label %e 67t: 68 %b = load i32, i32* null 69 br label %e 70e: 71 ret void 72} 73 74; Note that while the load is removed (because it's unused), the block 75; is not changed to unreachable 76define void @load_null_pointer_is_defined() null_pointer_is_valid { 77; IS__TUNIT____: Function Attrs: nofree nosync nounwind null_pointer_is_valid readnone willreturn 78; IS__TUNIT____-LABEL: define {{[^@]+}}@load_null_pointer_is_defined 79; IS__TUNIT____-SAME: () [[ATTR1:#.*]] { 80; IS__TUNIT____-NEXT: ret void 81; 82; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind null_pointer_is_valid readnone willreturn 83; IS__CGSCC____-LABEL: define {{[^@]+}}@load_null_pointer_is_defined 84; IS__CGSCC____-SAME: () [[ATTR1:#.*]] { 85; IS__CGSCC____-NEXT: ret void 86; 87 %a = load i32, i32* null 88 ret void 89} 90 91define internal i32* @ret_null() { 92; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 93; IS__CGSCC____-LABEL: define {{[^@]+}}@ret_null 94; IS__CGSCC____-SAME: () [[ATTR0]] { 95; IS__CGSCC____-NEXT: ret i32* undef 96; 97 ret i32* null 98} 99 100define void @load_null_propagated() { 101; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 102; IS__TUNIT____-LABEL: define {{[^@]+}}@load_null_propagated 103; IS__TUNIT____-SAME: () [[ATTR0]] { 104; IS__TUNIT____-NEXT: unreachable 105; 106; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 107; IS__CGSCC____-LABEL: define {{[^@]+}}@load_null_propagated 108; IS__CGSCC____-SAME: () [[ATTR0]] { 109; IS__CGSCC____-NEXT: unreachable 110; 111 %ptr = call i32* @ret_null() 112 %a = load i32, i32* %ptr 113 ret void 114} 115 116; -- Store tests -- 117 118define void @store_wholly_unreachable() { 119; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 120; IS__TUNIT____-LABEL: define {{[^@]+}}@store_wholly_unreachable 121; IS__TUNIT____-SAME: () [[ATTR0]] { 122; IS__TUNIT____-NEXT: unreachable 123; 124; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 125; IS__CGSCC____-LABEL: define {{[^@]+}}@store_wholly_unreachable 126; IS__CGSCC____-SAME: () [[ATTR0]] { 127; IS__CGSCC____-NEXT: unreachable 128; 129 store i32 5, i32* null 130 ret void 131} 132 133define void @store_single_bb_unreachable(i1 %cond) { 134; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 135; IS__TUNIT____-LABEL: define {{[^@]+}}@store_single_bb_unreachable 136; IS__TUNIT____-SAME: (i1 [[COND:%.*]]) [[ATTR0]] { 137; IS__TUNIT____-NEXT: br i1 [[COND]], label [[T:%.*]], label [[E:%.*]] 138; IS__TUNIT____: t: 139; IS__TUNIT____-NEXT: unreachable 140; IS__TUNIT____: e: 141; IS__TUNIT____-NEXT: ret void 142; 143; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 144; IS__CGSCC____-LABEL: define {{[^@]+}}@store_single_bb_unreachable 145; IS__CGSCC____-SAME: (i1 [[COND:%.*]]) [[ATTR0]] { 146; IS__CGSCC____-NEXT: br i1 [[COND]], label [[T:%.*]], label [[E:%.*]] 147; IS__CGSCC____: t: 148; IS__CGSCC____-NEXT: unreachable 149; IS__CGSCC____: e: 150; IS__CGSCC____-NEXT: ret void 151; 152 br i1 %cond, label %t, label %e 153t: 154 store i32 5, i32* null 155 br label %e 156e: 157 ret void 158} 159 160define void @store_null_pointer_is_defined() null_pointer_is_valid { 161; IS__TUNIT____: Function Attrs: nofree nosync nounwind null_pointer_is_valid willreturn writeonly 162; IS__TUNIT____-LABEL: define {{[^@]+}}@store_null_pointer_is_defined 163; IS__TUNIT____-SAME: () [[ATTR2:#.*]] { 164; IS__TUNIT____-NEXT: store i32 5, i32* null, align 536870912 165; IS__TUNIT____-NEXT: ret void 166; 167; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind null_pointer_is_valid willreturn writeonly 168; IS__CGSCC____-LABEL: define {{[^@]+}}@store_null_pointer_is_defined 169; IS__CGSCC____-SAME: () [[ATTR2:#.*]] { 170; IS__CGSCC____-NEXT: store i32 5, i32* null, align 536870912 171; IS__CGSCC____-NEXT: ret void 172; 173 store i32 5, i32* null 174 ret void 175} 176 177define void @store_null_propagated() { 178; ATTRIBUTOR-LABEL: @store_null_propagated( 179; ATTRIBUTOR-NEXT: unreachable 180; 181; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 182; IS__TUNIT____-LABEL: define {{[^@]+}}@store_null_propagated 183; IS__TUNIT____-SAME: () [[ATTR0]] { 184; IS__TUNIT____-NEXT: unreachable 185; 186; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 187; IS__CGSCC____-LABEL: define {{[^@]+}}@store_null_propagated 188; IS__CGSCC____-SAME: () [[ATTR0]] { 189; IS__CGSCC____-NEXT: unreachable 190; 191 %ptr = call i32* @ret_null() 192 store i32 5, i32* %ptr 193 ret void 194} 195 196; -- AtomicRMW tests -- 197 198define void @atomicrmw_wholly_unreachable() { 199; IS__TUNIT____: Function Attrs: nofree nounwind readnone willreturn 200; IS__TUNIT____-LABEL: define {{[^@]+}}@atomicrmw_wholly_unreachable 201; IS__TUNIT____-SAME: () [[ATTR3:#.*]] { 202; IS__TUNIT____-NEXT: unreachable 203; 204; IS__CGSCC____: Function Attrs: nofree norecurse nounwind readnone willreturn 205; IS__CGSCC____-LABEL: define {{[^@]+}}@atomicrmw_wholly_unreachable 206; IS__CGSCC____-SAME: () [[ATTR3:#.*]] { 207; IS__CGSCC____-NEXT: unreachable 208; 209 %a = atomicrmw add i32* null, i32 1 acquire 210 ret void 211} 212 213define void @atomicrmw_single_bb_unreachable(i1 %cond) { 214; IS__TUNIT____: Function Attrs: nofree nounwind readnone willreturn 215; IS__TUNIT____-LABEL: define {{[^@]+}}@atomicrmw_single_bb_unreachable 216; IS__TUNIT____-SAME: (i1 [[COND:%.*]]) [[ATTR3]] { 217; IS__TUNIT____-NEXT: br i1 [[COND]], label [[T:%.*]], label [[E:%.*]] 218; IS__TUNIT____: t: 219; IS__TUNIT____-NEXT: unreachable 220; IS__TUNIT____: e: 221; IS__TUNIT____-NEXT: ret void 222; 223; IS__CGSCC____: Function Attrs: nofree norecurse nounwind readnone willreturn 224; IS__CGSCC____-LABEL: define {{[^@]+}}@atomicrmw_single_bb_unreachable 225; IS__CGSCC____-SAME: (i1 [[COND:%.*]]) [[ATTR3]] { 226; IS__CGSCC____-NEXT: br i1 [[COND]], label [[T:%.*]], label [[E:%.*]] 227; IS__CGSCC____: t: 228; IS__CGSCC____-NEXT: unreachable 229; IS__CGSCC____: e: 230; IS__CGSCC____-NEXT: ret void 231; 232 br i1 %cond, label %t, label %e 233t: 234 %a = atomicrmw add i32* null, i32 1 acquire 235 br label %e 236e: 237 ret void 238} 239 240define void @atomicrmw_null_pointer_is_defined() null_pointer_is_valid { 241; IS__TUNIT____: Function Attrs: nofree nounwind null_pointer_is_valid willreturn 242; IS__TUNIT____-LABEL: define {{[^@]+}}@atomicrmw_null_pointer_is_defined 243; IS__TUNIT____-SAME: () [[ATTR4:#.*]] { 244; IS__TUNIT____-NEXT: [[A:%.*]] = atomicrmw add i32* null, i32 1 acquire 245; IS__TUNIT____-NEXT: ret void 246; 247; IS__CGSCC____: Function Attrs: nofree norecurse nounwind null_pointer_is_valid willreturn 248; IS__CGSCC____-LABEL: define {{[^@]+}}@atomicrmw_null_pointer_is_defined 249; IS__CGSCC____-SAME: () [[ATTR4:#.*]] { 250; IS__CGSCC____-NEXT: [[A:%.*]] = atomicrmw add i32* null, i32 1 acquire 251; IS__CGSCC____-NEXT: ret void 252; 253 %a = atomicrmw add i32* null, i32 1 acquire 254 ret void 255} 256 257define void @atomicrmw_null_propagated() { 258; ATTRIBUTOR-LABEL: @atomicrmw_null_propagated( 259; ATTRIBUTOR-NEXT: unreachable 260; 261; IS__TUNIT____: Function Attrs: nofree nounwind readnone willreturn 262; IS__TUNIT____-LABEL: define {{[^@]+}}@atomicrmw_null_propagated 263; IS__TUNIT____-SAME: () [[ATTR3]] { 264; IS__TUNIT____-NEXT: unreachable 265; 266; IS__CGSCC____: Function Attrs: nofree norecurse nounwind readnone willreturn 267; IS__CGSCC____-LABEL: define {{[^@]+}}@atomicrmw_null_propagated 268; IS__CGSCC____-SAME: () [[ATTR3]] { 269; IS__CGSCC____-NEXT: unreachable 270; 271 %ptr = call i32* @ret_null() 272 %a = atomicrmw add i32* %ptr, i32 1 acquire 273 ret void 274} 275 276; -- AtomicCmpXchg tests -- 277 278define void @atomiccmpxchg_wholly_unreachable() { 279; IS__TUNIT____: Function Attrs: nofree nounwind readnone willreturn 280; IS__TUNIT____-LABEL: define {{[^@]+}}@atomiccmpxchg_wholly_unreachable 281; IS__TUNIT____-SAME: () [[ATTR3]] { 282; IS__TUNIT____-NEXT: unreachable 283; 284; IS__CGSCC____: Function Attrs: nofree norecurse nounwind readnone willreturn 285; IS__CGSCC____-LABEL: define {{[^@]+}}@atomiccmpxchg_wholly_unreachable 286; IS__CGSCC____-SAME: () [[ATTR3]] { 287; IS__CGSCC____-NEXT: unreachable 288; 289 %a = cmpxchg i32* null, i32 2, i32 3 acq_rel monotonic 290 ret void 291} 292 293define void @atomiccmpxchg_single_bb_unreachable(i1 %cond) { 294; IS__TUNIT____: Function Attrs: nofree nounwind readnone willreturn 295; IS__TUNIT____-LABEL: define {{[^@]+}}@atomiccmpxchg_single_bb_unreachable 296; IS__TUNIT____-SAME: (i1 [[COND:%.*]]) [[ATTR3]] { 297; IS__TUNIT____-NEXT: br i1 [[COND]], label [[T:%.*]], label [[E:%.*]] 298; IS__TUNIT____: t: 299; IS__TUNIT____-NEXT: unreachable 300; IS__TUNIT____: e: 301; IS__TUNIT____-NEXT: ret void 302; 303; IS__CGSCC____: Function Attrs: nofree norecurse nounwind readnone willreturn 304; IS__CGSCC____-LABEL: define {{[^@]+}}@atomiccmpxchg_single_bb_unreachable 305; IS__CGSCC____-SAME: (i1 [[COND:%.*]]) [[ATTR3]] { 306; IS__CGSCC____-NEXT: br i1 [[COND]], label [[T:%.*]], label [[E:%.*]] 307; IS__CGSCC____: t: 308; IS__CGSCC____-NEXT: unreachable 309; IS__CGSCC____: e: 310; IS__CGSCC____-NEXT: ret void 311; 312 br i1 %cond, label %t, label %e 313t: 314 %a = cmpxchg i32* null, i32 2, i32 3 acq_rel monotonic 315 br label %e 316e: 317 ret void 318} 319 320define void @atomiccmpxchg_null_pointer_is_defined() null_pointer_is_valid { 321; IS__TUNIT____: Function Attrs: nofree nounwind null_pointer_is_valid willreturn 322; IS__TUNIT____-LABEL: define {{[^@]+}}@atomiccmpxchg_null_pointer_is_defined 323; IS__TUNIT____-SAME: () [[ATTR4]] { 324; IS__TUNIT____-NEXT: [[A:%.*]] = cmpxchg i32* null, i32 2, i32 3 acq_rel monotonic 325; IS__TUNIT____-NEXT: ret void 326; 327; IS__CGSCC____: Function Attrs: nofree norecurse nounwind null_pointer_is_valid willreturn 328; IS__CGSCC____-LABEL: define {{[^@]+}}@atomiccmpxchg_null_pointer_is_defined 329; IS__CGSCC____-SAME: () [[ATTR4]] { 330; IS__CGSCC____-NEXT: [[A:%.*]] = cmpxchg i32* null, i32 2, i32 3 acq_rel monotonic 331; IS__CGSCC____-NEXT: ret void 332; 333 %a = cmpxchg i32* null, i32 2, i32 3 acq_rel monotonic 334 ret void 335} 336 337define void @atomiccmpxchg_null_propagated() { 338; ATTRIBUTOR-LABEL: @atomiccmpxchg_null_propagated( 339; ATTRIBUTOR-NEXT: unreachable 340; 341; IS__TUNIT____: Function Attrs: nofree nounwind readnone willreturn 342; IS__TUNIT____-LABEL: define {{[^@]+}}@atomiccmpxchg_null_propagated 343; IS__TUNIT____-SAME: () [[ATTR3]] { 344; IS__TUNIT____-NEXT: unreachable 345; 346; IS__CGSCC____: Function Attrs: nofree norecurse nounwind readnone willreturn 347; IS__CGSCC____-LABEL: define {{[^@]+}}@atomiccmpxchg_null_propagated 348; IS__CGSCC____-SAME: () [[ATTR3]] { 349; IS__CGSCC____-NEXT: unreachable 350; 351 %ptr = call i32* @ret_null() 352 %a = cmpxchg i32* %ptr, i32 2, i32 3 acq_rel monotonic 353 ret void 354} 355 356; -- Conditional branching tests -- 357 358; Note: The unreachable on %t and %e is _not_ from AAUndefinedBehavior 359 360define i32 @cond_br_on_undef() { 361; IS__TUNIT____: Function Attrs: nofree noreturn nosync nounwind readnone willreturn 362; IS__TUNIT____-LABEL: define {{[^@]+}}@cond_br_on_undef 363; IS__TUNIT____-SAME: () [[ATTR5:#.*]] { 364; IS__TUNIT____-NEXT: unreachable 365; IS__TUNIT____: t: 366; IS__TUNIT____-NEXT: unreachable 367; IS__TUNIT____: e: 368; IS__TUNIT____-NEXT: unreachable 369; 370; IS__CGSCC____: Function Attrs: nofree norecurse noreturn nosync nounwind readnone willreturn 371; IS__CGSCC____-LABEL: define {{[^@]+}}@cond_br_on_undef 372; IS__CGSCC____-SAME: () [[ATTR5:#.*]] { 373; IS__CGSCC____-NEXT: unreachable 374; IS__CGSCC____: t: 375; IS__CGSCC____-NEXT: unreachable 376; IS__CGSCC____: e: 377; IS__CGSCC____-NEXT: unreachable 378; 379 br i1 undef, label %t, label %e 380t: 381 ret i32 1 382e: 383 ret i32 2 384} 385 386; More complicated branching 387 ; Valid branch - verify that this is not converted 388 ; to unreachable. 389define void @cond_br_on_undef2(i1 %cond) { 390; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 391; IS__TUNIT____-LABEL: define {{[^@]+}}@cond_br_on_undef2 392; IS__TUNIT____-SAME: (i1 [[COND:%.*]]) [[ATTR0]] { 393; IS__TUNIT____-NEXT: br i1 [[COND]], label [[T1:%.*]], label [[E1:%.*]] 394; IS__TUNIT____: t1: 395; IS__TUNIT____-NEXT: unreachable 396; IS__TUNIT____: t2: 397; IS__TUNIT____-NEXT: unreachable 398; IS__TUNIT____: e2: 399; IS__TUNIT____-NEXT: unreachable 400; IS__TUNIT____: e1: 401; IS__TUNIT____-NEXT: ret void 402; 403; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 404; IS__CGSCC____-LABEL: define {{[^@]+}}@cond_br_on_undef2 405; IS__CGSCC____-SAME: (i1 [[COND:%.*]]) [[ATTR0]] { 406; IS__CGSCC____-NEXT: br i1 [[COND]], label [[T1:%.*]], label [[E1:%.*]] 407; IS__CGSCC____: t1: 408; IS__CGSCC____-NEXT: unreachable 409; IS__CGSCC____: t2: 410; IS__CGSCC____-NEXT: unreachable 411; IS__CGSCC____: e2: 412; IS__CGSCC____-NEXT: unreachable 413; IS__CGSCC____: e1: 414; IS__CGSCC____-NEXT: ret void 415; 416 br i1 %cond, label %t1, label %e1 417t1: 418 br i1 undef, label %t2, label %e2 419t2: 420 ret void 421e2: 422 ret void 423e1: 424 ret void 425} 426 427define i1 @ret_undef() { 428; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 429; IS__TUNIT____-LABEL: define {{[^@]+}}@ret_undef 430; IS__TUNIT____-SAME: () [[ATTR0]] { 431; IS__TUNIT____-NEXT: ret i1 undef 432; 433; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 434; IS__CGSCC____-LABEL: define {{[^@]+}}@ret_undef 435; IS__CGSCC____-SAME: () [[ATTR0]] { 436; IS__CGSCC____-NEXT: ret i1 undef 437; 438 ret i1 undef 439} 440 441define void @cond_br_on_undef_interproc() { 442; IS__TUNIT____: Function Attrs: nofree noreturn nosync nounwind readnone willreturn 443; IS__TUNIT____-LABEL: define {{[^@]+}}@cond_br_on_undef_interproc 444; IS__TUNIT____-SAME: () [[ATTR5]] { 445; IS__TUNIT____-NEXT: unreachable 446; IS__TUNIT____: t: 447; IS__TUNIT____-NEXT: unreachable 448; IS__TUNIT____: e: 449; IS__TUNIT____-NEXT: unreachable 450; 451; IS__CGSCC____: Function Attrs: nofree norecurse noreturn nosync nounwind readnone willreturn 452; IS__CGSCC____-LABEL: define {{[^@]+}}@cond_br_on_undef_interproc 453; IS__CGSCC____-SAME: () [[ATTR5]] { 454; IS__CGSCC____-NEXT: unreachable 455; IS__CGSCC____: t: 456; IS__CGSCC____-NEXT: unreachable 457; IS__CGSCC____: e: 458; IS__CGSCC____-NEXT: unreachable 459; 460 %cond = call i1 @ret_undef() 461 br i1 %cond, label %t, label %e 462t: 463 ret void 464e: 465 ret void 466} 467 468define i1 @ret_undef2() { 469; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 470; IS__TUNIT____-LABEL: define {{[^@]+}}@ret_undef2 471; IS__TUNIT____-SAME: () [[ATTR0]] { 472; IS__TUNIT____-NEXT: br i1 true, label [[T:%.*]], label [[E:%.*]] 473; IS__TUNIT____: t: 474; IS__TUNIT____-NEXT: ret i1 undef 475; IS__TUNIT____: e: 476; IS__TUNIT____-NEXT: unreachable 477; 478; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 479; IS__CGSCC____-LABEL: define {{[^@]+}}@ret_undef2 480; IS__CGSCC____-SAME: () [[ATTR0]] { 481; IS__CGSCC____-NEXT: br i1 true, label [[T:%.*]], label [[E:%.*]] 482; IS__CGSCC____: t: 483; IS__CGSCC____-NEXT: ret i1 undef 484; IS__CGSCC____: e: 485; IS__CGSCC____-NEXT: unreachable 486; 487 br i1 true, label %t, label %e 488t: 489 ret i1 undef 490e: 491 ret i1 undef 492} 493 494; More complicated interproc deduction of undef 495define void @cond_br_on_undef_interproc2() { 496; IS__TUNIT____: Function Attrs: nofree noreturn nosync nounwind readnone willreturn 497; IS__TUNIT____-LABEL: define {{[^@]+}}@cond_br_on_undef_interproc2 498; IS__TUNIT____-SAME: () [[ATTR5]] { 499; IS__TUNIT____-NEXT: unreachable 500; IS__TUNIT____: t: 501; IS__TUNIT____-NEXT: unreachable 502; IS__TUNIT____: e: 503; IS__TUNIT____-NEXT: unreachable 504; 505; IS__CGSCC____: Function Attrs: nofree norecurse noreturn nosync nounwind readnone willreturn 506; IS__CGSCC____-LABEL: define {{[^@]+}}@cond_br_on_undef_interproc2 507; IS__CGSCC____-SAME: () [[ATTR5]] { 508; IS__CGSCC____-NEXT: unreachable 509; IS__CGSCC____: t: 510; IS__CGSCC____-NEXT: unreachable 511; IS__CGSCC____: e: 512; IS__CGSCC____-NEXT: unreachable 513; 514 %cond = call i1 @ret_undef2() 515 br i1 %cond, label %t, label %e 516t: 517 ret void 518e: 519 ret void 520} 521 522; Branch on undef that depends on propagation of 523; undef of a previous instruction. 524define i32 @cond_br_on_undef3() { 525; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 526; IS__TUNIT____-LABEL: define {{[^@]+}}@cond_br_on_undef3 527; IS__TUNIT____-SAME: () [[ATTR0]] { 528; IS__TUNIT____-NEXT: br label [[T:%.*]] 529; IS__TUNIT____: t: 530; IS__TUNIT____-NEXT: ret i32 1 531; IS__TUNIT____: e: 532; IS__TUNIT____-NEXT: unreachable 533; 534; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 535; IS__CGSCC____-LABEL: define {{[^@]+}}@cond_br_on_undef3 536; IS__CGSCC____-SAME: () [[ATTR0]] { 537; IS__CGSCC____-NEXT: br label [[T:%.*]] 538; IS__CGSCC____: t: 539; IS__CGSCC____-NEXT: ret i32 1 540; IS__CGSCC____: e: 541; IS__CGSCC____-NEXT: unreachable 542; 543 %cond = icmp ne i32 1, undef 544 br i1 %cond, label %t, label %e 545t: 546 ret i32 1 547e: 548 ret i32 2 549} 550 551; Branch on undef because of uninitialized value. 552; FIXME: Currently it doesn't propagate the undef. 553define i32 @cond_br_on_undef_uninit() { 554; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 555; IS__TUNIT____-LABEL: define {{[^@]+}}@cond_br_on_undef_uninit 556; IS__TUNIT____-SAME: () [[ATTR0]] { 557; IS__TUNIT____-NEXT: [[ALLOC:%.*]] = alloca i1, align 1 558; IS__TUNIT____-NEXT: [[COND:%.*]] = load i1, i1* [[ALLOC]], align 1 559; IS__TUNIT____-NEXT: br i1 [[COND]], label [[T:%.*]], label [[E:%.*]] 560; IS__TUNIT____: t: 561; IS__TUNIT____-NEXT: ret i32 1 562; IS__TUNIT____: e: 563; IS__TUNIT____-NEXT: ret i32 2 564; 565; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 566; IS__CGSCC____-LABEL: define {{[^@]+}}@cond_br_on_undef_uninit 567; IS__CGSCC____-SAME: () [[ATTR0]] { 568; IS__CGSCC____-NEXT: [[ALLOC:%.*]] = alloca i1, align 1 569; IS__CGSCC____-NEXT: [[COND:%.*]] = load i1, i1* [[ALLOC]], align 1 570; IS__CGSCC____-NEXT: br i1 [[COND]], label [[T:%.*]], label [[E:%.*]] 571; IS__CGSCC____: t: 572; IS__CGSCC____-NEXT: ret i32 1 573; IS__CGSCC____: e: 574; IS__CGSCC____-NEXT: ret i32 2 575; 576 %alloc = alloca i1 577 %cond = load i1, i1* %alloc 578 br i1 %cond, label %t, label %e 579t: 580 ret i32 1 581e: 582 ret i32 2 583} 584 585; Note that the `load` has UB (so it will be changed to unreachable) 586; and the branch is a terminator that can be constant-folded. 587; We want to test that doing both won't cause a segfault. 588; MODULE-NOT: @callee( 589define internal i32 @callee(i1 %C, i32* %A) { 590; 591; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 592; IS__CGSCC____-LABEL: define {{[^@]+}}@callee 593; IS__CGSCC____-SAME: () [[ATTR0]] { 594; IS__CGSCC____-NEXT: entry: 595; IS__CGSCC____-NEXT: unreachable 596; IS__CGSCC____: T: 597; IS__CGSCC____-NEXT: unreachable 598; IS__CGSCC____: F: 599; IS__CGSCC____-NEXT: ret i32 undef 600; 601entry: 602 %A.0 = load i32, i32* null 603 br i1 %C, label %T, label %F 604 605T: 606 ret i32 %A.0 607 608F: 609 ret i32 1 610} 611 612define i32 @foo() { 613; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 614; IS__TUNIT____-LABEL: define {{[^@]+}}@foo 615; IS__TUNIT____-SAME: () [[ATTR0]] { 616; IS__TUNIT____-NEXT: ret i32 1 617; 618; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 619; IS__CGSCC____-LABEL: define {{[^@]+}}@foo 620; IS__CGSCC____-SAME: () [[ATTR0]] { 621; IS__CGSCC____-NEXT: ret i32 1 622; 623 %X = call i32 @callee(i1 false, i32* null) 624 ret i32 %X 625} 626 627; Tests for nonnull noundef attribute violation. 628; 629; Tests for argument position 630 631define void @arg_nonnull_1(i32* nonnull %a) { 632; IS__TUNIT____: Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly 633; IS__TUNIT____-LABEL: define {{[^@]+}}@arg_nonnull_1 634; IS__TUNIT____-SAME: (i32* nocapture nofree nonnull writeonly align 4 dereferenceable(4) [[A:%.*]]) [[ATTR6:#.*]] { 635; IS__TUNIT____-NEXT: store i32 0, i32* [[A]], align 4 636; IS__TUNIT____-NEXT: ret void 637; 638; IS__CGSCC____: Function Attrs: argmemonly nofree norecurse nosync nounwind willreturn writeonly 639; IS__CGSCC____-LABEL: define {{[^@]+}}@arg_nonnull_1 640; IS__CGSCC____-SAME: (i32* nocapture nofree nonnull writeonly align 4 dereferenceable(4) [[A:%.*]]) [[ATTR6:#.*]] { 641; IS__CGSCC____-NEXT: store i32 0, i32* [[A]], align 4 642; IS__CGSCC____-NEXT: ret void 643; 644 store i32 0, i32* %a 645 ret void 646} 647 648define void @arg_nonnull_1_noundef_1(i32* nonnull noundef %a) { 649; IS__TUNIT____: Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly 650; IS__TUNIT____-LABEL: define {{[^@]+}}@arg_nonnull_1_noundef_1 651; IS__TUNIT____-SAME: (i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[A:%.*]]) [[ATTR6]] { 652; IS__TUNIT____-NEXT: store i32 0, i32* [[A]], align 4 653; IS__TUNIT____-NEXT: ret void 654; 655; IS__CGSCC____: Function Attrs: argmemonly nofree norecurse nosync nounwind willreturn writeonly 656; IS__CGSCC____-LABEL: define {{[^@]+}}@arg_nonnull_1_noundef_1 657; IS__CGSCC____-SAME: (i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[A:%.*]]) [[ATTR6]] { 658; IS__CGSCC____-NEXT: store i32 0, i32* [[A]], align 4 659; IS__CGSCC____-NEXT: ret void 660; 661 store i32 0, i32* %a 662 ret void 663} 664 665define void @arg_nonnull_12(i32* nonnull %a, i32* nonnull %b, i32* %c) { 666; IS__TUNIT____: Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly 667; IS__TUNIT____-LABEL: define {{[^@]+}}@arg_nonnull_12 668; IS__TUNIT____-SAME: (i32* nocapture nofree nonnull writeonly [[A:%.*]], i32* nocapture nofree nonnull writeonly [[B:%.*]], i32* nofree writeonly [[C:%.*]]) [[ATTR6]] { 669; IS__TUNIT____-NEXT: [[D:%.*]] = icmp eq i32* [[C]], null 670; IS__TUNIT____-NEXT: br i1 [[D]], label [[T:%.*]], label [[F:%.*]] 671; IS__TUNIT____: t: 672; IS__TUNIT____-NEXT: store i32 0, i32* [[A]], align 4 673; IS__TUNIT____-NEXT: br label [[RET:%.*]] 674; IS__TUNIT____: f: 675; IS__TUNIT____-NEXT: store i32 1, i32* [[B]], align 4 676; IS__TUNIT____-NEXT: br label [[RET]] 677; IS__TUNIT____: ret: 678; IS__TUNIT____-NEXT: ret void 679; 680; IS__CGSCC____: Function Attrs: argmemonly nofree norecurse nosync nounwind willreturn writeonly 681; IS__CGSCC____-LABEL: define {{[^@]+}}@arg_nonnull_12 682; IS__CGSCC____-SAME: (i32* nocapture nofree nonnull writeonly [[A:%.*]], i32* nocapture nofree nonnull writeonly [[B:%.*]], i32* nofree writeonly [[C:%.*]]) [[ATTR6]] { 683; IS__CGSCC____-NEXT: [[D:%.*]] = icmp eq i32* [[C]], null 684; IS__CGSCC____-NEXT: br i1 [[D]], label [[T:%.*]], label [[F:%.*]] 685; IS__CGSCC____: t: 686; IS__CGSCC____-NEXT: store i32 0, i32* [[A]], align 4 687; IS__CGSCC____-NEXT: br label [[RET:%.*]] 688; IS__CGSCC____: f: 689; IS__CGSCC____-NEXT: store i32 1, i32* [[B]], align 4 690; IS__CGSCC____-NEXT: br label [[RET]] 691; IS__CGSCC____: ret: 692; IS__CGSCC____-NEXT: ret void 693; 694 %d = icmp eq i32* %c, null 695 br i1 %d, label %t, label %f 696t: 697 store i32 0, i32* %a 698 br label %ret 699f: 700 store i32 1, i32* %b 701 br label %ret 702ret: 703 ret void 704} 705 706define void @arg_nonnull_12_noundef_2(i32* nonnull %a, i32* noundef nonnull %b, i32* %c) { 707; IS__TUNIT____: Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly 708; IS__TUNIT____-LABEL: define {{[^@]+}}@arg_nonnull_12_noundef_2 709; IS__TUNIT____-SAME: (i32* nocapture nofree nonnull writeonly [[A:%.*]], i32* nocapture nofree noundef nonnull writeonly [[B:%.*]], i32* nofree writeonly [[C:%.*]]) [[ATTR6]] { 710; IS__TUNIT____-NEXT: [[D:%.*]] = icmp eq i32* [[C]], null 711; IS__TUNIT____-NEXT: br i1 [[D]], label [[T:%.*]], label [[F:%.*]] 712; IS__TUNIT____: t: 713; IS__TUNIT____-NEXT: store i32 0, i32* [[A]], align 4 714; IS__TUNIT____-NEXT: br label [[RET:%.*]] 715; IS__TUNIT____: f: 716; IS__TUNIT____-NEXT: store i32 1, i32* [[B]], align 4 717; IS__TUNIT____-NEXT: br label [[RET]] 718; IS__TUNIT____: ret: 719; IS__TUNIT____-NEXT: ret void 720; 721; IS__CGSCC____: Function Attrs: argmemonly nofree norecurse nosync nounwind willreturn writeonly 722; IS__CGSCC____-LABEL: define {{[^@]+}}@arg_nonnull_12_noundef_2 723; IS__CGSCC____-SAME: (i32* nocapture nofree nonnull writeonly [[A:%.*]], i32* nocapture nofree noundef nonnull writeonly [[B:%.*]], i32* nofree writeonly [[C:%.*]]) [[ATTR6]] { 724; IS__CGSCC____-NEXT: [[D:%.*]] = icmp eq i32* [[C]], null 725; IS__CGSCC____-NEXT: br i1 [[D]], label [[T:%.*]], label [[F:%.*]] 726; IS__CGSCC____: t: 727; IS__CGSCC____-NEXT: store i32 0, i32* [[A]], align 4 728; IS__CGSCC____-NEXT: br label [[RET:%.*]] 729; IS__CGSCC____: f: 730; IS__CGSCC____-NEXT: store i32 1, i32* [[B]], align 4 731; IS__CGSCC____-NEXT: br label [[RET]] 732; IS__CGSCC____: ret: 733; IS__CGSCC____-NEXT: ret void 734; 735 %d = icmp eq i32* %c, null 736 br i1 %d, label %t, label %f 737t: 738 store i32 0, i32* %a 739 br label %ret 740f: 741 store i32 1, i32* %b 742 br label %ret 743ret: 744 ret void 745} 746 747; Pass null directly to argument with nonnull attribute 748define void @arg_nonnull_violation1_1() { 749; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 750; IS__TUNIT____-LABEL: define {{[^@]+}}@arg_nonnull_violation1_1 751; IS__TUNIT____-SAME: () [[ATTR0]] { 752; IS__TUNIT____-NEXT: unreachable 753; 754; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 755; IS__CGSCC____-LABEL: define {{[^@]+}}@arg_nonnull_violation1_1 756; IS__CGSCC____-SAME: () [[ATTR0]] { 757; IS__CGSCC____-NEXT: unreachable 758; 759 call void @arg_nonnull_1(i32* null) 760 ret void 761} 762 763define void @arg_nonnull_violation1_2() { 764; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 765; IS__TUNIT____-LABEL: define {{[^@]+}}@arg_nonnull_violation1_2 766; IS__TUNIT____-SAME: () [[ATTR0]] { 767; IS__TUNIT____-NEXT: unreachable 768; 769; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 770; IS__CGSCC____-LABEL: define {{[^@]+}}@arg_nonnull_violation1_2 771; IS__CGSCC____-SAME: () [[ATTR0]] { 772; IS__CGSCC____-NEXT: unreachable 773; 774 call void @arg_nonnull_1_noundef_1(i32* null) 775 ret void 776} 777 778; A case that depends on value simplification 779define void @arg_nonnull_violation2_1(i1 %c) { 780; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 781; IS__TUNIT____-LABEL: define {{[^@]+}}@arg_nonnull_violation2_1 782; IS__TUNIT____-SAME: (i1 [[C:%.*]]) [[ATTR0]] { 783; IS__TUNIT____-NEXT: unreachable 784; 785; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 786; IS__CGSCC____-LABEL: define {{[^@]+}}@arg_nonnull_violation2_1 787; IS__CGSCC____-SAME: (i1 [[C:%.*]]) [[ATTR0]] { 788; IS__CGSCC____-NEXT: unreachable 789; 790 %null = getelementptr i32, i32* null, i32 0 791 %mustnull = select i1 %c, i32* null, i32* %null 792 call void @arg_nonnull_1(i32* %mustnull) 793 ret void 794} 795 796define void @arg_nonnull_violation2_2(i1 %c) { 797; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 798; IS__TUNIT____-LABEL: define {{[^@]+}}@arg_nonnull_violation2_2 799; IS__TUNIT____-SAME: (i1 [[C:%.*]]) [[ATTR0]] { 800; IS__TUNIT____-NEXT: unreachable 801; 802; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 803; IS__CGSCC____-LABEL: define {{[^@]+}}@arg_nonnull_violation2_2 804; IS__CGSCC____-SAME: (i1 [[C:%.*]]) [[ATTR0]] { 805; IS__CGSCC____-NEXT: unreachable 806; 807 %null = getelementptr i32, i32* null, i32 0 808 %mustnull = select i1 %c, i32* null, i32* %null 809 call void @arg_nonnull_1_noundef_1(i32* %mustnull) 810 ret void 811} 812 813; Cases for single and multiple violation at a callsite 814define void @arg_nonnull_violation3_1(i1 %c) { 815; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 816; IS__TUNIT____-LABEL: define {{[^@]+}}@arg_nonnull_violation3_1 817; IS__TUNIT____-SAME: (i1 [[C:%.*]]) [[ATTR0]] { 818; IS__TUNIT____-NEXT: [[PTR:%.*]] = alloca i32, align 4 819; IS__TUNIT____-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]] 820; IS__TUNIT____: t: 821; IS__TUNIT____-NEXT: call void @arg_nonnull_12(i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]], i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]], i32* nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]]) [[ATTR7:#.*]] 822; IS__TUNIT____-NEXT: call void @arg_nonnull_12(i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]], i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]], i32* noalias nocapture nofree noundef writeonly align 536870912 null) [[ATTR7]] 823; IS__TUNIT____-NEXT: unreachable 824; IS__TUNIT____: f: 825; IS__TUNIT____-NEXT: unreachable 826; IS__TUNIT____: ret: 827; IS__TUNIT____-NEXT: ret void 828; 829; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 830; IS__CGSCC____-LABEL: define {{[^@]+}}@arg_nonnull_violation3_1 831; IS__CGSCC____-SAME: (i1 [[C:%.*]]) [[ATTR0]] { 832; IS__CGSCC____-NEXT: [[PTR:%.*]] = alloca i32, align 4 833; IS__CGSCC____-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]] 834; IS__CGSCC____: t: 835; IS__CGSCC____-NEXT: call void @arg_nonnull_12(i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]], i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]], i32* nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]]) [[ATTR7:#.*]] 836; IS__CGSCC____-NEXT: call void @arg_nonnull_12(i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]], i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]], i32* noalias nocapture nofree noundef writeonly align 536870912 null) [[ATTR7]] 837; IS__CGSCC____-NEXT: unreachable 838; IS__CGSCC____: f: 839; IS__CGSCC____-NEXT: unreachable 840; IS__CGSCC____: ret: 841; IS__CGSCC____-NEXT: ret void 842; 843 %ptr = alloca i32 844 br i1 %c, label %t, label %f 845t: 846 call void @arg_nonnull_12(i32* %ptr, i32* %ptr, i32* %ptr) 847 call void @arg_nonnull_12(i32* %ptr, i32* %ptr, i32* null) 848 call void @arg_nonnull_12(i32* %ptr, i32* null, i32* %ptr) 849 call void @arg_nonnull_12(i32* %ptr, i32* null, i32* null) 850 br label %ret 851f: 852 call void @arg_nonnull_12(i32* null, i32* %ptr, i32* %ptr) 853 call void @arg_nonnull_12(i32* null, i32* %ptr, i32* null) 854 call void @arg_nonnull_12(i32* null, i32* null, i32* %ptr) 855 call void @arg_nonnull_12(i32* null, i32* null, i32* null) 856 br label %ret 857ret: 858 ret void 859} 860 861define void @arg_nonnull_violation3_2(i1 %c) { 862; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 863; IS__TUNIT____-LABEL: define {{[^@]+}}@arg_nonnull_violation3_2 864; IS__TUNIT____-SAME: (i1 [[C:%.*]]) [[ATTR0]] { 865; IS__TUNIT____-NEXT: [[PTR:%.*]] = alloca i32, align 4 866; IS__TUNIT____-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]] 867; IS__TUNIT____: t: 868; IS__TUNIT____-NEXT: call void @arg_nonnull_12_noundef_2(i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]], i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]], i32* nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]]) [[ATTR7]] 869; IS__TUNIT____-NEXT: call void @arg_nonnull_12_noundef_2(i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]], i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]], i32* noalias nocapture nofree noundef writeonly align 536870912 null) [[ATTR7]] 870; IS__TUNIT____-NEXT: unreachable 871; IS__TUNIT____: f: 872; IS__TUNIT____-NEXT: unreachable 873; IS__TUNIT____: ret: 874; IS__TUNIT____-NEXT: ret void 875; 876; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 877; IS__CGSCC____-LABEL: define {{[^@]+}}@arg_nonnull_violation3_2 878; IS__CGSCC____-SAME: (i1 [[C:%.*]]) [[ATTR0]] { 879; IS__CGSCC____-NEXT: [[PTR:%.*]] = alloca i32, align 4 880; IS__CGSCC____-NEXT: br i1 [[C]], label [[T:%.*]], label [[F:%.*]] 881; IS__CGSCC____: t: 882; IS__CGSCC____-NEXT: call void @arg_nonnull_12_noundef_2(i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]], i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]], i32* nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]]) [[ATTR7]] 883; IS__CGSCC____-NEXT: call void @arg_nonnull_12_noundef_2(i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]], i32* nocapture nofree noundef nonnull writeonly align 4 dereferenceable(4) [[PTR]], i32* noalias nocapture nofree noundef writeonly align 536870912 null) [[ATTR7]] 884; IS__CGSCC____-NEXT: unreachable 885; IS__CGSCC____: f: 886; IS__CGSCC____-NEXT: unreachable 887; IS__CGSCC____: ret: 888; IS__CGSCC____-NEXT: ret void 889; 890 %ptr = alloca i32 891 br i1 %c, label %t, label %f 892t: 893 call void @arg_nonnull_12_noundef_2(i32* %ptr, i32* %ptr, i32* %ptr) 894 call void @arg_nonnull_12_noundef_2(i32* %ptr, i32* %ptr, i32* null) 895 call void @arg_nonnull_12_noundef_2(i32* %ptr, i32* null, i32* %ptr) 896 call void @arg_nonnull_12_noundef_2(i32* %ptr, i32* null, i32* null) 897 br label %ret 898f: 899 call void @arg_nonnull_12_noundef_2(i32* null, i32* %ptr, i32* %ptr) 900 call void @arg_nonnull_12_noundef_2(i32* null, i32* %ptr, i32* null) 901 call void @arg_nonnull_12_noundef_2(i32* null, i32* null, i32* %ptr) 902 call void @arg_nonnull_12_noundef_2(i32* null, i32* null, i32* null) 903 br label %ret 904ret: 905 ret void 906} 907 908; Tests for returned position 909 910define nonnull i32* @returned_nonnnull(i32 %c) { 911; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 912; IS__TUNIT____-LABEL: define {{[^@]+}}@returned_nonnnull 913; IS__TUNIT____-SAME: (i32 [[C:%.*]]) [[ATTR0]] { 914; IS__TUNIT____-NEXT: switch i32 [[C]], label [[ONDEFAULT:%.*]] [ 915; IS__TUNIT____-NEXT: i32 0, label [[ONZERO:%.*]] 916; IS__TUNIT____-NEXT: i32 1, label [[ONONE:%.*]] 917; IS__TUNIT____-NEXT: ] 918; IS__TUNIT____: onzero: 919; IS__TUNIT____-NEXT: [[PTR:%.*]] = alloca i32, align 4 920; IS__TUNIT____-NEXT: ret i32* [[PTR]] 921; IS__TUNIT____: onone: 922; IS__TUNIT____-NEXT: ret i32* null 923; IS__TUNIT____: ondefault: 924; IS__TUNIT____-NEXT: ret i32* undef 925; 926; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 927; IS__CGSCC____-LABEL: define {{[^@]+}}@returned_nonnnull 928; IS__CGSCC____-SAME: (i32 [[C:%.*]]) [[ATTR0]] { 929; IS__CGSCC____-NEXT: switch i32 [[C]], label [[ONDEFAULT:%.*]] [ 930; IS__CGSCC____-NEXT: i32 0, label [[ONZERO:%.*]] 931; IS__CGSCC____-NEXT: i32 1, label [[ONONE:%.*]] 932; IS__CGSCC____-NEXT: ] 933; IS__CGSCC____: onzero: 934; IS__CGSCC____-NEXT: [[PTR:%.*]] = alloca i32, align 4 935; IS__CGSCC____-NEXT: ret i32* [[PTR]] 936; IS__CGSCC____: onone: 937; IS__CGSCC____-NEXT: ret i32* null 938; IS__CGSCC____: ondefault: 939; IS__CGSCC____-NEXT: ret i32* undef 940; 941 switch i32 %c, label %ondefault [ i32 0, label %onzero 942 i32 1, label %onone ] 943onzero: 944 %ptr = alloca i32 945 ret i32* %ptr 946onone: 947 ret i32* null 948ondefault: 949 ret i32* undef 950} 951 952define noundef i32* @returned_noundef(i32 %c) { 953; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 954; IS__TUNIT____-LABEL: define {{[^@]+}}@returned_noundef 955; IS__TUNIT____-SAME: (i32 [[C:%.*]]) [[ATTR0]] { 956; IS__TUNIT____-NEXT: switch i32 [[C]], label [[ONDEFAULT:%.*]] [ 957; IS__TUNIT____-NEXT: i32 0, label [[ONZERO:%.*]] 958; IS__TUNIT____-NEXT: i32 1, label [[ONONE:%.*]] 959; IS__TUNIT____-NEXT: ] 960; IS__TUNIT____: onzero: 961; IS__TUNIT____-NEXT: [[PTR:%.*]] = alloca i32, align 4 962; IS__TUNIT____-NEXT: ret i32* [[PTR]] 963; IS__TUNIT____: onone: 964; IS__TUNIT____-NEXT: ret i32* null 965; IS__TUNIT____: ondefault: 966; IS__TUNIT____-NEXT: unreachable 967; 968; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 969; IS__CGSCC____-LABEL: define {{[^@]+}}@returned_noundef 970; IS__CGSCC____-SAME: (i32 [[C:%.*]]) [[ATTR0]] { 971; IS__CGSCC____-NEXT: switch i32 [[C]], label [[ONDEFAULT:%.*]] [ 972; IS__CGSCC____-NEXT: i32 0, label [[ONZERO:%.*]] 973; IS__CGSCC____-NEXT: i32 1, label [[ONONE:%.*]] 974; IS__CGSCC____-NEXT: ] 975; IS__CGSCC____: onzero: 976; IS__CGSCC____-NEXT: [[PTR:%.*]] = alloca i32, align 4 977; IS__CGSCC____-NEXT: ret i32* [[PTR]] 978; IS__CGSCC____: onone: 979; IS__CGSCC____-NEXT: ret i32* null 980; IS__CGSCC____: ondefault: 981; IS__CGSCC____-NEXT: unreachable 982; 983 switch i32 %c, label %ondefault [ i32 0, label %onzero 984 i32 1, label %onone ] 985onzero: 986 %ptr = alloca i32 987 ret i32* %ptr 988onone: 989 ret i32* null 990ondefault: 991 ret i32* undef 992} 993 994define nonnull noundef i32* @returned_nonnnull_noundef(i32 %c) { 995; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 996; IS__TUNIT____-LABEL: define {{[^@]+}}@returned_nonnnull_noundef 997; IS__TUNIT____-SAME: (i32 [[C:%.*]]) [[ATTR0]] { 998; IS__TUNIT____-NEXT: switch i32 [[C]], label [[ONDEFAULT:%.*]] [ 999; IS__TUNIT____-NEXT: i32 0, label [[ONZERO:%.*]] 1000; IS__TUNIT____-NEXT: i32 1, label [[ONONE:%.*]] 1001; IS__TUNIT____-NEXT: ] 1002; IS__TUNIT____: onzero: 1003; IS__TUNIT____-NEXT: [[PTR:%.*]] = alloca i32, align 4 1004; IS__TUNIT____-NEXT: ret i32* [[PTR]] 1005; IS__TUNIT____: onone: 1006; IS__TUNIT____-NEXT: unreachable 1007; IS__TUNIT____: ondefault: 1008; IS__TUNIT____-NEXT: unreachable 1009; 1010; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 1011; IS__CGSCC____-LABEL: define {{[^@]+}}@returned_nonnnull_noundef 1012; IS__CGSCC____-SAME: (i32 [[C:%.*]]) [[ATTR0]] { 1013; IS__CGSCC____-NEXT: switch i32 [[C]], label [[ONDEFAULT:%.*]] [ 1014; IS__CGSCC____-NEXT: i32 0, label [[ONZERO:%.*]] 1015; IS__CGSCC____-NEXT: i32 1, label [[ONONE:%.*]] 1016; IS__CGSCC____-NEXT: ] 1017; IS__CGSCC____: onzero: 1018; IS__CGSCC____-NEXT: [[PTR:%.*]] = alloca i32, align 4 1019; IS__CGSCC____-NEXT: ret i32* [[PTR]] 1020; IS__CGSCC____: onone: 1021; IS__CGSCC____-NEXT: unreachable 1022; IS__CGSCC____: ondefault: 1023; IS__CGSCC____-NEXT: unreachable 1024; 1025 switch i32 %c, label %ondefault [ i32 0, label %onzero 1026 i32 1, label %onone ] 1027onzero: 1028 %ptr = alloca i32 1029 ret i32* %ptr 1030onone: 1031 ret i32* null 1032ondefault: 1033 ret i32* undef 1034} 1035 1036define noundef i32 @returned_nonnnull_noundef_int() { 1037; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 1038; IS__TUNIT____-LABEL: define {{[^@]+}}@returned_nonnnull_noundef_int 1039; IS__TUNIT____-SAME: () [[ATTR0]] { 1040; IS__TUNIT____-NEXT: ret i32 0 1041; 1042; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 1043; IS__CGSCC____-LABEL: define {{[^@]+}}@returned_nonnnull_noundef_int 1044; IS__CGSCC____-SAME: () [[ATTR0]] { 1045; IS__CGSCC____-NEXT: ret i32 0 1046; 1047 ret i32 0 1048} 1049 1050declare void @callee_int_arg(i32) 1051 1052define void @callsite_noundef_1() { 1053; CHECK-LABEL: define {{[^@]+}}@callsite_noundef_1() { 1054; CHECK-NEXT: call void @callee_int_arg(i32 noundef 0) 1055; CHECK-NEXT: ret void 1056; 1057 call void @callee_int_arg(i32 noundef 0) 1058 ret void 1059} 1060 1061declare void @callee_ptr_arg(i32*) 1062 1063define void @callsite_noundef_2() { 1064; CHECK-LABEL: define {{[^@]+}}@callsite_noundef_2() { 1065; CHECK-NEXT: unreachable 1066; 1067 call void @callee_ptr_arg(i32* noundef undef) 1068 ret void 1069} 1070 1071define i32 @argument_noundef1(i32 noundef %c) { 1072; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 1073; IS__TUNIT____-LABEL: define {{[^@]+}}@argument_noundef1 1074; IS__TUNIT____-SAME: (i32 noundef returned [[C:%.*]]) [[ATTR0]] { 1075; IS__TUNIT____-NEXT: ret i32 [[C]] 1076; 1077; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 1078; IS__CGSCC____-LABEL: define {{[^@]+}}@argument_noundef1 1079; IS__CGSCC____-SAME: (i32 noundef returned [[C:%.*]]) [[ATTR0]] { 1080; IS__CGSCC____-NEXT: ret i32 [[C]] 1081; 1082 ret i32 %c 1083} 1084 1085define i32 @violate_noundef_nonpointer() { 1086; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 1087; IS__TUNIT____-LABEL: define {{[^@]+}}@violate_noundef_nonpointer 1088; IS__TUNIT____-SAME: () [[ATTR0]] { 1089; IS__TUNIT____-NEXT: unreachable 1090; 1091; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 1092; IS__CGSCC____-LABEL: define {{[^@]+}}@violate_noundef_nonpointer 1093; IS__CGSCC____-SAME: () [[ATTR0]] { 1094; IS__CGSCC____-NEXT: unreachable 1095; 1096 %ret = call i32 @argument_noundef1(i32 undef) 1097 ret i32 %ret 1098} 1099 1100define i32* @argument_noundef2(i32* noundef %c) { 1101; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 1102; IS__TUNIT____-LABEL: define {{[^@]+}}@argument_noundef2 1103; IS__TUNIT____-SAME: (i32* nofree noundef readnone returned "no-capture-maybe-returned" [[C:%.*]]) [[ATTR0]] { 1104; IS__TUNIT____-NEXT: ret i32* [[C]] 1105; 1106; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 1107; IS__CGSCC____-LABEL: define {{[^@]+}}@argument_noundef2 1108; IS__CGSCC____-SAME: (i32* nofree noundef readnone returned "no-capture-maybe-returned" [[C:%.*]]) [[ATTR0]] { 1109; IS__CGSCC____-NEXT: ret i32* [[C]] 1110; 1111 ret i32* %c 1112} 1113 1114define i32* @violate_noundef_pointer() { 1115; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn 1116; IS__TUNIT____-LABEL: define {{[^@]+}}@violate_noundef_pointer 1117; IS__TUNIT____-SAME: () [[ATTR0]] { 1118; IS__TUNIT____-NEXT: unreachable 1119; 1120; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn 1121; IS__CGSCC____-LABEL: define {{[^@]+}}@violate_noundef_pointer 1122; IS__CGSCC____-SAME: () [[ATTR0]] { 1123; IS__CGSCC____-NEXT: unreachable 1124; 1125 %ret = call i32* @argument_noundef2(i32* undef) 1126 ret i32* %ret 1127} 1128