Skip to content

Commit 058ee88

Browse files
celinvaltedinski
authored andcommitted
Audit command line arguments (rust-lang#1106)
* Remove unused --allow-cbmc-verification-failure flag * Cleaning up the kani arguments. - Removed --auto-unwind which as broken. - Fixed punctuation to be consistent. - Hide unstable / developer features from short help. * Fix --unwind conflict check We were not covering any other form of unwind. Note that this will also conflict with --unwinding-assertions which I think is probably fine since we have that option in Kani.
1 parent 0a642f6 commit 058ee88

File tree

10 files changed

+36
-51
lines changed

10 files changed

+36
-51
lines changed

kani-driver/src/args.rs

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct KaniArgs {
4141
#[structopt(long)]
4242
pub visualize: bool,
4343
/// Keep temporary files generated throughout Kani process
44-
#[structopt(long)]
44+
#[structopt(long, hidden_short_help(true))]
4545
pub keep_temps: bool,
4646

4747
/// Produce full debug information
@@ -53,20 +53,21 @@ pub struct KaniArgs {
5353
/// Output processing stages and commands, along with minor debug information
5454
#[structopt(long, short)]
5555
pub verbose: bool,
56-
/// Enable usage of unstable options.
56+
/// Enable usage of unstable options
5757
#[structopt(long, hidden_short_help(true))]
5858
pub enable_unstable: bool,
5959

60+
// Hide this since it depends on function that is a hidden option.
6061
/// Print commands instead of running them
61-
#[structopt(long, requires("function"))]
62+
#[structopt(long, requires("function"), hidden(true))]
6263
pub dry_run: bool,
6364
/// Generate C file equivalent to inputted program.
64-
/// This feature is unstable and it requires `--enable-unstable` to be used.
65+
/// This feature is unstable and it requires `--enable-unstable` to be used
6566
#[structopt(long, hidden_short_help(true), requires("enable-unstable"))]
6667
pub gen_c: bool,
6768

6869
// TODO: currently only cargo-kani pays attention to this.
69-
/// Directory for all generated artifacts
70+
/// Directory for all generated artifacts. Only effective when running Kani with cargo
7071
#[structopt(long, parse(from_os_str))]
7172
pub target_dir: Option<PathBuf>,
7273

@@ -77,26 +78,24 @@ pub struct KaniArgs {
7778
#[structopt(flatten)]
7879
pub checks: CheckArgs,
7980

80-
/// Entry point for verification (symbol name)
81-
#[structopt(long, hidden = true)]
81+
/// Entry point for verification (symbol name).
82+
/// This is an unstable feature. Consider using --harness instead
83+
#[structopt(long, hidden = true, requires("enable-unstable"))]
8284
pub function: Option<String>,
8385
/// Entry point for verification (proof harness)
8486
// In a dry-run, we don't have kani-metadata.json to read, so we can't use this flag
8587
#[structopt(long, conflicts_with = "function", conflicts_with = "dry-run")]
8688
pub harness: Option<String>,
8789

8890
/// Link external C files referenced by Rust code.
89-
/// This is an experimental feature and requires `--enable-unstable` to be used.
91+
/// This is an experimental feature and requires `--enable-unstable` to be used
9092
#[structopt(long, parse(from_os_str), hidden = true, requires("enable-unstable"))]
9193
pub c_lib: Vec<PathBuf>,
92-
/// Enable test function verification. Only use this option when the entry point is a test function.
94+
/// Enable test function verification. Only use this option when the entry point is a test function
9395
#[structopt(long)]
9496
pub tests: bool,
95-
/// Do not produce error return code on CBMC verification failure
97+
/// Kani will only compile the crate. No verification will be performed
9698
#[structopt(long, hidden_short_help(true))]
97-
pub allow_cbmc_verification_failure: bool,
98-
/// Kani will only compile the crate
99-
#[structopt(long)]
10099
pub only_codegen: bool,
101100

102101
/// Specify the number of bits used for representing object IDs in CBMC
@@ -108,23 +107,20 @@ pub struct KaniArgs {
108107
/// Specify the value used for loop unwinding for the specified harness in CBMC
109108
#[structopt(long, requires("harness"))]
110109
pub unwind: Option<u32>,
111-
/// Turn on automatic loop unwinding
112-
#[structopt(long)]
113-
pub auto_unwind: bool,
114-
/// Pass through directly to CBMC; must be the last flag
115-
/// This feature is unstable and it requires `--enable-unstable` to be used.
110+
/// Pass through directly to CBMC; must be the last flag.
111+
/// This feature is unstable and it requires `--enable-unstable` to be used
116112
#[structopt(long, allow_hyphen_values = true, min_values(0), requires("enable-unstable"))]
117113
// consumes everything
118114
pub cbmc_args: Vec<OsString>,
119115

120116
// Hide option till https://github.com/model-checking/kani/issues/697 is
121-
// fixed
122-
/// Use abstractions for the standard library
123-
/// This is an experimental feature and requires `--enable-unstable` to be used.
117+
// fixed.
118+
/// Use abstractions for the standard library.
119+
/// This is an experimental feature and requires `--enable-unstable` to be used
124120
#[structopt(long, hidden = true, requires("enable-unstable"))]
125121
pub use_abs: bool,
126122
// Hide option till https://github.com/model-checking/kani/issues/697 is
127-
// fixed
123+
// fixed.
128124
/// Choose abstraction for modules of standard library if available
129125
#[structopt(long, default_value = "std", possible_values = &AbstractionType::variants(),
130126
case_insensitive = true, hidden = true)]
@@ -133,12 +129,12 @@ pub struct KaniArgs {
133129
/// Enable extra pointer checks such as invalid pointers in relation operations and pointer
134130
/// arithmetic overflow.
135131
/// This feature is unstable and it may yield false counter examples. It requires
136-
/// `--enable-unstable` to be used.
132+
/// `--enable-unstable` to be used
137133
#[structopt(long, hidden_short_help(true), requires("enable-unstable"))]
138134
pub extra_pointer_checks: bool,
139135

140-
/// Restrict the targets of virtual table function pointer calls
141-
/// This feature is unstable and it requires `--enable-unstable` to be used.
136+
/// Restrict the targets of virtual table function pointer calls.
137+
/// This feature is unstable and it requires `--enable-unstable` to be used
142138
#[structopt(long, hidden_short_help(true), requires("enable-unstable"))]
143139
pub restrict_vtable: bool,
144140
/// Disable restricting the targets of virtual table function pointer calls
@@ -283,23 +279,13 @@ impl CargoKaniArgs {
283279
}
284280
impl KaniArgs {
285281
pub fn validate(&self) {
286-
let extra_unwind = self.cbmc_args.contains(&OsString::from("--unwind"));
287-
let extra_auto_unwind = self.cbmc_args.contains(&OsString::from("--auto-unwind"));
288-
let extras = extra_auto_unwind || extra_unwind;
289-
let natives = self.auto_unwind || self.default_unwind.is_some();
290-
let any_auto_unwind = extra_auto_unwind || self.auto_unwind;
291-
let any_unwind = self.default_unwind.is_some() || extra_unwind;
282+
let extra_unwind =
283+
self.cbmc_args.iter().any(|s| s.to_str().unwrap().starts_with("--unwind"));
284+
let natives_unwind = self.default_unwind.is_some() || self.unwind.is_some();
292285

293286
// TODO: these conflicting flags reflect what's necessary to pass current tests unmodified.
294287
// We should consider improving the error messages slightly in a later pull request.
295-
if any_auto_unwind && any_unwind {
296-
Error::with_description(
297-
"Conflicting flags: `--auto-unwind` is not compatible with other `--default-unwind` flags.",
298-
ErrorKind::ArgumentConflict,
299-
)
300-
.exit();
301-
}
302-
if natives && extras {
288+
if natives_unwind && extra_unwind {
303289
Error::with_description(
304290
"Conflicting flags: unwind flags provided to kani and in --cbmc-args.",
305291
ErrorKind::ArgumentConflict,

kani-driver/src/call_cbmc.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ impl KaniSession {
3333
cmd.args(args);
3434

3535
if self.args.output_format == crate::args::OutputFormat::Old {
36-
let result = self.run_terminal(cmd);
37-
if !self.args.allow_cbmc_verification_failure && result.is_err() {
36+
if self.run_terminal(cmd).is_err() {
3837
return Ok(VerificationStatus::Failure);
3938
}
4039
} else {
@@ -44,7 +43,7 @@ impl KaniSession {
4443
let _cbmc_result = self.run_redirect(cmd, &output_filename)?;
4544
let format_result = self.format_cbmc_output(&output_filename);
4645

47-
if !self.args.allow_cbmc_verification_failure && format_result.is_err() {
46+
if format_result.is_err() {
4847
// Because of things like --assertion-reach-checks and other future features,
4948
// we now decide if we fail or not based solely on the output of the formatter.
5049
return Ok(VerificationStatus::Failure);
@@ -88,8 +87,6 @@ impl KaniSession {
8887
if let Some(unwind_value) = resolve_unwind_value(&self.args, harness_metadata) {
8988
args.push("--unwind".into());
9089
args.push(unwind_value.to_string().into());
91-
} else if self.args.auto_unwind {
92-
args.push("--auto-unwind".into());
9390
}
9491

9592
args.extend(self.args.cbmc_args.iter().cloned());

tests/expected/dry-run-flag-conflict-auto-unwind/expected

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
error: Conflicting flags: unwind flags provided to kani and in --cbmc-args.

tests/expected/dry-run-flag-conflict-auto-unwind/main.rs renamed to tests/expected/dry-run-flag-unwind-conflict/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

4-
// kani-flags: --dry-run --auto-unwind --default-unwind 2 --enable-unstable --function main
4+
// kani-flags: --dry-run --default-unwind 2 --enable-unstable --function main --cbmc-args --unwindset 2
55

66
// `--dry-run` causes Kani to print out commands instead of running them
77
// In `expected` you will find substrings of these commands because the

tests/expected/dry-run/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

4-
// kani-flags: --dry-run --function main
4+
// kani-flags: --dry-run --function main --enable-unstable
55

66
// `--dry-run` causes Kani to print out commands instead of running them
77
// In `expected` you will find substrings of these commands because the

tests/ui/code-location/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33
//
4-
// kani-flags: --function harness
4+
// kani-flags: --harness harness
55
//
66
//! This test is to check how file names are displayed in the Kani output.
77

tests/ui/code-location/module/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

4-
// kani-flags: --function empty_harness
4+
// kani-flags: --harness empty_harness
55

66
// This file is to be used as a module on a different test, but the compiletest will still run
77
// kani on this file. Use an empty harness instead.

tests/ui/missing-function/extern_c.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

4-
// kani-flags: --function harness
4+
// kani-flags: --harness harness
55

66
// This test is to check Kani's error handling for missing functions.
77
// TODO: Verify that this prints a compiler warning:

tools/bookrunner/src/util.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ pub fn add_verification_job(litani: &mut Litani, test_props: &TestProps) {
205205
let mut kani = Command::new("kani");
206206
// Add `--function main` so we can run these without having to amend them to add `#[kani::proof]`.
207207
// Some of test_props.kani_args will contains `--cbmc-args` so we should always put that last.
208-
kani.arg(&test_props.path).args(&["--function", "main"]).args(&test_props.kani_args);
208+
kani.arg(&test_props.path)
209+
.args(&["--enable-unstable", "--function", "main"])
210+
.args(&test_props.kani_args);
209211
if !test_props.rustc_args.is_empty() {
210212
kani.env("RUSTFLAGS", test_props.rustc_args.join(" "));
211213
}

0 commit comments

Comments
 (0)