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

Allow &bool in asserts #2117

Merged
merged 2 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ pub mod process;
#[macro_export]
macro_rules! assert {
($cond:expr $(,)?) => {
kani::assert($cond, concat!("assertion failed: ", stringify!($cond)));
// The double negation is to resolve https://github.com/model-checking/kani/issues/2108
kani::assert(!!$cond, concat!("assertion failed: ", stringify!($cond)));
};
($cond:expr, $($arg:tt)+) => {{
kani::assert($cond, concat!(stringify!($($arg)+)));
kani::assert(!!$cond, concat!(stringify!($($arg)+)));
// Process the arguments of the assert inside an unreachable block. This
// is to make sure errors in the arguments (e.g. an unknown variable or
// an argument that does not implement the Display or Debug traits) are
Expand Down
12 changes: 12 additions & 0 deletions tests/kani/Assert/bool_ref.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! This test makes sure Kani handles the valid `assert!(&b)` syntax where `b` is a `bool`
//! See https://github.com/model-checking/kani/issues/2108 for details.

#[kani::proof]
fn check_assert_with_reg() {
let b1: bool = kani::any();
let b2 = b1 || !b1; // true
assert!(&b2);
}