]> git.lizzy.rs Git - rust.git/blob - tests/codegen/issue-75525-bounds-checks.rs
Rollup merge of #107756 - RalfJung:miri-out-of-addresses, r=oli-obk
[rust.git] / tests / codegen / issue-75525-bounds-checks.rs
1 // Regression test for #75525, verifies that no bounds checks are generated.
2
3 // compile-flags: -O
4
5 #![crate_type = "lib"]
6
7 // CHECK-LABEL: @f0
8 // CHECK-NOT: panic
9 #[no_mangle]
10 pub fn f0(idx: usize, buf: &[u8; 10]) -> u8 {
11     if idx < 8 { buf[idx + 1] } else { 0 }
12 }
13
14 // CHECK-LABEL: @f1
15 // CHECK-NOT: panic
16 #[no_mangle]
17 pub fn f1(idx: usize, buf: &[u8; 10]) -> u8 {
18     if idx > 5 && idx < 8 { buf[idx - 1] } else { 0 }
19 }
20
21 // CHECK-LABEL: @f2
22 // CHECK-NOT: panic
23 #[no_mangle]
24 pub fn f2(idx: usize, buf: &[u8; 10]) -> u8 {
25     if idx > 5 && idx < 8 { buf[idx] } else { 0 }
26 }