Skip to content

Commit

Permalink
Ensure storage markers are kept in std code (#3080)
Browse files Browse the repository at this point in the history
This is a follow-up to #3063 that turns off that MIR pass while
compiling `std` as well to ensure any bugs of the same nature in `std`
are captured by Kani.

Resolves #3079
  • Loading branch information
zhassan-aws authored Apr 5, 2024
1 parent 5131258 commit c4f16e9
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 3 deletions.
3 changes: 3 additions & 0 deletions kani-compiler/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ pub struct Arguments {
/// Enable specific checks.
#[clap(long)]
pub ub_check: Vec<ExtraChecks>,
/// Ignore storage markers.
#[clap(long)]
pub ignore_storage_markers: bool,
}

#[derive(Debug, Clone, Copy, AsRefStr, EnumString, VariantNames, PartialEq, Eq)]
Expand Down
14 changes: 12 additions & 2 deletions kani-compiler/src/codegen_cprover_gotoc/codegen/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,19 @@ impl<'tcx> GotocCtx<'tcx> {
self.codegen_set_discriminant(dest_ty, dest_expr, *variant_index, location)
}
StatementKind::StorageLive(var_id) => {
Stmt::decl(self.codegen_local(*var_id), None, location)
if self.queries.args().ignore_storage_markers {
Stmt::skip(location)
} else {
Stmt::decl(self.codegen_local(*var_id), None, location)
}
}
StatementKind::StorageDead(var_id) => {
if self.queries.args().ignore_storage_markers {
Stmt::skip(location)
} else {
Stmt::dead(self.codegen_local(*var_id), location)
}
}
StatementKind::StorageDead(var_id) => Stmt::dead(self.codegen_local(*var_id), location),
StatementKind::Intrinsic(NonDivergingIntrinsic::CopyNonOverlapping(
CopyNonOverlapping { src, dst, count },
)) => {
Expand Down
8 changes: 8 additions & 0 deletions kani-driver/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ pub struct VerificationArgs {
#[arg(long, hide_short_help = true, requires("enable_unstable"))]
pub ignore_global_asm: bool,

/// Ignore lifetimes of local variables. This effectively extends their
/// lifetimes to the function scope, and hence may cause Kani to miss
/// undefined behavior resulting from using the variable after it dies.
/// This option may impact the soundness of the analysis and may cause false
/// proofs and/or counterexamples
#[arg(long, hide_short_help = true, requires("enable_unstable"))]
pub ignore_locals_lifetime: bool,

/// Write the GotoC symbol table to a file in JSON format instead of goto binary format.
#[arg(long, hide_short_help = true)]
pub write_json_symtab: bool,
Expand Down
4 changes: 4 additions & 0 deletions kani-driver/src/call_single_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ impl KaniSession {
flags.push("--ub-check=validity".into())
}

if self.args.ignore_locals_lifetime {
flags.push("--ignore-storage-markers".into())
}

flags.extend(self.args.common_args.unstable_features.as_arguments().map(str::to_string));

// This argument will select the Kani flavour of the compiler. It will be removed before
Expand Down
5 changes: 5 additions & 0 deletions tests/perf/btreeset/insert_any/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

# Temporarily ignore the handling of storage markers till
# https://github.com/model-checking/kani/issues/3099 is fixed
[package.metadata.kani]
flags = { ignore-locals-lifetime = true, enable-unstable = true }
5 changes: 5 additions & 0 deletions tests/perf/btreeset/insert_multi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

# Temporarily ignore the handling of storage markers till
# https://github.com/model-checking/kani/issues/3099 is fixed
[package.metadata.kani]
flags = { ignore-locals-lifetime = true, enable-unstable = true }
5 changes: 5 additions & 0 deletions tests/perf/btreeset/insert_same/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

# Temporarily ignore the handling of storage markers till
# https://github.com/model-checking/kani/issues/3099 is fixed
[package.metadata.kani]
flags = { ignore-locals-lifetime = true, enable-unstable = true }
5 changes: 5 additions & 0 deletions tests/perf/hashset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ description = "Verify HashSet basic behavior"

[package.metadata.kani.unstable]
stubbing = true

# Temporarily ignore the handling of storage markers till
# https://github.com/model-checking/kani/issues/3099 is fixed
[package.metadata.kani]
flags = { ignore-locals-lifetime = true, enable-unstable = true }
9 changes: 8 additions & 1 deletion tools/build-kani/src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,14 @@ fn build_kani_lib(
"--message-format",
"json-diagnostic-rendered-ansi",
];
let mut rustc_args = vec!["--cfg=kani", "--cfg=kani_sysroot", "-Z", "always-encode-mir"];
let mut rustc_args = vec![
"--cfg=kani",
"--cfg=kani_sysroot",
"-Z",
"always-encode-mir",
"-Z",
"mir-enable-passes=-RemoveStorageMarkers",
];
rustc_args.extend_from_slice(extra_rustc_args);
let mut cmd = Command::new("cargo")
.env("CARGO_ENCODED_RUSTFLAGS", rustc_args.join("\x1f"))
Expand Down

0 comments on commit c4f16e9

Please sign in to comment.