diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-08-10 15:43:53 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-10 15:43:53 -0400 |
| commit | a7a4e17225bdb71211cc4ddc465c03864f4a563e (patch) | |
| tree | e0669918780a58111e3e17d44bb8357cf9155525 /tests/codegen-llvm | |
| parent | 5bd4e832d3608a4b06e3bc0b0bf348e664e961ec (diff) | |
| parent | 163594c8f81fc6bb8bb37645eac2f3b7da0be518 (diff) | |
| download | rust-a7a4e17225bdb71211cc4ddc465c03864f4a563e.tar.gz rust-a7a4e17225bdb71211cc4ddc465c03864f4a563e.zip | |
Rollup merge of #145064 - okaneco:saturating_sub_regression_tests, r=nikic
Add regression test for `saturating_sub` bounds check issue Add codegen test for issue where `valid_index.saturating_sub(X)` produced an extra bounds check. This was fixed by the LLVM upgrade. Closes rust-lang/rust#139759
Diffstat (limited to 'tests/codegen-llvm')
| -rw-r--r-- | tests/codegen-llvm/issues/saturating-sub-index-139759.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/codegen-llvm/issues/saturating-sub-index-139759.rs b/tests/codegen-llvm/issues/saturating-sub-index-139759.rs new file mode 100644 index 00000000000..eac2f4d306b --- /dev/null +++ b/tests/codegen-llvm/issues/saturating-sub-index-139759.rs @@ -0,0 +1,19 @@ +// Test that calculating an index with saturating subtraction from an in-bounds +// index doesn't generate another bounds check. + +//@ compile-flags: -Copt-level=3 +//@ min-llvm-version: 21 + +#![crate_type = "lib"] + +// CHECK-LABEL: @bounds_check_is_elided +#[no_mangle] +pub fn bounds_check_is_elided(s: &[i32], index: usize) -> i32 { + // CHECK-NOT: panic_bounds_check + if index < s.len() { + let lower_bound = index.saturating_sub(1); + s[lower_bound] + } else { + -1 + } +} |
