Skip to content

Commit

Permalink
Escape Zero-size types in playback (#2508)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshikiTakashima authored Jun 8, 2023
1 parent 95e7161 commit cf203d3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
10 changes: 8 additions & 2 deletions library/kani/src/concrete_playback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ pub fn concrete_playback_run<F: Fn()>(mut local_concrete_vals: Vec<Vec<u8>>, pro
});
}

/// Concrete playback implementation of kani::any_raw_internal.
/// Concrete playback implementation of
/// kani::any_raw_internal. Because CBMC does not bother putting in
/// Zero-Sized Types, those are defaulted to an empty vector.
///
/// # Safety
///
Expand All @@ -49,7 +51,11 @@ pub(crate) unsafe fn any_raw_internal<T, const SIZE_T: usize>() -> T {
let mut next_concrete_val: Vec<u8> = Vec::new();
CONCRETE_VALS.with(|glob_concrete_vals| {
let mut_ref_glob_concrete_vals = &mut *glob_concrete_vals.borrow_mut();
next_concrete_val = mut_ref_glob_concrete_vals.pop().expect("Not enough det vals found");
next_concrete_val = if SIZE_T > 0 {
mut_ref_glob_concrete_vals.pop().expect("Not enough det vals found")
} else {
vec![]
};
});
let next_concrete_val_len = next_concrete_val.len();
let bytes_t: [u8; SIZE_T] = next_concrete_val.try_into().expect(&format!(
Expand Down
4 changes: 4 additions & 0 deletions tests/script-based-pre/playback_zero_size/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT
script: playback_zst.sh
expected: playback_zst.expected
9 changes: 9 additions & 0 deletions tests/script-based-pre/playback_zero_size/original.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! This checks that Kani zero-size playback, 2 of them in a row.
#[kani::proof]
fn any_is_ok() {
let unit: () = kani::any();
kani::cover!(unit == ());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[TEST] Generate test...
Checking harness any_is_ok

[TEST] Run test...
test result: ok. 1 passed; 0 failed;
18 changes: 18 additions & 0 deletions tests/script-based-pre/playback_zero_size/playback_zst.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT
# Test that concrete playback -Z concrete-playback executes as expected
set -o pipefail
set -o nounset

RS_FILE="modified.rs"
cp original.rs ${RS_FILE}

echo "[TEST] Generate test..."
kani ${RS_FILE} -Z concrete-playback --concrete-playback=inplace

echo "[TEST] Run test..."
kani playback -Z concrete-playback ${RS_FILE} -- kani_concrete_playback

# Cleanup
rm ${RS_FILE}

0 comments on commit cf203d3

Please sign in to comment.