Skip to content

Commit c9d04c2

Browse files
committed
Add codegen test checking binary_search allows eliding bound checks
1 parent f43c022 commit c9d04c2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// min-llvm-version: 11.0.0
2+
// compile-flags: -O
3+
// ignore-debug: the debug assertions get in the way
4+
#![crate_type = "lib"]
5+
6+
// Make sure no bounds checks are emitted when slicing or indexing
7+
// with an index from `binary_search`.
8+
9+
// CHECK-LABEL: @binary_search_index_no_bounds_check
10+
#[no_mangle]
11+
pub fn binary_search_index_no_bounds_check(s: &[u8]) -> u8 {
12+
// CHECK-NOT: panic
13+
// CHECK-NOT: slice_index_len_fail
14+
if let Ok(idx) = s.binary_search(&b'\\') {
15+
s[idx]
16+
} else {
17+
42
18+
}
19+
}

0 commit comments

Comments
 (0)