]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/binary-search-index-no-bound-check.rs
Merge commit '40dd3e2b7089b5e96714e064b731f6dbf17c61a9' into sync_cg_clif-2021-05-27
[rust.git] / src / test / codegen / binary-search-index-no-bound-check.rs
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 }