Skip to content
New issue

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

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

Already on GitHub? # to your account

Hide --lib-c and add assume-false to unknown fns #964

Merged
merged 2 commits into from
Mar 22, 2022
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
5 changes: 3 additions & 2 deletions src/cargo-kani/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ pub struct KaniArgs {
/// Entry point for verification
#[structopt(long, default_value = "main")]
pub function: String,
/// Link external C files referenced by Rust code
#[structopt(long, parse(from_os_str))]
/// Link external C files referenced by Rust code.
/// This is an experimental feature.
#[structopt(long, parse(from_os_str), hidden = true)]
pub c_lib: Vec<PathBuf>,
/// Enable test function verification. Only use this option when the entry point is a test function.
#[structopt(long)]
Expand Down
2 changes: 1 addition & 1 deletion src/cargo-kani/src/call_goto_instrument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl KaniSession {
fn undefined_functions(&self, file: &Path) -> Result<()> {
let args: Vec<OsString> = vec![
"--generate-function-body-options".into(),
"assert-false".into(),
"assert-false-assume-false".into(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test that checks this behavior, e.g.:

extern "C" {
    fn missing_function() -> u32;
}

#[kani::proof]
fn main() {
    unsafe {
        let x = missing_function();
        assert!(x == 5);
    }
}

The assert should be reported as unreachable. Without your change, it fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

"--generate-function-body".into(),
".*".into(),
"--drop-unused-functions".into(),
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/cbmc_checks/float-overflow/check_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use kani::any;

// Use the result so rustc doesn't optimize them away.
fn dummy(result: f32) -> f32 {
result.round()
result
}

#[kani::proof]
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/missing-function/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Status: UNREACHABLE\
Description: "assertion failed: x == 5"

VERIFICATION:- FAILED

19 changes: 19 additions & 0 deletions tests/ui/missing-function/extern_c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

// kani-flags: --function harness

// This test is to check Kani's error handling for missing functions.
// TODO: Verify that this prints a compiler warning:
// - https://github.com/model-checking/kani/issues/576


extern "C" {
fn missing_function() -> u32;
}

#[kani::proof]
fn harness() {
let x = unsafe { missing_function() };
assert!(x == 5);
}