rust/tests/codegen-llvm/issues/assert-for-loop-bounds-check-71997.rs
okaneco 9e28de2720 Add codegen regression tests
Most of these regressions concern elimination of panics and bounds
checks that were fixed upstream by LLVM.
2025-08-20 22:29:45 -04:00

19 lines
523 B
Rust

// Tests that there's no bounds check within for-loop after asserting that
// the range start and end are within bounds.
//@ compile-flags: -Copt-level=3
#![crate_type = "lib"]
// CHECK-LABEL: @no_bounds_check_after_assert
#[no_mangle]
fn no_bounds_check_after_assert(slice: &[u64], start: usize, end: usize) -> u64 {
// CHECK-NOT: panic_bounds_check
let mut total = 0;
assert!(start < end && start < slice.len() && end <= slice.len());
for i in start..end {
total += slice[i];
}
total
}