Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape Zero-size types in playback #2508

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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![]
YoshikiTakashima marked this conversation as resolved.
Show resolved Hide resolved
};
});
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}