Open
Description
CBMC currently needs free
to be in scope. In order to enforce this, Kani currently creates an empty Box before to force free to be in scope.
The workaround on Kani's side looks like this,
// Filling the body of a contract
pub fn proof_for_contract(attr: TokenStream, item: TokenStream) -> TokenStream {
let args = proc_macro2::TokenStream::from(attr);
let ItemFn { attrs, vis, sig, block } = parse_macro_input!(item as ItemFn);
quote!(
#[allow(dead_code)]
#[kanitool::proof_for_contract = stringify!(#args)]
#(#attrs)*
#vis #sig {
let _ = std::boxed::Box::new(0_usize);
#block
}
)
.into()
}
When we remove the culprit line let _ = std::boxed::Box::new(0_usize);
. We get the following error from CBMC:
error: test failed: expected output to contain the line(s):
Failed Checks: |result : &T| *result != 0 && x % *result == 1 && y % *result == 0
status: exit status: 1
command: "kani" "/home/ubuntu/kani/tests/expected/function-contract/gcd_rec_contract_fail.rs" "-Zfunction-contracts"
stdout:
------------------------------------------
Kani Rust Verifier 0.52.0 (standalone)
Reading GOTO program from '/home/ubuntu/kani/tests/expected/function-contract/gcd_rec_contract_fail__RNvCsjbTzZZm4LvF_21gcd_rec_contract_fail14simple_harness.out'
Function Pointer Removal
Virtual function removal
Cleaning inline assembler statements
Loading CPROVER C library (x86_64)
Adding the cprover_contracts library (x86_64)
Contract '_RNvCsjbTzZZm4LvF_21gcd_rec_contract_fail18gcd_wrapper_7a7962' not found, deriving empty pure contract 'contract::_RNvCsjbTzZZm4LvF_21gcd_rec_contract_fail18gcd_wrapper_7a7962' from function '_RNvCsjbTzZZm4LvF_21gcd_rec_contract_fail18gcd_wrapper_7a7962'
file <builtin-library-malloc> line 6: symbol '__CPROVER_malloc_is_new_array' already has an initial value
symbol '__CPROVER_alloca_object' already has an initial value
symbol '__CPROVER_new_object' already has an initial value
file <builtin-library-free> line 11: symbol '__CPROVER_malloc_is_new_array' already has an initial value
file <builtin-library-__CPROVER_contracts_library> line 1048 function __CPROVER_contracts_write_set_deallocate_freeable: no body for function 'free'
No body for 'free' during inlining
Numeric exception : 0
error: goto-instrument exited with status exit status: 6
CBMC version: 5.95.1
Operating system: Both Ubuntu 22.04.4
Exact command line resulting in the issue:
"kani" "/home/ubuntu/kani/tests/expected/function-contract/gcd_rec_contract_fail.rs" "-Zfunction-contracts"