CBMC
Loading...
Searching...
No Matches
escape_analysis.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Field-insensitive, location-sensitive, over-approximative
4 escape analysis
5
6Author: Daniel Kroening, kroening@kroening.com
7
8\*******************************************************************/
9
12
13#ifndef CPROVER_ANALYSES_ESCAPE_ANALYSIS_H
14#define CPROVER_ANALYSES_ESCAPE_ANALYSIS_H
15
16#include <util/numbering.h>
17#include <util/threeval.h>
18#include <util/union_find.h>
19
20#include "ai.h"
21
23{
24public:
28
29 void transform(
32 const irep_idt &function_to,
34 ai_baset &ai,
35 const namespacet &ns) final override;
36
37 void output(
38 std::ostream &out,
39 const ai_baset &ai,
40 const namespacet &ns) const final override;
41
43
44 void make_bottom() final override
45 {
47 aliases.clear();
48 has_values=tvt(false);
49 }
50
51 void make_top() final override
52 {
54 aliases.clear();
55 has_values=tvt(true);
56 }
57
59 {
61 (cleanup_map.empty() && (aliases.size()==0)),
62 "If the domain is bottom, all maps must be empty");
63 return has_values.is_false();
64 }
65
66 bool is_top() const override final
67 {
69 (cleanup_map.empty() && (aliases.size()==0)),
70 "If the domain is top, all maps must be empty");
71 return has_values.is_true();
72 }
73
76
77 struct cleanupt
78 {
79 std::set<irep_idt> cleanup_functions;
80 };
81
82 // We track a set of 'cleanup functions' for specific
83 // identifiers. The cleanup functions are executed
84 // once the last pointer to an object is lost.
85 typedef std::map<irep_idt, cleanupt> cleanup_mapt;
87
88private:
90 void assign_lhs_cleanup(const exprt &, const std::set<irep_idt> &);
91 void get_rhs_cleanup(const exprt &, std::set<irep_idt> &);
92 void assign_lhs_aliases(const exprt &, const std::set<irep_idt> &);
93 void get_rhs_aliases(const exprt &, std::set<irep_idt> &);
94 void get_rhs_aliases_address_of(const exprt &, std::set<irep_idt> &);
96 void check_lhs(const exprt &, std::set<irep_idt> &) const;
97
98 friend class escape_analysist;
99
100 bool is_tracked(const symbol_exprt &);
101};
102
103class escape_analysist:public ait<escape_domaint>
104{
105public:
106 void instrument(goto_modelt &);
107
108protected:
109 virtual void initialize(const goto_functionst &)
110 {
111 }
112
114
115 void insert_cleanup(
118 const exprt &,
119 const std::set<irep_idt> &,
120 bool is_object,
121 const namespacet &);
122};
123
124#endif // CPROVER_ANALYSES_ESCAPE_ANALYSIS_H
Abstract Interpretation.
This is the basic interface of the abstract interpreter with default implementations of the core func...
Definition ai.h:117
virtual void clear()
Reset the abstract state.
Definition ai.h:265
The interface offered by a domain, allows code to manipulate domains without knowing their exact type...
Definition ai_domain.h:54
ai_history_baset::trace_ptrt trace_ptrt
Definition ai_domain.h:73
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
void instrument(goto_modelt &)
numberingt< irep_idt > bits
void insert_cleanup(goto_functionst::goto_functiont &, goto_programt::targett, const exprt &, const std::set< irep_idt > &, bool is_object, const namespacet &)
virtual void initialize(const goto_functionst &)
Initialize all the abstract states for a whole program.
void make_bottom() final override
no states
bool is_bottom() const override final
bool is_top() const override final
std::map< irep_idt, cleanupt > cleanup_mapt
bool merge(const escape_domaint &b, trace_ptrt from, trace_ptrt to)
void assign_lhs_cleanup(const exprt &, const std::set< irep_idt > &)
void check_lhs(const exprt &, std::set< irep_idt > &) const
void get_rhs_aliases(const exprt &, std::set< irep_idt > &)
irep_idt get_function(const exprt &)
void make_top() final override
all states – the analysis doesn't use this directly (see make_entry) and domains may refuse to implem...
cleanup_mapt cleanup_map
void get_rhs_aliases_address_of(const exprt &, std::set< irep_idt > &)
void transform(const irep_idt &function_from, trace_ptrt trace_from, const irep_idt &function_to, trace_ptrt trace_to, ai_baset &ai, const namespacet &ns) final override
how function calls are treated: a) there is an edge from each call site to the function head b) there...
bool is_tracked(const symbol_exprt &)
void assign_lhs_aliases(const exprt &, const std::set< irep_idt > &)
void output(std::ostream &out, const ai_baset &ai, const namespacet &ns) const final override
void get_rhs_cleanup(const exprt &, std::set< irep_idt > &)
union_find< irep_idt > aliasest
Base class for all expressions.
Definition expr.h:56
A collection of goto functions.
::goto_functiont goto_functiont
instructionst::iterator targett
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
Expression to hold a symbol (variable)
Definition std_expr.h:131
Definition threeval.h:20
bool is_false() const
Definition threeval.h:26
bool is_true() const
Definition threeval.h:25
size_t size() const
Definition union_find.h:268
void clear()
Definition union_find.h:247
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition invariant.h:534
std::set< irep_idt > cleanup_functions