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

Ensure storage markers are kept in std code #3080

Merged
merged 6 commits into from
Apr 5, 2024
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
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"))]
tautschnig marked this conversation as resolved.
Show resolved Hide resolved
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
Loading