Skip to content

Commit e0975b9

Browse files
elaborate, add check for exact bounds
1 parent 0906066 commit e0975b9

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/test/codegen/issue-69101-bounds-check.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
// compile-flags: -O
33
#![crate_type = "lib"]
44

5+
// Make sure no bounds checks are emitted in the loop when upfront slicing
6+
// ensures that the slices are big enough.
7+
// In particular, bounds checks were not always optimized out if the upfront
8+
// check was for a greater len than the loop requires.
9+
// (i.e. `already_sliced_no_bounds_check` was not always optimized even when
10+
// `already_sliced_no_bounds_check_exact` was)
511
// CHECK-LABEL: @already_sliced_no_bounds_check
612
#[no_mangle]
713
pub fn already_sliced_no_bounds_check(a: &[u8], b: &[u8], c: &mut [u8]) {
@@ -13,7 +19,18 @@ pub fn already_sliced_no_bounds_check(a: &[u8], b: &[u8], c: &mut [u8]) {
1319
}
1420
}
1521

16-
// make sure we're checking for the right thing: there can be a panic if the slice is too small
22+
// CHECK-LABEL: @already_sliced_no_bounds_check_exact
23+
#[no_mangle]
24+
pub fn already_sliced_no_bounds_check_exact(a: &[u8], b: &[u8], c: &mut [u8]) {
25+
// CHECK: slice_index_len_fail
26+
// CHECK-NOT: panic_bounds_check
27+
let _ = (&a[..1024], &b[..1024], &mut c[..1024]);
28+
for i in 0..1024 {
29+
c[i] = a[i] ^ b[i];
30+
}
31+
}
32+
33+
// Make sure we're checking for the right thing: there can be a panic if the slice is too small.
1734
// CHECK-LABEL: @already_sliced_bounds_check
1835
#[no_mangle]
1936
pub fn already_sliced_bounds_check(a: &[u8], b: &[u8], c: &mut [u8]) {

0 commit comments

Comments
 (0)