Skip to content

Commit bfe3937

Browse files
committed
Multiple bounds checking elision failures
1 parent 1a64684 commit bfe3937

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Regression test for #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+
//@ build-pass
8+
9+
#![crate_type = "lib"]
10+
11+
// CHECK-LABEL: @foo
12+
// CHECK-NOT: panic_bounds_check
13+
#[no_mangle]
14+
pub fn foo(buf: &[u8], alloced_size: usize) -> &[u8] {
15+
if alloced_size.checked_add(1).map(|total| buf.len() < total).unwrap_or(true) {
16+
return &[];
17+
}
18+
let size = buf[0];
19+
&buf[1..1 + usize::min(alloced_size, usize::from(size))]
20+
}

0 commit comments

Comments
 (0)