diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2025-08-03 21:56:56 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-03 21:56:56 +0200 |
| commit | c6d3a55914f72b868e31098a8a5d4fed3ae78e2e (patch) | |
| tree | 81c1561759d554b4dc9b7043c966b591e02cabff | |
| parent | 3823f0bc078c90eb0df74fa08fcae52b2c269330 (diff) | |
| parent | 19c6815a212d86c389ef54c3ddb02697ffc45f93 (diff) | |
| download | rust-c6d3a55914f72b868e31098a8a5d4fed3ae78e2e.tar.gz rust-c6d3a55914f72b868e31098a8a5d4fed3ae78e2e.zip | |
Rollup merge of #144790 - lucarlig:pr-bounds-elision, r=compiler-errors
Multiple bounds checking elision failures regression test for rust-lang/rust#120433
| -rw-r--r-- | tests/codegen-llvm/bounds-check-elision-slice-min.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/codegen-llvm/bounds-check-elision-slice-min.rs b/tests/codegen-llvm/bounds-check-elision-slice-min.rs new file mode 100644 index 00000000000..e160e5da50f --- /dev/null +++ b/tests/codegen-llvm/bounds-check-elision-slice-min.rs @@ -0,0 +1,19 @@ +//! Regression test for #<https://github.com/rust-lang/rust/issues/120433>: +//! Multiple bounds checking elision failures +//! (ensures bounds checks are properly elided, +//! with no calls to panic_bounds_check in the LLVM IR). + +//@ compile-flags: -C opt-level=3 + +#![crate_type = "lib"] + +// CHECK-LABEL: @foo +// CHECK-NOT: panic_bounds_check +#[no_mangle] +pub fn foo(buf: &[u8], alloced_size: usize) -> &[u8] { + if alloced_size.checked_add(1).map(|total| buf.len() < total).unwrap_or(true) { + return &[]; + } + let size = buf[0]; + &buf[1..1 + usize::min(alloced_size, usize::from(size))] +} |
