CBMC
escape_analysis.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Field-insensitive, location-sensitive, over-approximative
4  escape analysis
5 
6 Author: 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 {
24 public:
26  {
27  }
28 
29  void transform(
30  const irep_idt &function_from,
31  trace_ptrt trace_from,
32  const irep_idt &function_to,
33  trace_ptrt trace_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 
42  bool merge(const escape_domaint &b, trace_ptrt from, trace_ptrt to);
43 
44  void make_bottom() final override
45  {
46  cleanup_map.clear();
47  aliases.clear();
48  has_values=tvt(false);
49  }
50 
51  void make_top() final override
52  {
53  cleanup_map.clear();
54  aliases.clear();
55  has_values=tvt(true);
56  }
57 
58  bool is_bottom() const override final
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 
74  void make_entry() override final
75  {
76  make_top();
77  }
78 
81 
82  struct cleanupt
83  {
84  std::set<irep_idt> cleanup_functions;
85  };
86 
87  // We track a set of 'cleanup functions' for specific
88  // identifiers. The cleanup functions are executed
89  // once the last pointer to an object is lost.
90  typedef std::map<irep_idt, cleanupt> cleanup_mapt;
92 
93 private:
95  void assign_lhs_cleanup(const exprt &, const std::set<irep_idt> &);
96  void get_rhs_cleanup(const exprt &, std::set<irep_idt> &);
97  void assign_lhs_aliases(const exprt &, const std::set<irep_idt> &);
98  void get_rhs_aliases(const exprt &, std::set<irep_idt> &);
99  void get_rhs_aliases_address_of(const exprt &, std::set<irep_idt> &);
100  irep_idt get_function(const exprt &);
101  void check_lhs(const exprt &, std::set<irep_idt> &) const;
102 
103  friend class escape_analysist;
104 
105  bool is_tracked(const symbol_exprt &);
106 };
107 
108 class escape_analysist:public ait<escape_domaint>
109 {
110 public:
111  void instrument(goto_modelt &);
112 
113 protected:
114  virtual void initialize(const goto_functionst &)
115  {
116  }
117 
119 
120  void insert_cleanup(
123  const exprt &,
124  const std::set<irep_idt> &,
125  bool is_object,
126  const namespacet &);
127 };
128 
129 #endif // CPROVER_ANALYSES_ESCAPE_ANALYSIS_H
escape_domaint::escape_domaint
escape_domaint()
Definition: escape_analysis.h:25
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
escape_domaint
Definition: escape_analysis.h:22
union_find.h
escape_domaint::output
void output(std::ostream &out, const ai_baset &ai, const namespacet &ns) const final override
Definition: escape_analysis.cpp:280
escape_domaint::make_entry
void make_entry() override final
Make this domain a reasonable entry-point state.
Definition: escape_analysis.h:74
escape_domaint::aliasest
union_find< irep_idt > aliasest
Definition: escape_analysis.h:79
threeval.h
numberingt< irep_idt >
escape_domaint::check_lhs
void check_lhs(const exprt &, std::set< irep_idt > &) const
Definition: escape_analysis.cpp:379
escape_domaint::cleanupt::cleanup_functions
std::set< irep_idt > cleanup_functions
Definition: escape_analysis.h:84
escape_domaint::get_rhs_aliases
void get_rhs_aliases(const exprt &, std::set< irep_idt > &)
Definition: escape_analysis.cpp:116
escape_domaint::assign_lhs_cleanup
void assign_lhs_cleanup(const exprt &, const std::set< irep_idt > &)
Definition: escape_analysis.cpp:46
exprt
Base class for all expressions.
Definition: expr.h:55
ait
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition: ai.h:563
goto_modelt
Definition: goto_model.h:25
escape_domaint::get_rhs_cleanup
void get_rhs_cleanup(const exprt &, std::set< irep_idt > &)
Definition: escape_analysis.cpp:86
symbol_exprt
Expression to hold a symbol (variable)
Definition: std_expr.h:112
union_find< irep_idt >
ai_domain_baset::trace_ptrt
ai_history_baset::trace_ptrt trace_ptrt
Definition: ai_domain.h:74
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:90
escape_domaint::make_top
void make_top() final override
all states – the analysis doesn't use this, and domains may refuse to implement it.
Definition: escape_analysis.h:51
union_find::clear
void clear()
Definition: union_find.h:247
escape_analysist
Definition: escape_analysis.h:108
escape_domaint::aliases
aliasest aliases
Definition: escape_analysis.h:80
escape_domaint::get_function
irep_idt get_function(const exprt &)
Definition: escape_analysis.cpp:31
escape_analysist::initialize
virtual void initialize(const goto_functionst &)
Initialize all the abstract states for a whole program.
Definition: escape_analysis.h:114
DATA_INVARIANT
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition: invariant.h:510
escape_domaint::merge
bool merge(const escape_domaint &b, trace_ptrt from, trace_ptrt to)
Definition: escape_analysis.cpp:326
escape_domaint::cleanupt
Definition: escape_analysis.h:82
escape_domaint::get_rhs_aliases_address_of
void get_rhs_aliases_address_of(const exprt &, std::set< irep_idt > &)
Definition: escape_analysis.cpp:148
escape_domaint::make_bottom
void make_bottom() final override
no states
Definition: escape_analysis.h:44
escape_domaint::is_top
bool is_top() const override final
Definition: escape_analysis.h:66
escape_domaint::assign_lhs_aliases
void assign_lhs_aliases(const exprt &, const std::set< irep_idt > &)
Definition: escape_analysis.cpp:65
escape_analysist::instrument
void instrument(goto_modelt &)
Definition: escape_analysis.cpp:449
numbering.h
ai.h
tvt::is_false
bool is_false() const
Definition: threeval.h:26
tvt
Definition: threeval.h:19
goto_functionst::goto_functiont
::goto_functiont goto_functiont
Definition: goto_functions.h:27
goto_functionst
A collection of goto functions.
Definition: goto_functions.h:24
escape_domaint::has_values
tvt has_values
Definition: escape_analysis.h:94
union_find::size
size_t size() const
Definition: union_find.h:268
escape_analysist::bits
numberingt< irep_idt > bits
Definition: escape_analysis.h:118
escape_domaint::is_bottom
bool is_bottom() const override final
Definition: escape_analysis.h:58
escape_domaint::cleanup_mapt
std::map< irep_idt, cleanupt > cleanup_mapt
Definition: escape_analysis.h:90
ai_baset
This is the basic interface of the abstract interpreter with default implementations of the core func...
Definition: ai.h:118
escape_analysist::insert_cleanup
void insert_cleanup(goto_functionst::goto_functiont &, goto_programt::targett, const exprt &, const std::set< irep_idt > &, bool is_object, const namespacet &)
Definition: escape_analysis.cpp:414
ai_domain_baset
The interface offered by a domain, allows code to manipulate domains without knowing their exact type...
Definition: ai_domain.h:54
escape_domaint::transform
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...
Definition: escape_analysis.cpp:167
escape_domaint::cleanup_map
cleanup_mapt cleanup_map
Definition: escape_analysis.h:91
goto_programt::targett
instructionst::iterator targett
Definition: goto_program.h:586
tvt::is_true
bool is_true() const
Definition: threeval.h:25
escape_domaint::is_tracked
bool is_tracked(const symbol_exprt &)
Definition: escape_analysis.cpp:17