Skip to content

Commit d8f7ad4

Browse files
zhassan-awstedinski
authored andcommitted
Check for exact match of reachability check ID (rust-lang#1093)
1 parent ac2b1de commit d8f7ad4

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

scripts/cbmc_json_parser.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class GlobalMessages(str, Enum):
5050
REACH_CHECK_DESC = "[KANI_REACHABILITY_CHECK]"
5151
REACH_CHECK_KEY = "reachCheckResult"
5252
CHECK_ID = "KANI_CHECK_ID"
53+
CHECK_ID_RE = CHECK_ID + r"_.*_([0-9])*"
5354
UNSUPPORTED_CONSTRUCT_DESC = "is not currently supported by Kani"
5455
UNWINDING_ASSERT_DESC = "unwinding assertion loop"
5556

@@ -300,7 +301,9 @@ def postprocess_results(properties, extra_ptr_check):
300301
property["status"] = "UNDETERMINED"
301302
elif GlobalMessages.REACH_CHECK_KEY in property and property[GlobalMessages.REACH_CHECK_KEY] == "SUCCESS":
302303
# Change SUCCESS to UNREACHABLE
303-
assert property["status"] == "SUCCESS", "** ERROR: Expecting an unreachable property to have a status of \"SUCCESS\""
304+
description = property["description"]
305+
assert property[
306+
"status"] == "SUCCESS", f"** ERROR: Expecting the unreachable property \"{description}\" to have a status of \"SUCCESS\""
304307
property["status"] = "UNREACHABLE"
305308

306309
messages = ""
@@ -517,7 +520,7 @@ def annotate_properties_with_reach_results(properties, reach_checks):
517520
for reach_check in reach_checks:
518521
description = reach_check["description"]
519522
# Extract the ID of the assert from the description
520-
match_obj = re.search(GlobalMessages.CHECK_ID + r"_.*_([0-9])*", description)
523+
match_obj = re.search(GlobalMessages.CHECK_ID_RE, description)
521524
if not match_obj:
522525
raise Exception("Error: failed to extract check ID for reachability check \"" + description + "\"")
523526
check_id = match_obj.group(0)
@@ -531,8 +534,13 @@ def get_matching_property(properties, check_id):
531534
Find the property with the given ID
532535
"""
533536
for property in properties:
534-
if check_id in property["description"]:
535-
return property
537+
description = property["description"]
538+
match_obj = re.search("\\[" + GlobalMessages.CHECK_ID_RE + "\\]", description)
539+
# Currently, not all properties have a check ID
540+
if match_obj:
541+
prop_check_id = match_obj.group(0)
542+
if prop_check_id == "[" + check_id + "]":
543+
return property
536544
raise Exception("Error: failed to find a property with ID \"" + check_id + "\"")
537545

538546

@@ -551,7 +559,7 @@ def remove_check_ids_from_description(properties):
551559
they're not shown to the user. The removal of the IDs should only be done
552560
after all ID-based post-processing is done.
553561
"""
554-
check_id_pattern = re.compile(r"\[" + GlobalMessages.CHECK_ID + r"_.*_[0-9]*\] ")
562+
check_id_pattern = re.compile(r"\[" + GlobalMessages.CHECK_ID_RE + r"\] ")
555563
for property in properties:
556564
property["description"] = re.sub(check_id_pattern, "", property["description"])
557565

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Status: FAILURE\
2+
Description: "assertion failed: 3 + 3 == 5"
3+
4+
Status: UNREACHABLE\
5+
Description: "assertion failed: 2 + 2 == 4"
6+
7+
Status: SUCCESS\
8+
Description: "assertion failed: 1 + 1 == 2"
9+
10+
VERIFICATION:- FAILED

tests/expected/reach/check_id/main.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// This test has more than 10 asserts to satisfy the condition that two check
5+
// IDs are a prefix of each other, e.g.:
6+
// KANI_CHECK_ID_reach_check.225019a5::reach_check_1
7+
// KANI_CHECK_ID_reach_check.225019a5::reach_check_10
8+
9+
fn foo(x: i32) {
10+
assert!(1 + 1 == 2);
11+
if x < 9 {
12+
// unreachable
13+
assert!(2 + 2 == 4);
14+
}
15+
}
16+
17+
#[kani::proof]
18+
fn main() {
19+
assert!(1 + 1 == 2);
20+
let x = if kani::any() { 33 } else { 57 };
21+
foo(x);
22+
assert!(1 + 1 == 2);
23+
assert!(1 + 1 == 2);
24+
assert!(1 + 1 == 2);
25+
assert!(1 + 1 == 2);
26+
assert!(1 + 1 == 2);
27+
assert!(1 + 1 == 2);
28+
assert!(1 + 1 == 2);
29+
assert!(3 + 3 == 5);
30+
}

0 commit comments

Comments
 (0)