Skip to content
/ rustc Public
forked from rust-lang/rust

Commit

Permalink
add codegen test for rust-lang#113757
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji committed May 20, 2024
1 parent 2354167 commit ddad7fc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit ddad7fc

Please sign in to comment.