]> git.lizzy.rs Git - rust.git/blob - tests/codegen/issue-45964-bounds-check-slice-pos.rs
Rollup merge of #106709 - khuey:disable_split_dwarf_inlining_by_default, r=davidtwco
[rust.git] / tests / codegen / issue-45964-bounds-check-slice-pos.rs
1 // This test case checks that slice::{r}position functions do not
2 // prevent optimizing away bounds checks
3
4 // compile-flags: -O
5
6 #![crate_type="rlib"]
7
8 // CHECK-LABEL: @test
9 #[no_mangle]
10 pub fn test(y: &[u32], x: &u32, z: &u32) -> bool {
11     let result = match y.iter().position(|a| a == x) {
12         Some(p) => Ok(p),
13         None => Err(()),
14     };
15
16     if let Ok(p) = result {
17         // CHECK-NOT: panic
18         y[p] == *z
19     } else {
20         false
21     }
22 }
23
24 // CHECK-LABEL: @rtest
25 #[no_mangle]
26 pub fn rtest(y: &[u32], x: &u32, z: &u32) -> bool {
27     let result = match y.iter().rposition(|a| a == x) {
28         Some(p) => Ok(p),
29         None => Err(()),
30     };
31
32     if let Ok(p) = result {
33         // CHECK-NOT: panic
34         y[p] == *z
35     } else {
36         false
37     }
38 }