Skip to content

Commit 8a06d53

Browse files
committed
Add unstable option assume-no-panic
Compute verification results under the assumption that no panic occurs.
1 parent 4058625 commit 8a06d53

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

kani-compiler/src/args.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ pub enum ReachabilityType {
3737
/// with. Usually stored in and accessible via [`crate::kani_queries::QueryDb`].
3838
#[derive(Debug, Default, Clone, clap::Parser)]
3939
pub struct Arguments {
40+
/// Compute verification results under the assumption that no panic occurs.
41+
/// This feature is unstable, and it requires `-Z unstable-options` to be used
42+
#[clap(long)]
43+
pub assume_no_panic: bool,
4044
/// Option used to disable asserting function contracts.
4145
#[clap(long)]
4246
pub no_assert_contracts: bool,

kani-compiler/src/codegen_cprover_gotoc/codegen/assert.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,18 @@ impl GotocCtx<'_> {
133133
message: &str,
134134
loc: Location,
135135
) -> Stmt {
136-
let property_name = property_class.as_str();
137-
Stmt::block(
138-
vec![Stmt::assert(cond.clone(), property_name, message, loc), Stmt::assume(cond, loc)],
139-
loc,
140-
)
136+
if property_class == PropertyClass::Assertion && self.queries.args().assume_no_panic {
137+
Stmt::assume(cond, loc)
138+
} else {
139+
let property_name = property_class.as_str();
140+
Stmt::block(
141+
vec![
142+
Stmt::assert(cond.clone(), property_name, message, loc),
143+
Stmt::assume(cond, loc),
144+
],
145+
loc,
146+
)
147+
}
141148
}
142149

143150
/// Generate code to cover the given condition at the current location

kani-driver/src/args/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ pub enum CargoKaniSubcommand {
212212
#[derive(Debug, clap::Args)]
213213
#[clap(next_help_heading = "Verification Options")]
214214
pub struct VerificationArgs {
215+
/// Compute verification results under the assumption that no panic occurs.
216+
/// This feature is unstable, and it requires `-Z unstable-options` to be used
217+
#[arg(long, hide_short_help = true)]
218+
pub assume_no_panic: bool,
219+
215220
/// Link external C files referenced by Rust code.
216221
/// This is an experimental feature and requires `-Z c-ffi` to be used
217222
#[arg(long, hide = true, num_args(1..))]
@@ -634,6 +639,12 @@ impl ValidateArgs for VerificationArgs {
634639

635640
// check_unstable() calls: for each unstable option, check that the requisite unstable feature is provided.
636641
let unstable = || -> Result<(), Error> {
642+
self.common_args.check_unstable(
643+
self.assume_no_panic,
644+
"assume-no-panic",
645+
UnstableFeature::UnstableOptions,
646+
)?;
647+
637648
self.common_args.check_unstable(
638649
self.concrete_playback.is_some(),
639650
"concrete-playback",

kani-driver/src/call_single_file.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ impl KaniSession {
116116
pub fn kani_compiler_local_flags(&self) -> Vec<KaniArg> {
117117
let mut flags: Vec<KaniArg> = vec![];
118118

119+
if self.args.assume_no_panic {
120+
flags.push("--assume-no-panic".into());
121+
}
122+
119123
if self.args.common_args.debug {
120124
flags.push("--log-level=debug".into());
121125
} else if self.args.common_args.verbose {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
//
4+
// kani-flags: -Z unstable-options --assume-no-panic
5+
//! Test that --assume-no-panic works
6+
7+
#[kani::proof]
8+
fn div0() -> i32 {
9+
let x: i32 = kani::any();
10+
let y: i32 = kani::any();
11+
x / y
12+
}

0 commit comments

Comments
 (0)