Skip to content

Commit 5d2485e

Browse files
authored
Avoid an unnecssary suffix to the goto filename (#2472)
1 parent 8348dc2 commit 5d2485e

4 files changed

Lines changed: 31 additions & 47 deletions

File tree

kani-driver/src/harness_runner.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::args::OutputFormat;
1111
use crate::call_cbmc::{VerificationResult, VerificationStatus};
1212
use crate::project::Project;
1313
use crate::session::KaniSession;
14-
use crate::util::{error, specialized_harness_name, warning};
14+
use crate::util::{error, warning};
1515

1616
/// A HarnessRunner is responsible for checking all proof harnesses. The data in this structure represents
1717
/// "background information" that the controlling driver (e.g. cargo-kani or kani) computed.
@@ -56,24 +56,13 @@ impl<'sess, 'pr> HarnessRunner<'sess, 'pr> {
5656
let report_dir = self.project.outdir.join(format!("report-{harness_filename}"));
5757
let goto_file =
5858
self.project.get_harness_artifact(&harness, ArtifactType::Goto).unwrap();
59-
let specialized_obj = specialized_harness_name(goto_file, &harness_filename);
60-
self.sess.record_temporary_file(&specialized_obj);
61-
self.sess.instrument_model(
62-
goto_file,
63-
&specialized_obj,
64-
&self.project,
65-
&harness,
66-
)?;
59+
self.sess.instrument_model(goto_file, goto_file, &self.project, &harness)?;
6760

6861
if self.sess.args.synthesize_loop_contracts {
69-
self.sess.synthesize_loop_contracts(
70-
&specialized_obj,
71-
&specialized_obj,
72-
&harness,
73-
)?;
62+
self.sess.synthesize_loop_contracts(goto_file, &goto_file, &harness)?;
7463
}
7564

76-
let result = self.sess.check_harness(&specialized_obj, &report_dir, harness)?;
65+
let result = self.sess.check_harness(goto_file, &report_dir, harness)?;
7766
Ok(HarnessResult { harness, result })
7867
})
7968
.collect::<Result<Vec<_>>>()

kani-driver/src/util.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,6 @@ pub fn render_command(cmd: &Command) -> OsString {
157157
str
158158
}
159159

160-
/// Generate the filename for a specialized harness from the base linked object
161-
pub fn specialized_harness_name(linked_obj: &Path, harness_filename: &str) -> PathBuf {
162-
alter_extension(linked_obj, &format!("for-{harness_filename}.out"))
163-
}
164-
165160
/// Print a warning message. This will add a "warning:" tag before the message and style accordingly.
166161
pub fn warning(msg: &str) {
167162
let warning = console::style("warning:").bold().yellow();
@@ -229,21 +224,4 @@ mod tests {
229224
c1.env("PARAM", "VALUE");
230225
assert_eq!(render_command(&c1), OsString::from("PARAM=\"VALUE\" a b \"/c d/\""));
231226
}
232-
233-
#[test]
234-
fn check_specialized_harness_name() {
235-
// It's important that the filenames produced end in `.out` as we produce
236-
// `--gen-c` filenames with `alter_extension` and we previously had a bug where
237-
// `for-harness` was the "extension" being removed, and all filenames collided.
238-
239-
// cargo kani typically produced a file name like this
240-
let h1 = PathBuf::from("./cbmc-linked.out");
241-
assert_eq!(specialized_harness_name(&h1, "main"), Path::new("./cbmc-linked.for-main.out"));
242-
assert_eq!(specialized_harness_name(&h1, "hs_n"), Path::new("./cbmc-linked.for-hs_n.out"));
243-
244-
// kani typically produces a file name like this
245-
let h2 = PathBuf::from("./rs-file.out");
246-
assert_eq!(specialized_harness_name(&h2, "main"), Path::new("./rs-file.for-main.out"));
247-
assert_eq!(specialized_harness_name(&h2, "hs_n"), Path::new("./rs-file.for-hs_n.out"));
248-
}
249227
}

tests/kani/LongNames/test.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
//! This test checks that Kani handles harnesses with long name, e.g. due to
5+
//! nested modules
6+
//! The test is from https://github.com/model-checking/kani/issues/2468
7+
8+
mod a_really_long_module_name {
9+
mod yet_another_really_long_module_name {
10+
mod one_more_really_long_module_name {
11+
#[kani::proof]
12+
fn a_really_long_harness_name() {
13+
assert_eq!(1, 1);
14+
}
15+
}
16+
}
17+
}

tests/script-based-pre/check-output/check-output.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ rm -rf *.c
3434
kani --gen-c --enable-unstable singlefile.rs >& kani.log || \
3535
{ ret=$?; echo "== Failed to run Kani"; cat kani.log; rm kani.log; exit 1; }
3636
rm -f kani.log
37-
if ! [ -e singlefile_main.for-main.c ]
37+
if ! [ -e singlefile_main.c ]
3838
then
39-
echo "Error: no GotoC file generated. Expected: singlefile_main.for-main.c"
39+
echo "Error: no GotoC file generated. Expected: singlefile_main.c"
4040
exit 1
4141
fi
4242

43-
if ! [ -e singlefile_main.for-main.demangled.c ]
43+
if ! [ -e singlefile_main.demangled.c ]
4444
then
45-
echo "Error: no demangled GotoC file generated. Expected singlefile_main.for-main.demangled.c."
45+
echo "Error: no demangled GotoC file generated. Expected singlefile_main.demangled.c."
4646
exit 1
4747
fi
4848

@@ -57,9 +57,9 @@ declare -a PATTERNS=(
5757
)
5858

5959
for val in "${PATTERNS[@]}"; do
60-
if ! grep -Fq "$val" singlefile_main.for-main.demangled.c;
60+
if ! grep -Fq "$val" singlefile_main.demangled.c;
6161
then
62-
echo "Error: demangled file singlefile_main.for-main.demangled.c did not contain expected pattern '$val'."
62+
echo "Error: demangled file singlefile_main.demangled.c did not contain expected pattern '$val'."
6363
exit 1
6464
fi
6565
done
@@ -75,17 +75,17 @@ cargo kani --target-dir build --gen-c --enable-unstable >& kani.log || \
7575
rm -f kani.log
7676
cd build/kani/${TARGET}/debug/deps/
7777

78-
mangled=$(ls multifile*.for-main.c)
78+
mangled=$(ls multifile*_main.c)
7979
if ! [ -e "${mangled}" ]
8080
then
81-
echo "Error: no GotoC file found. Expected: build/${TARGET}/debug/deps/multifile*.for-main.c"
81+
echo "Error: no GotoC file found. Expected: build/kani/${TARGET}/debug/deps/multifile*_main.c"
8282
exit 1
8383
fi
8484

85-
demangled=$(ls multifile*.for-main.demangled.c)
85+
demangled=$(ls multifile*_main.demangled.c)
8686
if ! [ -e "${demangled}" ]
8787
then
88-
echo "Error: no demangled GotoC file found. Expected build/${TARGET}/debug/deps/multifile*.for-main.demangled.c."
88+
echo "Error: no demangled GotoC file found. Expected build/kani/${TARGET}/debug/deps/multifile*_main.demangled.c."
8989
exit 1
9090
fi
9191

0 commit comments

Comments
 (0)