CBMC
ai_baset Class Reference

This is the basic interface of the abstract interpreter with default implementations of the core functionality. More...

#include <ai.h>

+ Inheritance diagram for ai_baset:
+ Collaboration diagram for ai_baset:

Public Types

typedef ai_domain_baset statet
 
typedef ai_storage_baset::cstate_ptrt cstate_ptrt
 
typedef ai_history_baset::trace_ptrt trace_ptrt
 
typedef ai_history_baset::trace_sett trace_sett
 
typedef ai_storage_baset::ctrace_set_ptrt ctrace_set_ptrt
 
typedef goto_programt::const_targett locationt
 

Public Member Functions

 ai_baset (std::unique_ptr< ai_history_factory_baset > &&hf, std::unique_ptr< ai_domain_factory_baset > &&df, std::unique_ptr< ai_storage_baset > &&st, message_handlert &mh)
 
virtual ~ai_baset ()
 
void operator() (const irep_idt &function_id, const goto_programt &goto_program, const namespacet &ns)
 Run abstract interpretation on a single function. More...
 
void operator() (const goto_functionst &goto_functions, const namespacet &ns)
 Run abstract interpretation on a whole program. More...
 
void operator() (const abstract_goto_modelt &goto_model)
 Run abstract interpretation on a whole program. More...
 
void operator() (const irep_idt &function_id, const goto_functionst::goto_functiont &goto_function, const namespacet &ns)
 Run abstract interpretation on a single function. More...
 
virtual ctrace_set_ptrt abstract_traces_before (locationt l) const
 Returns all of the histories that have reached the start of the instruction. More...
 
virtual ctrace_set_ptrt abstract_traces_after (locationt l) const
 Returns all of the histories that have reached the end of the instruction. More...
 
virtual cstate_ptrt abstract_state_before (locationt l) const
 Get a copy of the abstract state before the given instruction, without needing to know what kind of domain or history is used. More...
 
virtual cstate_ptrt abstract_state_after (locationt l) const
 Get a copy of the abstract state after the given instruction, without needing to know what kind of domain or history is used. More...
 
virtual cstate_ptrt abstract_state_before (const trace_ptrt &p) const
 The same interfaces but with histories. More...
 
virtual cstate_ptrt abstract_state_after (const trace_ptrt &p) const
 
virtual void clear ()
 Reset the abstract state. More...
 
virtual void output (const namespacet &ns, const irep_idt &function_id, const goto_programt &goto_program, std::ostream &out) const
 Output the abstract states for a single function. More...
 
virtual void output (const namespacet &ns, const goto_functionst &goto_functions, std::ostream &out) const
 Output the abstract states for a whole program. More...
 
void output (const goto_modelt &goto_model, std::ostream &out) const
 Output the abstract states for a whole program. More...
 
void output (const namespacet &ns, const goto_functionst::goto_functiont &goto_function, std::ostream &out) const
 Output the abstract states for a function. More...
 
virtual jsont output_json (const namespacet &ns, const goto_functionst &goto_functions) const
 Output the abstract states for the whole program as JSON. More...
 
jsont output_json (const goto_modelt &goto_model) const
 Output the abstract states for a whole program as JSON. More...
 
jsont output_json (const namespacet &ns, const goto_programt &goto_program) const
 Output the abstract states for a single function as JSON. More...
 
jsont output_json (const namespacet &ns, const goto_functionst::goto_functiont &goto_function) const
 Output the abstract states for a single function as JSON. More...
 
virtual xmlt output_xml (const namespacet &ns, const goto_functionst &goto_functions) const
 Output the abstract states for the whole program as XML. More...
 
xmlt output_xml (const goto_modelt &goto_model) const
 Output the abstract states for the whole program as XML. More...
 
xmlt output_xml (const namespacet &ns, const goto_programt &goto_program) const
 Output the abstract states for a single function as XML. More...
 
xmlt output_xml (const namespacet &ns, const goto_functionst::goto_functiont &goto_function) const
 Output the abstract states for a single function as XML. More...
 

Protected Types

typedef trace_sett working_sett
 The work queue, sorted using the history's ordering operator. More...
 

Protected Member Functions

virtual void initialize (const irep_idt &function_id, const goto_programt &goto_program)
 Initialize all the abstract states for a single function. More...
 
virtual void initialize (const irep_idt &function_id, const goto_functionst::goto_functiont &goto_function)
 Initialize all the abstract states for a single function. More...
 
virtual void initialize (const goto_functionst &goto_functions)
 Initialize all the abstract states for a whole program. More...
 
virtual void finalize ()
 Override this to add a cleanup or post-processing step after fixedpoint has run. More...
 
trace_ptrt entry_state (const goto_programt &goto_program)
 Set the abstract state of the entry location of a single function to the entry state required by the analysis. More...
 
trace_ptrt entry_state (const goto_functionst &goto_functions)
 Set the abstract state of the entry location of a whole program to the entry state required by the analysis. More...
 
virtual jsont output_json (const namespacet &ns, const irep_idt &function_id, const goto_programt &goto_program) const
 Output the abstract states for a single function as JSON. More...
 
virtual xmlt output_xml (const namespacet &ns, const irep_idt &function_id, const goto_programt &goto_program) const
 Output the abstract states for a single function as XML. More...
 
trace_ptrt get_next (working_sett &working_set)
 Get the next location from the work queue. More...
 
void put_in_working_set (working_sett &working_set, trace_ptrt t)
 
virtual bool fixedpoint (trace_ptrt starting_trace, const irep_idt &function_id, const goto_programt &goto_program, const goto_functionst &goto_functions, const namespacet &ns)
 Run the fixedpoint algorithm until it reaches a fixed point. More...
 
virtual void fixedpoint (trace_ptrt starting_trace, const goto_functionst &goto_functions, const namespacet &ns)
 
virtual bool visit (const irep_idt &function_id, trace_ptrt p, working_sett &working_set, const goto_programt &goto_program, const goto_functionst &goto_functions, const namespacet &ns)
 Perform one step of abstract interpretation from trace t Depending on the instruction type it may compute a number of "edges" or applications of the abstract transformer. More...
 
virtual bool visit_function_call (const irep_idt &function_id, trace_ptrt p_call, working_sett &working_set, const goto_programt &goto_program, const goto_functionst &goto_functions, const namespacet &ns)
 
virtual bool visit_end_function (const irep_idt &function_id, trace_ptrt p, working_sett &working_set, const goto_programt &goto_program, const goto_functionst &goto_functions, const namespacet &ns)
 
bool visit_edge (const irep_idt &function_id, trace_ptrt p, const irep_idt &to_function_id, locationt to_l, trace_ptrt caller_history, const namespacet &ns, working_sett &working_set)
 
virtual bool visit_edge_function_call (const irep_idt &calling_function_id, trace_ptrt p_call, locationt l_return, const irep_idt &callee_function_id, working_sett &working_set, const goto_programt &callee, const goto_functionst &goto_functions, const namespacet &ns)
 
virtual bool merge (const statet &src, trace_ptrt from, trace_ptrt to)
 Merge the state src, flowing from tracet from to tracet to, into the state currently stored for tracet to. More...
 
virtual std::unique_ptr< statetmake_temporary_state (const statet &s)
 Make a copy of a state. More...
 
virtual statetget_state (trace_ptrt p)
 Get the state for the given history, creating it with the factory if it doesn't exist. More...
 

Protected Attributes

std::unique_ptr< ai_history_factory_basethistory_factory
 For creating history objects. More...
 
std::unique_ptr< ai_domain_factory_basetdomain_factory
 For creating domain objects. More...
 
std::unique_ptr< ai_storage_basetstorage
 
message_handlertmessage_handler
 

Detailed Description

This is the basic interface of the abstract interpreter with default implementations of the core functionality.

Users of abstract interpreters should use the interface given by this class. It breaks into three categories:

  1. Running an analysis, via ai_baset::operator()(const irep_idt&,const goto_programt&, const namespacet&), ai_baset::operator()(const goto_functionst&,const namespacet&) and ai_baset::operator()(const abstract_goto_modelt&)
  2. Accessing the results of an analysis, by looking up the history objects for a given location l using ai_baset::abstract_traces_before(locationt)const or the domains using ai_baset::abstract_state_before(locationt)const
  3. Outputting the results of the analysis; see ai_baset::output(const namespacet&, const irep_idt&, const goto_programt&, std::ostream&)const et cetera.

Where possible, uses should be agnostic of the particular configuration of the abstract interpreter. The "tasks" that goto-analyze uses are good examples of how to do this.

From a development point of view, there are several directions in which this can be extended by inheriting from ai_baset or one of its children:

A. To change how single edges are computed ait::visit_edge and ait::visit_edge_function_call ai_recursive_interproceduralt uses this to recurse to evaluate function calls rather than approximating them as ai_baset does.

B. To change how individual instructions are handled ait::visit() and related functions.

C. To change the way that the fixed point is computed ait::fixedpoint() concurrency_aware_ait does this to compute a fixed point over threads.

D. For pre-analysis initialization ait::initialize(const irep_idt&, const goto_programt&), ait::initialize(const irep_idt&, const goto_functionst::goto_functiont&) and ait::initialize(const goto_functionst&),

E. For post-analysis cleanup ait::finalize(),

Historically, uses of abstract interpretation inherited from ait<domainT> and added the necessary functionality. This works (although care must be taken to respect the APIs of the various components – there are some hacks to support older analyses that didn't) but is discouraged in favour of having an object for the abstract interpreter and using its public API.

Definition at line 118 of file ai.h.

Member Typedef Documentation

◆ cstate_ptrt

Definition at line 122 of file ai.h.

◆ ctrace_set_ptrt

◆ locationt

Definition at line 126 of file ai.h.

◆ statet

Definition at line 121 of file ai.h.

◆ trace_ptrt

Definition at line 123 of file ai.h.

◆ trace_sett

Definition at line 124 of file ai.h.

◆ working_sett

The work queue, sorted using the history's ordering operator.

Definition at line 416 of file ai.h.

Constructor & Destructor Documentation

◆ ai_baset()

ai_baset::ai_baset ( std::unique_ptr< ai_history_factory_baset > &&  hf,
std::unique_ptr< ai_domain_factory_baset > &&  df,
std::unique_ptr< ai_storage_baset > &&  st,
message_handlert mh 
)
inline

Definition at line 128 of file ai.h.

◆ ~ai_baset()

virtual ai_baset::~ai_baset ( )
inlinevirtual

Definition at line 140 of file ai.h.

Member Function Documentation

◆ abstract_state_after() [1/2]

virtual cstate_ptrt ai_baset::abstract_state_after ( const trace_ptrt p) const
inlinevirtual

Definition at line 250 of file ai.h.

◆ abstract_state_after() [2/2]

virtual cstate_ptrt ai_baset::abstract_state_after ( locationt  l) const
inlinevirtual

Get a copy of the abstract state after the given instruction, without needing to know what kind of domain or history is used.

Note: intended for users of the abstract interpreter; derived classes should use get_state to access the actual underlying state.

Parameters
lThe location before which we want the abstract state
Returns
The abstract state after l. We return a pointer to a copy as the method should be const and there are some non-trivial cases including merging abstract states, etc.

PRECONDITION(l is dereferenceable && std::next(l) is dereferenceable) Check relies on a DATA_INVARIANT of goto_programs

Definition at line 236 of file ai.h.

◆ abstract_state_before() [1/2]

virtual cstate_ptrt ai_baset::abstract_state_before ( const trace_ptrt p) const
inlinevirtual

The same interfaces but with histories.

Definition at line 245 of file ai.h.

◆ abstract_state_before() [2/2]

virtual cstate_ptrt ai_baset::abstract_state_before ( locationt  l) const
inlinevirtual

Get a copy of the abstract state before the given instruction, without needing to know what kind of domain or history is used.

Note: intended for users of the abstract interpreter; derived classes should use get_state to access the actual underlying state. PRECONDITION(l is dereferenceable)

Parameters
lThe location before which we want the abstract state
Returns
The abstract state before l. We return a pointer to a copy as the method should be const and there are some non-trivial cases including merging abstract states, etc.

Definition at line 223 of file ai.h.

◆ abstract_traces_after()

virtual ctrace_set_ptrt ai_baset::abstract_traces_after ( locationt  l) const
inlinevirtual

Returns all of the histories that have reached the end of the instruction.

PRECONDITION(l is dereferenceable)

Parameters
lThe location before which we want the set of histories
Returns
The set of histories before l.

PRECONDITION(l is dereferenceable && std::next(l) is dereferenceable) Check relies on a DATA_INVARIANT of goto_programs

Definition at line 206 of file ai.h.

◆ abstract_traces_before()

virtual ctrace_set_ptrt ai_baset::abstract_traces_before ( locationt  l) const
inlinevirtual

Returns all of the histories that have reached the start of the instruction.

PRECONDITION(l is dereferenceable)

Parameters
lThe location before which we want the set of histories
Returns
The set of histories before l.

Definition at line 196 of file ai.h.

◆ clear()

virtual void ai_baset::clear ( )
inlinevirtual

Reset the abstract state.

Definition at line 267 of file ai.h.

◆ entry_state() [1/2]

ai_baset::trace_ptrt ai_baset::entry_state ( const goto_functionst goto_functions)
protected

Set the abstract state of the entry location of a whole program to the entry state required by the analysis.

Definition at line 166 of file ai.cpp.

◆ entry_state() [2/2]

ai_baset::trace_ptrt ai_baset::entry_state ( const goto_programt goto_program)
protected

Set the abstract state of the entry location of a single function to the entry state required by the analysis.

Definition at line 180 of file ai.cpp.

◆ finalize()

void ai_baset::finalize ( )
protectedvirtual

Override this to add a cleanup or post-processing step after fixedpoint has run.

Reimplemented in dependence_grapht, and variable_sensitivity_dependence_grapht.

Definition at line 207 of file ai.cpp.

◆ fixedpoint() [1/2]

void ai_baset::fixedpoint ( trace_ptrt  starting_trace,
const goto_functionst goto_functions,
const namespacet ns 
)
protectedvirtual

Reimplemented in concurrency_aware_ait< domainT >, and concurrency_aware_ait< rd_range_domaint >.

Definition at line 256 of file ai.cpp.

◆ fixedpoint() [2/2]

bool ai_baset::fixedpoint ( trace_ptrt  starting_trace,
const irep_idt function_id,
const goto_programt goto_program,
const goto_functionst goto_functions,
const namespacet ns 
)
protectedvirtual

Run the fixedpoint algorithm until it reaches a fixed point.

Returns
True if we found something new

Definition at line 230 of file ai.cpp.

◆ get_next()

ai_baset::trace_ptrt ai_baset::get_next ( working_sett working_set)
protected

Get the next location from the work queue.

Definition at line 212 of file ai.cpp.

◆ get_state()

virtual statet& ai_baset::get_state ( trace_ptrt  p)
inlineprotectedvirtual

Get the state for the given history, creating it with the factory if it doesn't exist.

Definition at line 517 of file ai.h.

◆ initialize() [1/3]

void ai_baset::initialize ( const goto_functionst goto_functions)
protectedvirtual

Initialize all the abstract states for a whole program.

Override this to do custom per-analysis initialization.

Reimplemented in reaching_definitions_analysist, dependence_grapht, custom_bitvector_analysist, escape_analysist, and global_may_alias_analysist.

Definition at line 201 of file ai.cpp.

◆ initialize() [2/3]

void ai_baset::initialize ( const irep_idt function_id,
const goto_functionst::goto_functiont goto_function 
)
protectedvirtual

Initialize all the abstract states for a single function.

Definition at line 188 of file ai.cpp.

◆ initialize() [3/3]

void ai_baset::initialize ( const irep_idt function_id,
const goto_programt goto_program 
)
protectedvirtual

Initialize all the abstract states for a single function.

Override this to do custom per-domain initialization.

Reimplemented in variable_sensitivity_dependence_grapht, invariant_propagationt, and dependence_grapht.

Definition at line 195 of file ai.cpp.

◆ make_temporary_state()

virtual std::unique_ptr<statet> ai_baset::make_temporary_state ( const statet s)
inlineprotectedvirtual

Make a copy of a state.

Definition at line 507 of file ai.h.

◆ merge()

virtual bool ai_baset::merge ( const statet src,
trace_ptrt  from,
trace_ptrt  to 
)
inlineprotectedvirtual

Merge the state src, flowing from tracet from to tracet to, into the state currently stored for tracet to.

Definition at line 500 of file ai.h.

◆ operator()() [1/4]

void ai_baset::operator() ( const abstract_goto_modelt goto_model)
inline

Run abstract interpretation on a whole program.

Definition at line 169 of file ai.h.

◆ operator()() [2/4]

void ai_baset::operator() ( const goto_functionst goto_functions,
const namespacet ns 
)
inline

Run abstract interpretation on a whole program.

Definition at line 158 of file ai.h.

◆ operator()() [3/4]

void ai_baset::operator() ( const irep_idt function_id,
const goto_functionst::goto_functiont goto_function,
const namespacet ns 
)
inline

Run abstract interpretation on a single function.

Definition at line 179 of file ai.h.

◆ operator()() [4/4]

void ai_baset::operator() ( const irep_idt function_id,
const goto_programt goto_program,
const namespacet ns 
)
inline

Run abstract interpretation on a single function.

Definition at line 145 of file ai.h.

◆ output() [1/4]

void ai_baset::output ( const goto_modelt goto_model,
std::ostream &  out 
) const
inline

Output the abstract states for a whole program.

Definition at line 291 of file ai.h.

◆ output() [2/4]

void ai_baset::output ( const namespacet ns,
const goto_functionst goto_functions,
std::ostream &  out 
) const
virtual

Output the abstract states for a whole program.

Definition at line 21 of file ai.cpp.

◆ output() [3/4]

void ai_baset::output ( const namespacet ns,
const goto_functionst::goto_functiont goto_function,
std::ostream &  out 
) const
inline

Output the abstract states for a function.

Definition at line 300 of file ai.h.

◆ output() [4/4]

void ai_baset::output ( const namespacet ns,
const irep_idt function_id,
const goto_programt goto_program,
std::ostream &  out 
) const
virtual

Output the abstract states for a single function.

Parameters
nsThe namespace
function_idThe identifier used to find a symbol to identify the goto_program's source language
goto_programThe goto program
outThe ostream to direct output to

Definition at line 40 of file ai.cpp.

◆ output_json() [1/5]

jsont ai_baset::output_json ( const goto_modelt goto_model) const
inline

Output the abstract states for a whole program as JSON.

Definition at line 314 of file ai.h.

◆ output_json() [2/5]

jsont ai_baset::output_json ( const namespacet ns,
const goto_functionst goto_functions 
) const
virtual

Output the abstract states for the whole program as JSON.

Definition at line 62 of file ai.cpp.

◆ output_json() [3/5]

jsont ai_baset::output_json ( const namespacet ns,
const goto_functionst::goto_functiont goto_function 
) const
inline

Output the abstract states for a single function as JSON.

Definition at line 330 of file ai.h.

◆ output_json() [4/5]

jsont ai_baset::output_json ( const namespacet ns,
const goto_programt goto_program 
) const
inline

Output the abstract states for a single function as JSON.

Definition at line 322 of file ai.h.

◆ output_json() [5/5]

jsont ai_baset::output_json ( const namespacet ns,
const irep_idt function_id,
const goto_programt goto_program 
) const
protectedvirtual

Output the abstract states for a single function as JSON.

Parameters
nsThe namespace
goto_programThe goto program
function_idThe identifier used to find a symbol to identify the source language
Returns
The JSON object

Definition at line 84 of file ai.cpp.

◆ output_xml() [1/5]

xmlt ai_baset::output_xml ( const goto_modelt goto_model) const
inline

Output the abstract states for the whole program as XML.

Definition at line 343 of file ai.h.

◆ output_xml() [2/5]

xmlt ai_baset::output_xml ( const namespacet ns,
const goto_functionst goto_functions 
) const
virtual

Output the abstract states for the whole program as XML.

Definition at line 111 of file ai.cpp.

◆ output_xml() [3/5]

xmlt ai_baset::output_xml ( const namespacet ns,
const goto_functionst::goto_functiont goto_function 
) const
inline

Output the abstract states for a single function as XML.

Definition at line 359 of file ai.h.

◆ output_xml() [4/5]

xmlt ai_baset::output_xml ( const namespacet ns,
const goto_programt goto_program 
) const
inline

Output the abstract states for a single function as XML.

Definition at line 351 of file ai.h.

◆ output_xml() [5/5]

xmlt ai_baset::output_xml ( const namespacet ns,
const irep_idt function_id,
const goto_programt goto_program 
) const
protectedvirtual

Output the abstract states for a single function as XML.

Parameters
nsThe namespace
goto_programThe goto program
function_idThe identifier used to find a symbol to identify the source language
Returns
The XML object

Definition at line 137 of file ai.cpp.

◆ put_in_working_set()

void ai_baset::put_in_working_set ( working_sett working_set,
trace_ptrt  t 
)
inlineprotected

Definition at line 421 of file ai.h.

◆ visit()

bool ai_baset::visit ( const irep_idt function_id,
trace_ptrt  p,
working_sett working_set,
const goto_programt goto_program,
const goto_functionst goto_functions,
const namespacet ns 
)
protectedvirtual

Perform one step of abstract interpretation from trace t Depending on the instruction type it may compute a number of "edges" or applications of the abstract transformer.

Returns
True if the state was changed

Definition at line 268 of file ai.cpp.

◆ visit_edge()

bool ai_baset::visit_edge ( const irep_idt function_id,
trace_ptrt  p,
const irep_idt to_function_id,
locationt  to_l,
trace_ptrt  caller_history,
const namespacet ns,
working_sett working_set 
)
protected

Definition at line 329 of file ai.cpp.

◆ visit_edge_function_call()

bool ai_baset::visit_edge_function_call ( const irep_idt calling_function_id,
trace_ptrt  p_call,
locationt  l_return,
const irep_idt callee_function_id,
working_sett working_set,
const goto_programt callee,
const goto_functionst goto_functions,
const namespacet ns 
)
protectedvirtual

Reimplemented in ai_recursive_interproceduralt, and ai_three_way_merget.

Definition at line 414 of file ai.cpp.

◆ visit_end_function()

bool ai_baset::visit_end_function ( const irep_idt function_id,
trace_ptrt  p,
working_sett working_set,
const goto_programt goto_program,
const goto_functionst goto_functions,
const namespacet ns 
)
protectedvirtual

Definition at line 521 of file ai.cpp.

◆ visit_function_call()

bool ai_baset::visit_function_call ( const irep_idt function_id,
trace_ptrt  p_call,
working_sett working_set,
const goto_programt goto_program,
const goto_functionst goto_functions,
const namespacet ns 
)
protectedvirtual

Definition at line 442 of file ai.cpp.

Member Data Documentation

◆ domain_factory

std::unique_ptr<ai_domain_factory_baset> ai_baset::domain_factory
protected

For creating domain objects.

Definition at line 496 of file ai.h.

◆ history_factory

std::unique_ptr<ai_history_factory_baset> ai_baset::history_factory
protected

For creating history objects.

Definition at line 493 of file ai.h.

◆ message_handler

message_handlert& ai_baset::message_handler
protected

Definition at line 523 of file ai.h.

◆ storage

std::unique_ptr<ai_storage_baset> ai_baset::storage
protected

Definition at line 513 of file ai.h.


The documentation for this class was generated from the following files: