Skip to content

Commit

Permalink
Update the script
Browse files Browse the repository at this point in the history
  • Loading branch information
qinheping committed Oct 22, 2024
1 parent e8a7fca commit 1422f9d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
#![feature(tbm_target_feature)]
#![feature(wasm_target_feature)]
#![feature(x86_amx_intrinsics)]
#![cfg_attr(kani, feature(proc_macro_hygiene))]
// tidy-alphabetical-end

// allow using `core::` in intra-doc links
Expand Down
37 changes: 33 additions & 4 deletions library/core/src/str/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ use crate::convert::TryInto as _;
use crate::slice::memchr;
use crate::{cmp, fmt};

use safety::{requires, ensures};

#[cfg(kani)]
use crate::kani;
#[cfg(kani)]
use crate::kani::mem::same_allocation;

// Pattern

Expand Down Expand Up @@ -1885,6 +1889,7 @@ fn simd_contains(needle: &str, haystack: &str) -> Option<bool> {
/// Both slices must have the same length.
#[cfg(all(target_arch = "x86_64", target_feature = "sse2"))] // only called on x86
#[inline]
#[requires(x.len() == y.len())]
unsafe fn small_slice_eq(x: &[u8], y: &[u8]) -> bool {
debug_assert_eq!(x.len(), y.len());
// This function is adapted from
Expand Down Expand Up @@ -1951,13 +1956,37 @@ unsafe fn small_slice_eq(x: &[u8], y: &[u8]) -> bool {
#[cfg(kani)]
#[unstable(feature = "kani", issue = "none")]
pub mod verify {
use super::*;

pub fn any_slice_of_array<T, const LENGTH: usize>(arr: &[T; LENGTH]) -> &[T] {
let (from, to) = any_range::<LENGTH>();
&arr[from..to]
}

/// A mutable version of the previous function
pub fn any_slice_of_array_mut<T, const LENGTH: usize>(arr: &mut [T; LENGTH]) -> &mut [T] {
let (from, to) = any_range::<LENGTH>();
&mut arr[from..to]
}

fn any_range<const LENGTH: usize>() -> (usize, usize) {
let from: usize = kani::any();
let to: usize = kani::any();
kani::assume(to <= LENGTH);
kani::assume(from <= to);
(from, to)
}

#[cfg(all(target_arch = "x86_64", target_feature = "sse2"))] // only called on x86
#[kani::proof]
pub fn check_small_slice_eq() {
let _ = Box::new(0);
const ARR_SIZE: usize = 1000;
let x: [i32; ARR_SIZE] = kani::any();
let y: [i32; ARR_SIZE] = kani::any();
small_slice_eq(x, y);
let x: [u8; ARR_SIZE] = kani::any();
let y: [u8; ARR_SIZE] = kani::any();
let xs = any_slice_of_array(&x);
let ys = any_slice_of_array(&y);
unsafe {
small_slice_eq(xs, ys);
}
}
}
2 changes: 1 addition & 1 deletion scripts/check_kani.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ cargo build-dev --release
echo "Running tests..."
echo
cd "$VERIFY_RUST_STD_DIR"
$KANI_DIR/scripts/kani verify-std -Z unstable-options $VERIFY_RUST_STD_DIR/library --target-dir "$RUNNER_TEMP" -Z function-contracts -Z mem-predicates
$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

echo "Tests completed."
echo
Expand Down

0 comments on commit 1422f9d

Please sign in to comment.