From f37c576dbd350adf0644ca9a2b83e28d9d57a076 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 20 May 2024 18:18:52 +0000 Subject: [PATCH] add codegen test for #113757 --- ...issue-113757-bounds-check-after-cmp-max.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs 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, size: usize)-> Option<&mut [u8]> { + if v.len() > max(1, size) { + let start = v.len() - size; + Some(&mut v[start..]) + } else { + None + } +}