Open jaisnan opened 1 month ago
I am sorry, I don't understand how to reproduce this. Where can I find that let _ = std::boxed::Box::new(0_usize);
that needs to be removed in order to observe the problem?
Contracts instrumentation attempts to load free
from the CPROVER library no matter what the GOTO model contains
The contracts instrumentation assumes that if an entry for a library function like free
is found in the symbol table then the body of the function is present too, and it doesn't attempt to force-load the function. So the only way contracts would not load the free
function into the model is if the symbol table produced by Kani contains an entry for the free
function but does not contain the body of the function.
The output mentioning builtin-library-free suggests it is loaded, so I’m quite confused what is actually going on here. Needs details to reproduce and debug.
This is an extract of kani_lib.c
// Declare functions instead of importing more headers in order to avoid conflicting definitions.
// See https://github.com/model-checking/kani/issues/1774 for more details.
void free(void *ptr);
void *memcpy(void *dst, const void *src, size_t n);
void *calloc(size_t nmemb, size_t size);
Could these declarations result in an entry being present for free
in the symbol table but the value of the symbol being absent ? or the entry being present but the GOTO function being pruned if its not actually used before contracts instrumentation is applied ?
file <builtin-library-free>
really suggests that we are reading (using?) the definition from CBMC's library, though admittedly this is part of a warning, so it could be that we don't actually link in the implementation. So, still, we need a way to actually reproduce this.
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,
When we remove the culprit line
let _ = std::boxed::Box::new(0_usize);
. We get the following error from CBMC: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"