Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions kani-compiler/src/codegen_cprover_gotoc/overrides/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,19 @@ impl GotocHook for LoopInvariantRegister {
) -> Stmt {
let loc = gcx.codegen_span_stable(span);
let func_exp = gcx.codegen_func_expr(instance, loc);

Stmt::goto(bb_label(target.unwrap()), loc)
.with_loop_contracts(func_exp.call(fargs).cast_to(Type::CInteger(CIntType::Bool)))
// Add `free(0)` to make sure the body of `free` won't be dropped to
// satisfy the requirement of DFCC.
Stmt::block(
vec![
BuiltinFn::Free
.call(vec![Expr::pointer_constant(0, Type::void_pointer())], loc)
.as_stmt(loc),
Stmt::goto(bb_label(target.unwrap()), loc).with_loop_contracts(
func_exp.call(fargs).cast_to(Type::CInteger(CIntType::Bool)),
),
],
loc,
)
}
}

Expand Down
4 changes: 0 additions & 4 deletions tests/expected/loop-contract/count_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,5 @@ const fn count_zero(slice: &[u8]) -> usize {

#[kani::proof]
pub fn check_counter() {
// Needed to avoid having `free` be removed as unused function. This is
// because DFCC contract enforcement assumes that a definition for `free`
// exists.
let _ = Box::new(10);
assert_eq!(count_zero(&[1, 2, 3]), 0)
}
4 changes: 0 additions & 4 deletions tests/expected/loop-contract/memchar_naive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@

#[kani::proof]
fn memchar_naive_harness() {
// Needed to avoid having `free` be removed as unused function. This is
// because DFCC contract enforcement assumes that a definition for `free`
// exists.
let _ = Box::new(10);
let text = [1, 2, 3, 4, 5];
let x = 5;
let mut i = 0;
Expand Down
4 changes: 0 additions & 4 deletions tests/expected/loop-contract/multiple_loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ fn simple_while_loops() {

#[kani::proof]
fn multiple_loops_harness() {
// Needed to avoid having `free` be removed as unused function. This is
// because DFCC contract enforcement assumes that a definition for `free`
// exists.
let _ = Box::new(10);
multiple_loops();
simple_while_loops();
}
5 changes: 0 additions & 5 deletions tests/expected/loop-contract/simple_while_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
#![feature(proc_macro_hygiene)]

#[kani::proof]
#[kani::solver(kissat)]
fn simple_while_loop_harness() {
// Needed to avoid having `free` be removed as unused function. This is
// because DFCC contract enforcement assumes that a definition for `free`
// exists.
let _ = Box::new(10);
let mut x: u8 = kani::any_where(|i| *i >= 2);

#[kani::loop_invariant(x >= 2)]
Expand Down
4 changes: 0 additions & 4 deletions tests/expected/loop-contract/small_slice_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ unsafe fn small_slice_eq(x: &[u8], y: &[u8]) -> bool {

#[kani::proof]
fn small_slice_eq_harness() {
// Needed to avoid having `free` be removed as unused function. This is
// because DFCC contract enforcement assumes that a definition for `free`
// exists.
let _ = Box::new(10);
const ARR_SIZE: usize = 2000;
let x: [u8; ARR_SIZE] = kani::any();
let y: [u8; ARR_SIZE] = kani::any();
Expand Down
Loading