Skip to content

Commit 5957298

Browse files
committed
Update kani version
1 parent e43d6fb commit 5957298

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

library/core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@
230230
#![feature(unboxed_closures)]
231231
#![feature(unsized_fn_params)]
232232
#![feature(with_negative_coherence)]
233+
#![feature(proc_macro_hygiene)]
233234
// tidy-alphabetical-end
234235
//
235236
// Target features:
@@ -247,7 +248,6 @@
247248
#![feature(tbm_target_feature)]
248249
#![feature(wasm_target_feature)]
249250
#![feature(x86_amx_intrinsics)]
250-
#![cfg_attr(kani, feature(proc_macro_hygiene))]
251251
// tidy-alphabetical-end
252252

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

library/core/src/slice/mod.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,7 +2787,10 @@ impl<T> [T] {
27872787
// returns Equal. We want the number of loop iterations to depend *only*
27882788
// on the size of the input slice so that the CPU can reliably predict
27892789
// the loop count.
2790-
#[cfg_attr(kani, kani::loop_invariant(size <= self.len() && size >= 1 && base <= self.len() && size+base <= self.len()))]
2790+
#[safety::loop_invariant(size <= self.len()
2791+
&& size >= 1
2792+
&& base <= self.len()
2793+
&& size+base <= self.len())]
27912794
while size > 1 {
27922795
let half = size / 2;
27932796
let mid = base + half;
@@ -4925,29 +4928,27 @@ impl<const N: usize> fmt::Display for GetManyMutError<N> {
49254928
pub mod verify {
49264929
use super::*;
49274930

4928-
// Copied from https://github.com/model-checking/kani/blob/main/library/kani/src/slice.rs
4929-
// should be removed when these functions are moved to `kani_core`
4930-
pub fn any_slice_of_array<T, const LENGTH: usize>(arr: &[T; LENGTH]) -> &[T] {
4931-
let (from, to) = any_range::<LENGTH>();
4932-
&arr[from..to]
4933-
}
4934-
4935-
fn any_range<const LENGTH: usize>() -> (usize, usize) {
4936-
let from: usize = kani::any();
4937-
let to: usize = kani::any();
4938-
kani::assume(to <= LENGTH);
4939-
kani::assume(from <= to);
4940-
(from, to)
4941-
}
4942-
49434931
#[kani::proof]
49444932
pub fn check_binary_search_by() {
4945-
const ARR_SIZE: usize = 1000;
4946-
let x: [u8; ARR_SIZE] = kani::any();
4947-
let xs = any_slice_of_array(&x);
49484933
let key: u8 = kani::any();
4949-
unsafe {
4950-
xs.binary_search_by(|p| p.cmp(&key));
4934+
if kani::any() {
4935+
// TODO: ARR_SIZE can be `std::usize::MAX` with cbmc argument
4936+
// `--arrays-uf-always`
4937+
const ARR_SIZE: usize = 1000;
4938+
let x: [u8; ARR_SIZE] = kani::any();
4939+
let xs = kani::slice::any_slice_of_array(&x);
4940+
unsafe {
4941+
xs.binary_search_by(|p| p.cmp(&key));
4942+
}
4943+
} else {
4944+
let ptr = kani::any_where::<usize, _>(|val| *val != 0) as *const u8;
4945+
kani::assume(ptr.is_aligned());
4946+
unsafe {
4947+
assert_eq!(
4948+
crate::slice::from_raw_parts(ptr, 0).binary_search_by(|p| p.cmp(&key)),
4949+
Err(0)
4950+
);
4951+
}
49514952
}
49524953
}
49534954
}

scripts/run-kani.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ main() {
183183

184184
echo "Running Kani verify-std command..."
185185

186-
"$kani_path" verify-std -Z unstable-options ./library --target-dir "$temp_dir_target" -Z function-contracts -Z mem-predicates --output-format=terse $command_args
186+
"$kani_path" verify-std -Z unstable-options ./library --target-dir "$temp_dir_target" -Z function-contracts -Z mem-predicates -Z loop-contracts --output-format=terse $command_args --enable-unstable --cbmc-args --object-bits 12
187187
}
188188

189189
main

tool_config/kani-version.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# incompatible with the verify-std repo.
33

44
[kani]
5-
commit = "2565ef65767a696f1d519b42621b4e502e8970d0"
5+
commit = "8400296f5280be4f99820129bc66447e8dff63f4"

0 commit comments

Comments
 (0)