Skip to content

Commit c4f16e9

Browse files
authored
Ensure storage markers are kept in std code (rust-lang#3080)
This is a follow-up to rust-lang#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 rust-lang#3079
1 parent 5131258 commit c4f16e9

File tree

9 files changed

+55
-3
lines changed

9 files changed

+55
-3
lines changed

kani-compiler/src/args.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ pub struct Arguments {
7474
/// Enable specific checks.
7575
#[clap(long)]
7676
pub ub_check: Vec<ExtraChecks>,
77+
/// Ignore storage markers.
78+
#[clap(long)]
79+
pub ignore_storage_markers: bool,
7780
}
7881

7982
#[derive(Debug, Clone, Copy, AsRefStr, EnumString, VariantNames, PartialEq, Eq)]

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,19 @@ impl<'tcx> GotocCtx<'tcx> {
7676
self.codegen_set_discriminant(dest_ty, dest_expr, *variant_index, location)
7777
}
7878
StatementKind::StorageLive(var_id) => {
79-
Stmt::decl(self.codegen_local(*var_id), None, location)
79+
if self.queries.args().ignore_storage_markers {
80+
Stmt::skip(location)
81+
} else {
82+
Stmt::decl(self.codegen_local(*var_id), None, location)
83+
}
84+
}
85+
StatementKind::StorageDead(var_id) => {
86+
if self.queries.args().ignore_storage_markers {
87+
Stmt::skip(location)
88+
} else {
89+
Stmt::dead(self.codegen_local(*var_id), location)
90+
}
8091
}
81-
StatementKind::StorageDead(var_id) => Stmt::dead(self.codegen_local(*var_id), location),
8292
StatementKind::Intrinsic(NonDivergingIntrinsic::CopyNonOverlapping(
8393
CopyNonOverlapping { src, dst, count },
8494
)) => {

kani-driver/src/args/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,14 @@ pub struct VerificationArgs {
252252
#[arg(long, hide_short_help = true, requires("enable_unstable"))]
253253
pub ignore_global_asm: bool,
254254

255+
/// Ignore lifetimes of local variables. This effectively extends their
256+
/// lifetimes to the function scope, and hence may cause Kani to miss
257+
/// undefined behavior resulting from using the variable after it dies.
258+
/// This option may impact the soundness of the analysis and may cause false
259+
/// proofs and/or counterexamples
260+
#[arg(long, hide_short_help = true, requires("enable_unstable"))]
261+
pub ignore_locals_lifetime: bool,
262+
255263
/// Write the GotoC symbol table to a file in JSON format instead of goto binary format.
256264
#[arg(long, hide_short_help = true)]
257265
pub write_json_symtab: bool,

kani-driver/src/call_single_file.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ impl KaniSession {
105105
flags.push("--ub-check=validity".into())
106106
}
107107

108+
if self.args.ignore_locals_lifetime {
109+
flags.push("--ignore-storage-markers".into())
110+
}
111+
108112
flags.extend(self.args.common_args.unstable_features.as_arguments().map(str::to_string));
109113

110114
// This argument will select the Kani flavour of the compiler. It will be removed before

tests/perf/btreeset/insert_any/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ edition = "2021"
99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010

1111
[dependencies]
12+
13+
# Temporarily ignore the handling of storage markers till
14+
# https://github.com/model-checking/kani/issues/3099 is fixed
15+
[package.metadata.kani]
16+
flags = { ignore-locals-lifetime = true, enable-unstable = true }

tests/perf/btreeset/insert_multi/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ edition = "2021"
99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010

1111
[dependencies]
12+
13+
# Temporarily ignore the handling of storage markers till
14+
# https://github.com/model-checking/kani/issues/3099 is fixed
15+
[package.metadata.kani]
16+
flags = { ignore-locals-lifetime = true, enable-unstable = true }

tests/perf/btreeset/insert_same/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ edition = "2021"
99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010

1111
[dependencies]
12+
13+
# Temporarily ignore the handling of storage markers till
14+
# https://github.com/model-checking/kani/issues/3099 is fixed
15+
[package.metadata.kani]
16+
flags = { ignore-locals-lifetime = true, enable-unstable = true }

tests/perf/hashset/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ description = "Verify HashSet basic behavior"
1212

1313
[package.metadata.kani.unstable]
1414
stubbing = true
15+
16+
# Temporarily ignore the handling of storage markers till
17+
# https://github.com/model-checking/kani/issues/3099 is fixed
18+
[package.metadata.kani]
19+
flags = { ignore-locals-lifetime = true, enable-unstable = true }

tools/build-kani/src/sysroot.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,14 @@ fn build_kani_lib(
124124
"--message-format",
125125
"json-diagnostic-rendered-ansi",
126126
];
127-
let mut rustc_args = vec!["--cfg=kani", "--cfg=kani_sysroot", "-Z", "always-encode-mir"];
127+
let mut rustc_args = vec![
128+
"--cfg=kani",
129+
"--cfg=kani_sysroot",
130+
"-Z",
131+
"always-encode-mir",
132+
"-Z",
133+
"mir-enable-passes=-RemoveStorageMarkers",
134+
];
128135
rustc_args.extend_from_slice(extra_rustc_args);
129136
let mut cmd = Command::new("cargo")
130137
.env("CARGO_ENCODED_RUSTFLAGS", rustc_args.join("\x1f"))

0 commit comments

Comments
 (0)