Skip to content

Commit 752bce5

Browse files
authored
Rollup merge of #78252 - bugadani:issue-45964, r=Mark-Simulacrum
Add codegen test for #45964 Closes #45964
2 parents 8646c2a + 3815c6a commit 752bce5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
}

0 commit comments

Comments
 (0)