about summary refs log tree commit diff
path: root/tests/codegen-llvm/issues/assert-for-loop-bounds-check-71997.rs
blob: a0c64d607a8f2e409955a99b983ec0699c15d974 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// 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
}