Skip to content

Commit 1422f9d

Browse files
committed
Update the script
1 parent e8a7fca commit 1422f9d

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

library/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@
263263
#![feature(tbm_target_feature)]
264264
#![feature(wasm_target_feature)]
265265
#![feature(x86_amx_intrinsics)]
266+
#![cfg_attr(kani, feature(proc_macro_hygiene))]
266267
// tidy-alphabetical-end
267268

268269
// allow using `core::` in intra-doc links

library/core/src/str/pattern.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ use crate::convert::TryInto as _;
4343
use crate::slice::memchr;
4444
use crate::{cmp, fmt};
4545

46+
use safety::{requires, ensures};
47+
4648
#[cfg(kani)]
4749
use crate::kani;
50+
#[cfg(kani)]
51+
use crate::kani::mem::same_allocation;
4852

4953
// Pattern
5054

@@ -1885,6 +1889,7 @@ fn simd_contains(needle: &str, haystack: &str) -> Option<bool> {
18851889
/// Both slices must have the same length.
18861890
#[cfg(all(target_arch = "x86_64", target_feature = "sse2"))] // only called on x86
18871891
#[inline]
1892+
#[requires(x.len() == y.len())]
18881893
unsafe fn small_slice_eq(x: &[u8], y: &[u8]) -> bool {
18891894
debug_assert_eq!(x.len(), y.len());
18901895
// This function is adapted from
@@ -1951,13 +1956,37 @@ unsafe fn small_slice_eq(x: &[u8], y: &[u8]) -> bool {
19511956
#[cfg(kani)]
19521957
#[unstable(feature = "kani", issue = "none")]
19531958
pub mod verify {
1959+
use super::*;
1960+
1961+
pub fn any_slice_of_array<T, const LENGTH: usize>(arr: &[T; LENGTH]) -> &[T] {
1962+
let (from, to) = any_range::<LENGTH>();
1963+
&arr[from..to]
1964+
}
1965+
1966+
/// A mutable version of the previous function
1967+
pub fn any_slice_of_array_mut<T, const LENGTH: usize>(arr: &mut [T; LENGTH]) -> &mut [T] {
1968+
let (from, to) = any_range::<LENGTH>();
1969+
&mut arr[from..to]
1970+
}
1971+
1972+
fn any_range<const LENGTH: usize>() -> (usize, usize) {
1973+
let from: usize = kani::any();
1974+
let to: usize = kani::any();
1975+
kani::assume(to <= LENGTH);
1976+
kani::assume(from <= to);
1977+
(from, to)
1978+
}
1979+
19541980
#[cfg(all(target_arch = "x86_64", target_feature = "sse2"))] // only called on x86
19551981
#[kani::proof]
19561982
pub fn check_small_slice_eq() {
1957-
let _ = Box::new(0);
19581983
const ARR_SIZE: usize = 1000;
1959-
let x: [i32; ARR_SIZE] = kani::any();
1960-
let y: [i32; ARR_SIZE] = kani::any();
1961-
small_slice_eq(x, y);
1984+
let x: [u8; ARR_SIZE] = kani::any();
1985+
let y: [u8; ARR_SIZE] = kani::any();
1986+
let xs = any_slice_of_array(&x);
1987+
let ys = any_slice_of_array(&y);
1988+
unsafe {
1989+
small_slice_eq(xs, ys);
1990+
}
19621991
}
19631992
}

scripts/check_kani.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ cargo build-dev --release
4444
echo "Running tests..."
4545
echo
4646
cd "$VERIFY_RUST_STD_DIR"
47-
$KANI_DIR/scripts/kani verify-std -Z unstable-options $VERIFY_RUST_STD_DIR/library --target-dir "$RUNNER_TEMP" -Z function-contracts -Z mem-predicates
47+
$KANI_DIR/scripts/kani verify-std -Z unstable-options $VERIFY_RUST_STD_DIR/library --target-dir "$RUNNER_TEMP" -Z function-contracts -Z mem-predicates -Z loop-contracts
4848

4949
echo "Tests completed."
5050
echo

0 commit comments

Comments
 (0)