Add regression test for saturating_sub bounds check issue
Add codegen test for issue where `valid_index.saturating_sub(X)` produced an extra bounds check. This was fixed by the LLVM upgrade.
This commit is contained in:
parent
cd434309ef
commit
163594c8f8
1 changed files with 19 additions and 0 deletions
19
tests/codegen-llvm/issues/saturating-sub-index-139759.rs
Normal file
19
tests/codegen-llvm/issues/saturating-sub-index-139759.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// Test that calculating an index with saturating subtraction from an in-bounds
|
||||
// index doesn't generate another bounds check.
|
||||
|
||||
//@ compile-flags: -Copt-level=3
|
||||
//@ min-llvm-version: 21
|
||||
|
||||
#![crate_type = "lib"]
|
||||
|
||||
// CHECK-LABEL: @bounds_check_is_elided
|
||||
#[no_mangle]
|
||||
pub fn bounds_check_is_elided(s: &[i32], index: usize) -> i32 {
|
||||
// CHECK-NOT: panic_bounds_check
|
||||
if index < s.len() {
|
||||
let lower_bound = index.saturating_sub(1);
|
||||
s[lower_bound]
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue