Skip to content

Commit 0906066

Browse files
Test that bounds checks are elided when slice len is checked up-front
1 parent 06e4768 commit 0906066

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// no-system-llvm
2+
// compile-flags: -O
3+
#![crate_type = "lib"]
4+
5+
// CHECK-LABEL: @already_sliced_no_bounds_check
6+
#[no_mangle]
7+
pub fn already_sliced_no_bounds_check(a: &[u8], b: &[u8], c: &mut [u8]) {
8+
// CHECK: slice_index_len_fail
9+
// CHECK-NOT: panic_bounds_check
10+
let _ = (&a[..2048], &b[..2048], &mut c[..2048]);
11+
for i in 0..1024 {
12+
c[i] = a[i] ^ b[i];
13+
}
14+
}
15+
16+
// make sure we're checking for the right thing: there can be a panic if the slice is too small
17+
// CHECK-LABEL: @already_sliced_bounds_check
18+
#[no_mangle]
19+
pub fn already_sliced_bounds_check(a: &[u8], b: &[u8], c: &mut [u8]) {
20+
// CHECK: slice_index_len_fail
21+
// CHECK: panic_bounds_check
22+
let _ = (&a[..1023], &b[..2048], &mut c[..2048]);
23+
for i in 0..1024 {
24+
c[i] = a[i] ^ b[i];
25+
}
26+
}

0 commit comments

Comments
 (0)