Back to top Code Contracts Transformation Specification
Let us now consider a function bar
, called directly or indirectly from main
.
Assuming that bar
satisfies a contract d
, we want to replace bar
with an abstraction derived from d
. Checking that bar
actually satisfies d
is the responsibility of the user, and will usually be done using another proof harness.
int d(int *a)
__CPROVER_requires(R)
__CPROVER_ensures(E)
__CPROVER_assigns({a1, a2, ...})
__CPROVER_frees({f1, f2, ...})
;
int bar(int *a)
{
}
We abstract bar
by replacing its instructions with instructions modelling the non-deterministic behavior of the contract d
, following this template:
ret_t foo(foo_params, write_set_t caller_write_set) {
assert(contract::requires(foo_params, requires_write_set));
hist1_t hist1 = ...;
hist2_t hist2 = ...;
contract::assigns(contract_write_set, empty_write_set);
contract::frees(contract_write_set, empty_write_set);
contract::havoc(contract_write_set);
ret_t retval = nondet();
__CPROVER_contracts_write_set_link_allocated(ensures_write_set, caller_write_set);
__CPROVER_contracts_write_set_link_deallocated(ensures_write_set, contract_write_set);
assume(contract::ensures(foo_params, ensures_write_set));
return retval;
}
void __CPROVER_contracts_write_set_deallocate_freeable(__CPROVER_contracts_write_set_ptr_t set, __CPROVER_contracts_write_set_ptr_t target)
Non-deterministically call __CPROVER_contracts_free on all elements of set->contract_frees,...
void __CPROVER_contracts_write_set_release(__CPROVER_contracts_write_set_ptr_t set)
Releases resources used by set.
__CPROVER_bool __CPROVER_contracts_write_set_check_assigns_clause_inclusion(__CPROVER_contracts_write_set_ptr_t reference, __CPROVER_contracts_write_set_ptr_t candidate)
Checks the inclusion of the candidate->contract_assigns elements in reference->contract_assigns or re...
void __CPROVER_contracts_write_set_create(__CPROVER_contracts_write_set_ptr_t set, __CPROVER_size_t contract_assigns_size, __CPROVER_size_t contract_frees_size, __CPROVER_bool assume_requires_ctx, __CPROVER_bool assert_requires_ctx, __CPROVER_bool assume_ensures_ctx, __CPROVER_bool assert_ensures_ctx, __CPROVER_bool allow_allocate, __CPROVER_bool allow_deallocate)
Initialises a __CPROVER_contracts_write_set_t object.
__CPROVER_bool __CPROVER_contracts_write_set_check_frees_clause_inclusion(__CPROVER_contracts_write_set_ptr_t reference, __CPROVER_contracts_write_set_ptr_t candidate)
Checks the inclusion of the candidate->contract_frees elements in reference->contract_frees or refere...
__CPROVER_bool __CPROVER_contracts_write_set_check_allocated_deallocated_is_empty(__CPROVER_contracts_write_set_ptr_t set)
Returns true iff set->deallocated is empty.
Runtime representation of a write set.
After applying this transformation, any function that called the initial bar
now calls the abstraction derived from the contract.