CBMC
|
A frees clause allows the user to specify a set of pointers that may be freed by a function or by the function it calls, transitively. A function contract may have zero or more frees clauses. When no clause is provided the empty set is used as default. Contracts can also have an empty frees clause. When more than one frees clause is given, the sets of pointers they contain are unioned together to yield a single set of pointers.
The clause has the following syntax (square brackets denote optional expressions [
]
):
Where targets
has the following syntax:
A frees clause target must be either:
__CPROVER_freeable
void
(itself containing direct or indirect calls to __CPROVER_freeable
or to functions that call __CPROVER_freeable
);The set of pointers specified by the frees clause of the contract is interpreted at the function call-site where the contract is being checked or used to abstract a function call.
When checking a contract against a function, each pointer that the function attempts to free gets checked for membership in the set of pointers specified by the frees clause.
When replacing a function call by a contract, each pointer of the frees clause gets non-deterministically freed between the evaluation of preconditions and before the evaluation of post-conditions.
Users can define parametric sets of freeable pointers by writing functions that return the void
type and call (directly or indirectly) the built-in function __CPROVER_freeable
:
Calling the built-in function:
in the context of a frees clause specifies that ptr
is freeable in that context.
The predicate:
can only be used in pre and post conditions, in contract checking or replacement modes. It returns true
if and only if the pointer satisfies the preconditions of the free
function from stdlib.h
(see here), that is if and only if the pointer points to a valid dynamically allocated object and has offset zero.
The predicate:
can only be used in post conditions and returns true
if and only if the pointer was freed during the execution of the function under analysis.