-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test that bounds checks are elided when slice len is checked up-front
- Loading branch information
1 parent
06e4768
commit 0906066
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// no-system-llvm | ||
// compile-flags: -O | ||
#![crate_type = "lib"] | ||
|
||
// CHECK-LABEL: @already_sliced_no_bounds_check | ||
#[no_mangle] | ||
pub fn already_sliced_no_bounds_check(a: &[u8], b: &[u8], c: &mut [u8]) { | ||
// CHECK: slice_index_len_fail | ||
// CHECK-NOT: panic_bounds_check | ||
let _ = (&a[..2048], &b[..2048], &mut c[..2048]); | ||
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 | ||
// CHECK-LABEL: @already_sliced_bounds_check | ||
#[no_mangle] | ||
pub fn already_sliced_bounds_check(a: &[u8], b: &[u8], c: &mut [u8]) { | ||
// CHECK: slice_index_len_fail | ||
// CHECK: panic_bounds_check | ||
let _ = (&a[..1023], &b[..2048], &mut c[..2048]); | ||
for i in 0..1024 { | ||
c[i] = a[i] ^ b[i]; | ||
} | ||
} |