diff options
| author | bors <bors@rust-lang.org> | 2022-06-15 05:39:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-15 05:39:29 +0000 |
| commit | 389352c4bbd56024eefd1566e06dcba04d223f92 (patch) | |
| tree | edb2f035bc8ad77fd480002ddfc6d6562cde5a2f /src/test/codegen | |
| parent | ddb6cc85243ac4761fbc32a407b10216544fe57b (diff) | |
| parent | 1b8fc2f8f66f49bfa1538eeac2a9bd776833b22f (diff) | |
| download | rust-389352c4bbd56024eefd1566e06dcba04d223f92.tar.gz rust-389352c4bbd56024eefd1566e06dcba04d223f92.zip | |
Auto merge of #98123 - JohnTitor:rollup-rfg1a4s, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #97822 (Filter out intrinsics if we have other import candidates to suggest) - #98026 (Move some tests to more reasonable directories) - #98067 (compiler: remove unused deps) - #98078 (Use unchecked mul to compute slice sizes) - #98083 (Rename rustc_serialize::opaque::Encoder as MemEncoder.) - #98087 (Suggest adding a `#[macro_export]` to a private macro) - #98113 (Fix misspelling of "constraint" as "contraint") Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'src/test/codegen')
| -rw-r--r-- | src/test/codegen/issue-96497-slice-size-nowrap.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/test/codegen/issue-96497-slice-size-nowrap.rs b/src/test/codegen/issue-96497-slice-size-nowrap.rs new file mode 100644 index 00000000000..a5dbef93460 --- /dev/null +++ b/src/test/codegen/issue-96497-slice-size-nowrap.rs @@ -0,0 +1,29 @@ +// This test case checks that LLVM is aware that computing the size of a slice cannot wrap. +// The possibility of wrapping results in an additional branch when dropping boxed slices +// in some situations, see https://github.com/rust-lang/rust/issues/96497#issuecomment-1112865218 + +// compile-flags: -O +// min-llvm-version: 14.0 + +#![crate_type="lib"] + +// CHECK-LABEL: @simple_size_of_nowrap +#[no_mangle] +pub fn simple_size_of_nowrap(x: &[u32]) -> usize { + // Make sure the shift used to compute the size has a nowrap flag. + + // CHECK: [[A:%.*]] = shl nsw {{.*}}, 2 + // CHECK-NEXT: ret {{.*}} [[A]] + core::mem::size_of_val(x) +} + +// CHECK-LABEL: @drop_write +#[no_mangle] +pub fn drop_write(mut x: Box<[u32]>) { + // Check that this write is optimized out. + // This depends on the size calculation not wrapping, + // since otherwise LLVM can't tell that the memory is always deallocated if the slice len > 0. + + // CHECK-NOT: store i32 42 + x[1] = 42; +} |
