rust/tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

19 lines
433 B
Rust
Raw Normal View History

2024-05-20 13:18:52 -05:00
// in Rust 1.73, -O and opt-level=3 optimizes differently
//@ compile-flags: -C opt-level=3
#![crate_type = "lib"]
use std::cmp::max;
// CHECK-LABEL: @foo
// CHECK-NOT: slice_start_index_len_fail
// CHECK-NOT: unreachable
#[no_mangle]
pub fn foo(v: &mut Vec<u8>, size: usize) -> Option<&mut [u8]> {
2024-05-20 13:18:52 -05:00
if v.len() > max(1, size) {
let start = v.len() - size;
Some(&mut v[start..])
} else {
None
}
}