1 // This test case checks that LLVM is aware that computing the size of a slice cannot wrap.
2 // The possibility of wrapping results in an additional branch when dropping boxed slices
3 // in some situations, see https://github.com/rust-lang/rust/issues/96497#issuecomment-1112865218
6 // min-llvm-version: 14.0
10 // CHECK-LABEL: @simple_size_of_nowrap
12 pub fn simple_size_of_nowrap(x: &[u32]) -> usize {
13 // Make sure the shift used to compute the size has a nowrap flag.
15 // CHECK: [[A:%.*]] = shl nsw {{.*}}, 2
16 // CHECK-NEXT: ret {{.*}} [[A]]
17 core::mem::size_of_val(x)
20 // CHECK-LABEL: @drop_write
22 pub fn drop_write(mut x: Box<[u32]>) {
23 // Check that this write is optimized out.
24 // This depends on the size calculation not wrapping,
25 // since otherwise LLVM can't tell that the memory is always deallocated if the slice len > 0.
27 // CHECK-NOT: store i32 42