about summary refs log tree commit diff
path: root/tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs
blob: d495adf99804c0f054205c7d1744f339d43c7ef6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// 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]> {
    if v.len() > max(1, size) {
        let start = v.len() - size;
        Some(&mut v[start..])
    } else {
        None
    }
}