Skip to content

Commit 988f11f

Browse files
zhassan-awstedinski
authored andcommitted
Handle CBMC error messages (rust-lang#1108)
1 parent 49253b3 commit 988f11f

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

scripts/cbmc_json_parser.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class GlobalMessages(str, Enum):
4545
PROGRAM = 'program'
4646
RESULT = 'result'
4747
MESSAGE_TEXT = 'messageText'
48+
MESSAGE_TYPE = 'messageType'
4849
SUCCESS = 'SUCCESS'
4950
FAILED = 'FAILED'
5051
REACH_CHECK_DESC = "[KANI_REACHABILITY_CHECK]"
@@ -180,6 +181,13 @@ def transform_cbmc_output(cbmc_response_string, output_style, extra_ptr_check):
180181

181182
# Extract property information from the restructured JSON file
182183
properties, solver_information = extract_solver_information(cbmc_json_array)
184+
185+
# Check if there were any errors
186+
errors = extract_errors(solver_information)
187+
if errors:
188+
print('\n'.join(errors))
189+
return 1
190+
183191
properties, messages = postprocess_results(properties, extra_ptr_check)
184192

185193
# Using Case Switching to Toggle between various output styles
@@ -265,6 +273,21 @@ def extract_solver_information(cbmc_response_json_array):
265273

266274
return properties, solver_information
267275

276+
def extract_errors(solver_information):
277+
"""
278+
Extract errors from the CBMC output, which are messages that have the
279+
message type 'ERROR'
280+
"""
281+
errors = []
282+
for message in solver_information:
283+
if GlobalMessages.MESSAGE_TYPE in message and message[GlobalMessages.MESSAGE_TYPE] == 'ERROR':
284+
error_message = message[GlobalMessages.MESSAGE_TEXT]
285+
# Replace "--object bits n" with "--enable-unstable --cbmc-args
286+
# --object bits n" in the message
287+
if 'use the `--object-bits n` option' in error_message:
288+
error_message = error_message.replace("--object-bits ", "--enable-unstable --cbmc-args --object-bits ")
289+
errors.append(error_message)
290+
return errors
268291

269292
def postprocess_results(properties, extra_ptr_check):
270293
"""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
too many addressed objects: maximum number of objects is set to 2^n=32 (with n=5); use the `--enable-unstable --cbmc-args --object-bits n` option to increase the maximum number
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// Checks for error message with an --object-bits value that is too small
5+
6+
// kani-flags: --default-unwind 30 --enable-unstable --cbmc-args --object-bits 5
7+
8+
#[kani::proof]
9+
fn main() {
10+
let arr: [i32; 100] = kani::any();
11+
assert_eq!(arr[0], arr[99]);
12+
}

0 commit comments

Comments
 (0)