CBMC
|
A very simple, cheap analysis to determine when dereference operations are trivially guarded by a check against a null pointer access. More...
#include <local_safe_pointers.h>
Classes | |
struct | type_comparet |
Comparator that regards type-equal expressions as equal, and otherwise uses the natural (operator<) ordering on irept. More... | |
Public Member Functions | |
void | operator() (const goto_programt &goto_program) |
Compute safe dereference expressions for a given GOTO program. More... | |
bool | is_non_null_at_program_point (const exprt &expr, goto_programt::const_targett program_point) |
Return true if the local-safe-pointers analysis has determined expr cannot be null as of program_point (i.e. More... | |
bool | is_safe_dereference (const dereference_exprt &deref, goto_programt::const_targett program_point) |
void | output (std::ostream &stream, const goto_programt &program, const namespacet &ns) |
Output non-null expressions per instruction in human-readable format. More... | |
void | output_safe_dereferences (std::ostream &stream, const goto_programt &program, const namespacet &ns) |
Output safely dereferenced expressions per instruction in human-readable format. More... | |
Private Attributes | |
std::map< unsigned, std::set< exprt, type_comparet > > | non_null_expressions |
A very simple, cheap analysis to determine when dereference operations are trivially guarded by a check against a null pointer access.
In the interests of a very cheap analysis we only search for very local guards – at the moment only if(x != null) { *x }
and assume(x != null); *x
are handled. Control-flow convergence and possibly-aliasing operations are handled pessimistically.
Definition at line 27 of file local_safe_pointers.h.
bool local_safe_pointerst::is_non_null_at_program_point | ( | const exprt & | expr, |
goto_programt::const_targett | program_point | ||
) |
Return true if the local-safe-pointers analysis has determined expr
cannot be null as of program_point
(i.e.
that expr
is non-null when the program_point
instruction starts executing)
Definition at line 278 of file local_safe_pointers.cpp.
|
inline |
Definition at line 47 of file local_safe_pointers.h.
void local_safe_pointerst::operator() | ( | const goto_programt & | goto_program | ) |
Compute safe dereference expressions for a given GOTO program.
This populates non_null_expressions
mapping instruction location numbers onto a set of expressions that are known to be non-null BEFORE that instruction is executed.
goto_program | program to analyse |
Definition at line 82 of file local_safe_pointers.cpp.
void local_safe_pointerst::output | ( | std::ostream & | out, |
const goto_programt & | goto_program, | ||
const namespacet & | ns | ||
) |
Output non-null expressions per instruction in human-readable format.
out | stream to write output to |
goto_program | GOTO program analysed (the same one passed to operator()) |
ns | namespace |
Definition at line 189 of file local_safe_pointers.cpp.
void local_safe_pointerst::output_safe_dereferences | ( | std::ostream & | out, |
const goto_programt & | goto_program, | ||
const namespacet & | ns | ||
) |
Output safely dereferenced expressions per instruction in human-readable format.
For example, if we have an instruction ASSUME x->y->z == a->b
and we know expressions x->y
, a
and other
are not null prior to it, this will print {x->y, a}
, the intersection of the dereference_exprt
s used here and the known-not-null expressions.
out | stream to write output to |
goto_program | GOTO program analysed (the same one passed to operator()) |
ns | namespace |
Definition at line 233 of file local_safe_pointers.cpp.
|
private |
Definition at line 39 of file local_safe_pointers.h.