diff options
| author | Lzu Tao <taolzu@gmail.com> | 2024-05-20 18:18:52 +0000 |
|---|---|---|
| committer | Lzu Tao <taolzu@gmail.com> | 2024-06-09 07:35:24 +0000 |
| commit | f37c576dbd350adf0644ca9a2b83e28d9d57a076 (patch) | |
| tree | 4d72c0d4aa2b096eb877b1463dfe02732c61ecd1 | |
| parent | f3c89f1751217f8ad2267d5acaed9b665392e9cc (diff) | |
| download | rust-f37c576dbd350adf0644ca9a2b83e28d9d57a076.tar.gz rust-f37c576dbd350adf0644ca9a2b83e28d9d57a076.zip | |
add codegen test for #113757
| -rw-r--r-- | tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs b/tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs new file mode 100644 index 00000000000..5dedefc43d1 --- /dev/null +++ b/tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs @@ -0,0 +1,19 @@ +// in Rust 1.73, -O and opt-level=3 optimizes differently +//@ compile-flags: -C opt-level=3 +//@ min-llvm-version: 17 +#![crate_type = "lib"] + +use std::cmp::max; + +#[no_mangle] +// CHECK-LABEL: @foo +// CHECK-NOT: slice_start_index_len_fail +// CHECK-NOT: unreachable +pub fn foo(v: &mut Vec<u8>, size: usize)-> Option<&mut [u8]> { + if v.len() > max(1, size) { + let start = v.len() - size; + Some(&mut v[start..]) + } else { + None + } +} |
