2020-06-14 23:50:56 -05:00
|
|
|
// no-system-llvm
|
|
|
|
// compile-flags: -O
|
2020-06-17 12:10:49 -05:00
|
|
|
// ignore-debug: the debug assertions get in the way
|
2020-06-14 23:50:56 -05:00
|
|
|
#![crate_type = "lib"]
|
|
|
|
|
2020-06-15 17:19:54 -05:00
|
|
|
// Make sure no bounds checks are emitted in the loop when upfront slicing
|
|
|
|
// ensures that the slices are big enough.
|
|
|
|
// In particular, bounds checks were not always optimized out if the upfront
|
|
|
|
// check was for a greater len than the loop requires.
|
|
|
|
// (i.e. `already_sliced_no_bounds_check` was not always optimized even when
|
|
|
|
// `already_sliced_no_bounds_check_exact` was)
|
2020-06-14 23:50:56 -05:00
|
|
|
// CHECK-LABEL: @already_sliced_no_bounds_check
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn already_sliced_no_bounds_check(a: &[u8], b: &[u8], c: &mut [u8]) {
|
2020-07-19 09:12:50 -05:00
|
|
|
// CHECK: slice_end_index_len_fail
|
2020-06-14 23:50:56 -05:00
|
|
|
// CHECK-NOT: panic_bounds_check
|
|
|
|
let _ = (&a[..2048], &b[..2048], &mut c[..2048]);
|
|
|
|
for i in 0..1024 {
|
|
|
|
c[i] = a[i] ^ b[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 17:19:54 -05:00
|
|
|
// CHECK-LABEL: @already_sliced_no_bounds_check_exact
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn already_sliced_no_bounds_check_exact(a: &[u8], b: &[u8], c: &mut [u8]) {
|
2020-07-19 09:12:50 -05:00
|
|
|
// CHECK: slice_end_index_len_fail
|
2020-06-15 17:19:54 -05:00
|
|
|
// CHECK-NOT: panic_bounds_check
|
|
|
|
let _ = (&a[..1024], &b[..1024], &mut c[..1024]);
|
|
|
|
for i in 0..1024 {
|
|
|
|
c[i] = a[i] ^ b[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we're checking for the right thing: there can be a panic if the slice is too small.
|
2020-06-14 23:50:56 -05:00
|
|
|
// CHECK-LABEL: @already_sliced_bounds_check
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn already_sliced_bounds_check(a: &[u8], b: &[u8], c: &mut [u8]) {
|
2020-07-19 09:12:50 -05:00
|
|
|
// CHECK: slice_end_index_len_fail
|
2020-06-14 23:50:56 -05:00
|
|
|
// CHECK: panic_bounds_check
|
|
|
|
let _ = (&a[..1023], &b[..2048], &mut c[..2048]);
|
|
|
|
for i in 0..1024 {
|
|
|
|
c[i] = a[i] ^ b[i];
|
|
|
|
}
|
|
|
|
}
|