From a27f3e3fd1e4d16160f8885b6b06665b5319f56c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 21 Jul 2025 14:34:12 +0200 Subject: Rename `tests/codegen` into `tests/codegen-llvm` --- .../binary-search-index-no-bound-check.rs | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/codegen-llvm/binary-search-index-no-bound-check.rs (limited to 'tests/codegen-llvm/binary-search-index-no-bound-check.rs') diff --git a/tests/codegen-llvm/binary-search-index-no-bound-check.rs b/tests/codegen-llvm/binary-search-index-no-bound-check.rs new file mode 100644 index 00000000000..d59c0beec64 --- /dev/null +++ b/tests/codegen-llvm/binary-search-index-no-bound-check.rs @@ -0,0 +1,35 @@ +//@ compile-flags: -Copt-level=3 +#![crate_type = "lib"] + +// Make sure no bounds checks are emitted when slicing or indexing +// with an index from `binary_search`. + +// CHECK-LABEL: @binary_search_index_no_bounds_check +#[no_mangle] +pub fn binary_search_index_no_bounds_check(s: &[u8]) -> u8 { + // CHECK-NOT: panic + // CHECK-NOT: slice_start_index_len_fail + // CHECK-NOT: slice_end_index_len_fail + // CHECK-NOT: panic_bounds_check + if let Ok(idx) = s.binary_search(&b'\\') { s[idx] } else { 42 } +} + +// Similarly, check that `partition_point` is known to return a valid fencepost. + +// CHECK-LABEL: @unknown_split +#[no_mangle] +pub fn unknown_split(x: &[i32], i: usize) -> (&[i32], &[i32]) { + // This just makes sure that the subsequent function is looking for the + // absence of something that might actually be there. + + // CHECK: call core::panicking::panic + x.split_at(i) +} + +// CHECK-LABEL: @partition_point_split_no_bounds_check +#[no_mangle] +pub fn partition_point_split_no_bounds_check(x: &[i32], needle: i32) -> (&[i32], &[i32]) { + // CHECK-NOT: call core::panicking::panic + let i = x.partition_point(|p| p < &needle); + x.split_at(i) +} -- cgit 1.4.1-3-g733a5