CBMC
|
Back to top Code Contracts Transformation Specification
Frame condition checking consists in checking that a function (and any functions it calls) only assigns to memory locations allowed by the contract's assigns clause, and only deallocates objects allowed by the contract's frees clause.
To implement frame condition checking we use a method inspired by Dynamic Frames.
The method consists in:
In our approach a dynamic frame is represented by the __CPROVER_contracts_write_set_t data type defined in cprover_contracts.c.
From an simple point of view, a __CPROVER_contracts_write_set_t tracks 4 sets of memory locations:
contract_assigns
is the set of memory locations specified in the assigns clause of the contract of interest;contract_frees
is the set of pointers specified in the frees clause of the contract of interest;allocated
is the set of identifiers of objects (as given by __CPROVER_POINTER_OBJECT(x)
) that were locally allocated since first entering the function under verification (on the stack using DECL x
or on the heap using x = __CPROVER_allocate(...)
);deallocated
is the set of pointers p
that were deallocated using __CPROVER_deallocate(p)
since first entering the function under verification.The __CPROVER_contracts_write_set_t type is accompanied by functions allowing to (cf cprover_contracts.c):
contract_assigns
;contract_frees
;allocated
;deallocated
;car_t
describing a location about to be assigned is contained within contract_assigns
or allocated
;contract_frees
or allocated
;The instrumentation adds a __CPROVER_contracts_write_set_ptr_t parameter to all functions of the GOTO model as follows:
The bodies of the functions are instrumented so that:
write_set
is NULL
, no checks are performed;write_set
is not NULL
, the following checks are performed:contract_assigns
or allocated
;DECL
) and heap-allocated objects (__CPROVER_allocate
) are recorded in allocated
__CPROVER_deallocate
are checked for inclusion in contract_frees
or allocated
, and are recorded in deallocated
(so that contract postconditions about deallocations can be checked).write_set
parameter is propagated to functions calls or function pointer calls.Prev | Next |
---|---|
Code Contracts Developer Documentation | Write Set Representation |