Skip to content

Commit c6d3a55

Browse files
Rollup merge of #144790 - lucarlig:pr-bounds-elision, r=compiler-errors
Multiple bounds checking elision failures regression test for #120433
2 parents 3823f0b + 19c6815 commit c6d3a55

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Regression test for #<https://github.com/rust-lang/rust/issues/120433>:
2+
//! Multiple bounds checking elision failures
3+
//! (ensures bounds checks are properly elided,
4+
//! with no calls to panic_bounds_check in the LLVM IR).
5+
6+
//@ compile-flags: -C opt-level=3
7+
8+
#![crate_type = "lib"]
9+
10+
// CHECK-LABEL: @foo
11+
// CHECK-NOT: panic_bounds_check
12+
#[no_mangle]
13+
pub fn foo(buf: &[u8], alloced_size: usize) -> &[u8] {
14+
if alloced_size.checked_add(1).map(|total| buf.len() < total).unwrap_or(true) {
15+
return &[];
16+
}
17+
let size = buf[0];
18+
&buf[1..1 + usize::min(alloced_size, usize::from(size))]
19+
}

0 commit comments

Comments
 (0)