Skip to content

Commit 946263e

Browse files
author
Carolyn Zech
authored
Clarify Rust intrinsic assumption error message (#4015)
"assumption failed" is mysterious--the user will likely conclude that a `kani::assume` failed, when in fact this is an assume introduced by the Rust compiler to perform optimizations. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent 59b25fd commit 946263e

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl GotocCtx<'_> {
299299
Intrinsic::Assume => self.codegen_assert_assume(
300300
fargs.remove(0).cast_to(Type::bool()),
301301
PropertyClass::Assume,
302-
"assumption failed",
302+
"Rust intrinsic assumption failed",
303303
loc,
304304
),
305305
Intrinsic::AtomicAnd(_) => codegen_atomic_binop!(bitand),

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,15 @@ impl GotocCtx<'_> {
151151
let farg_types = operands.map(|op| self.operand_ty_stable(&op));
152152
self.codegen_copy("copy_nonoverlapping", true, fargs, &farg_types, None, location)
153153
}
154+
// https://doc.rust-lang.org/beta/nightly-rustc/rustc_middle/mir/enum.NonDivergingIntrinsic.html#variant.Assume
155+
// Informs the optimizer that a condition is always true.
156+
// If the condition is false, the behavior is undefined.
154157
StatementKind::Intrinsic(NonDivergingIntrinsic::Assume(ref op)) => {
155158
let cond = self.codegen_operand_stable(op).cast_to(Type::bool());
156159
self.codegen_assert_assume(
157160
cond,
158161
PropertyClass::Assume,
159-
"assumption failed",
162+
"Rust intrinsic assumption failed",
160163
location,
161164
)
162165
}

tests/expected/any_vec/exact_length.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Checking harness check_access_length_17...
22

3-
Failed Checks: assumption failed\
3+
Failed Checks: Rust intrinsic assumption failed\
44
in <usize as std::slice::SliceIndex<[u8]>>::get_unchecked
55

66
Checking harness check_access_length_zero...
77

8-
Failed Checks: assumption failed\
8+
Failed Checks: Rust intrinsic assumption failed\
99
in <usize as std::slice::SliceIndex<[u8]>>::get_unchecked
1010

1111
Verification failed for - check_access_length_17
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Checking harness check_always_out_bounds...
22

3-
Failed Checks: assumption failed
3+
Failed Checks: Rust intrinsic assumption failed
44
in <usize as std::slice::SliceIndex<[u8]>>::get_unchecked
55

66
Verification failed for - check_always_out_bounds

0 commit comments

Comments
 (0)