Skip to content

Commit 131c073

Browse files
authored
Fix description updates for missing function properties (rust-lang#1513)
* Update conditions to check for missing undef functions * Update UI tests * Remove const string not used anymore * Import `rustc-demangle` and use it * Update tests to account for function names * Short-form for dependencies declaration * Include demangled name in tests * Don't use mangled part of demangled name in tests * Use alternative format for demangled names * Add backquotes around function names * Update comment * Remove backquotes for location * Update missing function tests
1 parent d3acb55 commit 131c073

File tree

9 files changed

+20
-18
lines changed

9 files changed

+20
-18
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ dependencies = [
344344
"once_cell",
345345
"pathdiff",
346346
"regex",
347+
"rustc-demangle",
347348
"serde",
348349
"serde_json",
349350
"structopt",

kani-driver/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ clap = "2.34"
2424
glob = "0.3"
2525
toml = "0.5"
2626
regex = "1.6"
27+
rustc-demangle = "0.1.21"
2728
pathdiff = "0.2.1"
2829

2930
# A good set of suggested dependencies can be found in rustup:

kani-driver/src/cbmc_output_parser.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use console::style;
2525
use once_cell::sync::Lazy;
2626
use pathdiff::diff_paths;
2727
use regex::Regex;
28+
use rustc_demangle::demangle;
2829
use serde::Deserialize;
2930
use std::{
3031
collections::HashMap,
@@ -176,7 +177,6 @@ static CBMC_ALT_DESCRIPTIONS: Lazy<CbmcAltDescriptions> = Lazy::new(|| {
176177

177178
const UNSUPPORTED_CONSTRUCT_DESC: &str = "is not currently supported by Kani";
178179
const UNWINDING_ASSERT_DESC: &str = "unwinding assertion loop";
179-
const ASSERTION_FALSE: &str = "assertion false";
180180
const DEFAULT_ASSERTION: &str = "assertion";
181181
const REACH_CHECK_DESC: &str = "[KANI_REACHABILITY_CHECK]";
182182

@@ -277,7 +277,8 @@ impl std::fmt::Display for SourceLocation {
277277
write!(&mut fmt_str, "Unknown file")?;
278278
}
279279
if let Some(function) = self.function.clone() {
280-
write!(&mut fmt_str, " in function {function}")?;
280+
let demangled_function = demangle(&function);
281+
write!(&mut fmt_str, " in function {:#}", demangled_function)?;
281282
}
282283

283284
write! {f, "{}", fmt_str}
@@ -811,16 +812,17 @@ fn has_check_failure(properties: &Vec<Property>, description: &str) -> bool {
811812

812813
/// Replaces the description of all properties from functions with a missing
813814
/// definition.
814-
/// TODO: This hasn't been working as expected, see
815-
/// <https://github.com/model-checking/kani/issues/1424>
816815
fn modify_undefined_function_checks(mut properties: Vec<Property>) -> (Vec<Property>, bool) {
817816
let mut has_unknown_location_checks = false;
818817
for mut prop in &mut properties {
819-
if prop.description.contains(ASSERTION_FALSE)
820-
&& extract_property_class(prop).unwrap() == DEFAULT_ASSERTION
818+
if let Some(function) = &prop.source_location.function
819+
&& prop.description == DEFAULT_ASSERTION
821820
&& prop.source_location.file.is_none()
822821
{
823-
prop.description = "Function with missing definition is unreachable".to_string();
822+
// Missing functions come with mangled names.
823+
// `demangle` produces the demangled version if it's a mangled name.
824+
let modified_description = format!("Function `{:#}` with missing definition is unreachable", demangle(function));
825+
prop.description = modified_description;
824826
if prop.status == CheckStatus::Failure {
825827
has_unknown_location_checks = true;
826828
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Status: UNREACHABLE\
1+
Status: UNDETERMINED\
22
Description: "assertion failed: x == 5"
3-
3+
Status: FAILURE\
4+
Description: "Function `missing_function` with missing definition is unreachable"
45
VERIFICATION:- FAILED

tests/ui/missing-function/extern_c/extern_c.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
// TODO: Verify that this prints a compiler warning:
88
// - https://github.com/model-checking/kani/issues/576
99

10-
// TODO: Missing functions produce non-informative property descriptions
11-
// https://github.com/model-checking/kani/issues/1271
1210
extern "C" {
1311
fn missing_function() -> u32;
1412
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Status: FAILURE\
2-
Description: "assertion"
2+
Description: "Function `<alloc::string::String as core::clone::Clone>::clone` with missing definition is unreachable"
3+
Status: UNDETERMINED

tests/ui/missing-function/replaced-description/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// Copyright Kani Contributors
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

4-
// This test is to check if the description for undefined functions has been updated to "Function with missing definition is unreachable"
4+
// Checks if the description for undefined functions has been updated to
5+
// "Function with missing definition is unreachable"
56

6-
// TODO: Missing functions produce non-informative property descriptions
7-
// https://github.com/model-checking/kani/issues/1271
87
#[kani::proof]
98
fn main() {
109
let x = String::from("foo");
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Status: FAILURE\
2-
Description: "assertion"
2+
Description: "Function `core::num::<impl core::str::traits::FromStr for i32>::from_str` with missing definition is unreachable"
3+
Status: UNDETERMINED

tests/ui/missing-function/rust-by-example-description/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
// kani-flags: --enable-unstable --cbmc-args --unwind 4 --object-bits 9
55
// This test is to check if the description for undefined functions has been updated to "Function with missing definition is unreachable"
66

7-
// TODO: Missing functions produce non-informative property descriptions
8-
// https://github.com/model-checking/kani/issues/1271
97
#![allow(unused)]
108
#[kani::proof]
119
pub fn main() {

0 commit comments

Comments
 (0)