Skip to content

Commit 432b652

Browse files
committed
Prefix property descriptions of panics with "Panic:"
This will reduce the ambiguity between cases of Kani reporting a safety (undefined behavior) violation vs Kani demonstrating the possibility of a panic (defined behavior).
1 parent 7209765 commit 432b652

File tree

176 files changed

+409
-398
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+409
-398
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
FAILURE\
2-
Description: "assertion failed: arr.len() != 3"
2+
Description: "Panic: assertion failed: arr.len() != 3"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
SUCCESS\
2-
Description: "assertion failed: sum == 6"
2+
Description: "Panic: assertion failed: sum == 6"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
UNDETERMINED\
2-
Description: "assertion failed: x == 0"
2+
Description: "Panic: assertion failed: x == 0"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
UNREACHABLE\
2-
Description: "assertion failed: x < 8"
2+
Description: "Panic: assertion failed: x < 8"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl GotocCtx<'_> {
231231
// If there is one in the MIR, use it; otherwise, explain that we can't.
232232
assert!(!fargs.is_empty(), "Panic requires a string message");
233233
let msg = self.extract_const_message(&fargs[0]).unwrap_or(String::from(
234-
"This is a placeholder message; Kani doesn't support message formatted at runtime",
234+
"Panic: This is a placeholder message; Kani doesn't support message formatted at runtime",
235235
));
236236
self.codegen_fatal_error(PropertyClass::Assertion, &msg, span)
237237
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl GotocCtx<'_> {
261261
// "index out of bounds: the length is {len} but the index is {index}",
262262
// but CBMC only accepts static messages so we don't add values to the message.
263263
(
264-
"index out of bounds: the length is less than or equal to the given index",
264+
"Panic: index out of bounds: the length is less than or equal to the given index".to_string(),
265265
PropertyClass::Assertion,
266266
)
267267
}
@@ -270,22 +270,23 @@ impl GotocCtx<'_> {
270270
// Generate a generic one here.
271271
(
272272
"misaligned pointer dereference: address must be a multiple of its type's \
273-
alignment",
273+
alignment".to_string(),
274274
PropertyClass::SafetyCheck,
275275
)
276276
}
277277
// For all other assert kind we can get the static message.
278278
AssertMessage::NullPointerDereference => {
279-
(msg.description().unwrap(), PropertyClass::SafetyCheck)
279+
(msg.description().unwrap().to_string(), PropertyClass::SafetyCheck)
280280
}
281281
AssertMessage::Overflow { .. }
282282
| AssertMessage::OverflowNeg { .. }
283283
| AssertMessage::DivisionByZero { .. }
284284
| AssertMessage::RemainderByZero { .. }
285285
| AssertMessage::ResumedAfterReturn { .. }
286-
| AssertMessage::ResumedAfterPanic { .. } => {
287-
(msg.description().unwrap(), PropertyClass::Assertion)
288-
}
286+
| AssertMessage::ResumedAfterPanic { .. } => (
287+
"Panic: ".to_owned() + msg.description().unwrap(),
288+
PropertyClass::Assertion,
289+
),
289290
};
290291

291292
let (msg_str, reach_stmt) =

kani-compiler/src/codegen_cprover_gotoc/overrides/hooks.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ impl GotocHook for Assert {
137137
Stmt::block(
138138
vec![
139139
reach_stmt,
140-
gcx.codegen_assert_assume(cond, PropertyClass::Assertion, &msg, caller_loc),
140+
gcx.codegen_assert_assume(
141+
cond,
142+
PropertyClass::Assertion,
143+
&("Panic: ".to_owned() + &msg),
144+
caller_loc,
145+
),
141146
Stmt::goto(bb_label(target), caller_loc),
142147
],
143148
caller_loc,
@@ -272,7 +277,12 @@ impl GotocHook for Check {
272277
Stmt::block(
273278
vec![
274279
reach_stmt,
275-
gcx.codegen_assert(cond, PropertyClass::Assertion, &msg, caller_loc),
280+
gcx.codegen_assert(
281+
cond,
282+
PropertyClass::Assertion,
283+
&("Panic: ".to_owned() + &msg),
284+
caller_loc,
285+
),
276286
Stmt::goto(bb_label(target), caller_loc),
277287
],
278288
caller_loc,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Status: SUCCESS\
2-
Description: "assertion failed: x * y == 33"
2+
Description: "Panic: assertion failed: x * y == 33"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Status: SUCCESS\
2-
Description: "assertion failed: x == 98"
2+
Description: "Panic: assertion failed: x == 98"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
UNREACHABLE\
2-
Description: "assertion failed: z == x - 1"
2+
Description: "Panic: assertion failed: z == x - 1"

0 commit comments

Comments
 (0)