We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4b55fe1 commit 19c6815Copy full SHA for 19c6815
tests/codegen-llvm/bounds-check-elision-slice-min.rs
@@ -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