CBMC
custom_bitvector_analysis.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Field-insensitive, location-sensitive bitvector analysis
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_ANALYSES_CUSTOM_BITVECTOR_ANALYSIS_H
13 #define CPROVER_ANALYSES_CUSTOM_BITVECTOR_ANALYSIS_H
14 
15 #include <util/numbering.h>
16 #include <util/threeval.h>
17 
18 #include "ai.h"
19 #include "local_may_alias.h"
20 
22 
24 {
25 public:
26  void transform(
27  const irep_idt &function_from,
28  trace_ptrt trace_from,
29  const irep_idt &function_to,
30  trace_ptrt trace_to,
31  ai_baset &ai,
32  const namespacet &ns) final override;
33 
34  void output(
35  std::ostream &out,
36  const ai_baset &ai,
37  const namespacet &ns) const final override;
38 
39  void make_bottom() final override
40  {
41  may_bits.clear();
42  must_bits.clear();
43  has_values=tvt(false);
44  }
45 
46  void make_top() final override
47  {
48  may_bits.clear();
49  must_bits.clear();
50  has_values=tvt(true);
51  }
52 
53  void make_entry() final override
54  {
55  make_top();
56  }
57 
58  bool is_bottom() const final override
59  {
61  (may_bits.empty() && must_bits.empty()),
62  "If the domain is bottom, it must have no bits set");
63  return has_values.is_false();
64  }
65 
66  bool is_top() const final override
67  {
69  (may_bits.empty() && must_bits.empty()),
70  "If the domain is top, it must have no bits set");
71  return has_values.is_true();
72  }
73 
74  bool merge(const custom_bitvector_domaint &b, trace_ptrt from, trace_ptrt to);
75 
76  typedef unsigned long long bit_vectort;
77 
78  typedef std::map<irep_idt, bit_vectort> bitst;
79 
80  struct vectorst
81  {
84  {
85  }
86  };
87 
88  static vectorst merge(const vectorst &a, const vectorst &b)
89  {
90  vectorst result;
91  result.may_bits=a.may_bits|b.may_bits;
92  result.must_bits=a.must_bits&b.must_bits;
93  return result;
94  }
95 
97 
98  void assign_struct_rec(
99  locationt from,
100  const exprt &lhs,
101  const exprt &rhs,
103  const namespacet &);
104 
105  void assign_lhs(const exprt &, const vectorst &);
106  void assign_lhs(const irep_idt &, const vectorst &);
107  vectorst get_rhs(const exprt &) const;
108  vectorst get_rhs(const irep_idt &) const;
109 
111 
113  {
114  }
115 
116  static bool has_get_must_or_may(const exprt &);
117  exprt eval(
118  const exprt &src,
120 
121 private:
123 
124  void set_bit(const exprt &, unsigned bit_nr, modet);
125  void set_bit(const irep_idt &, unsigned bit_nr, modet);
126 
127  static inline void set_bit(bit_vectort &dest, unsigned bit_nr)
128  {
129  dest|=(1ll<<bit_nr);
130  }
131 
132  static inline void clear_bit(bit_vectort &dest, unsigned bit_nr)
133  {
134  dest|=(1ll<<bit_nr);
135  dest^=(1ll<<bit_nr);
136  }
137 
138  static inline bool get_bit(const bit_vectort src, unsigned bit_nr)
139  {
140  return (src&(1ll<<bit_nr))!=0;
141  }
142 
143  void erase_blank_vectors(bitst &);
144 
145  static irep_idt object2id(const exprt &);
146 };
147 
148 class custom_bitvector_analysist:public ait<custom_bitvector_domaint>
149 {
150 public:
151  void instrument(goto_functionst &);
152  void check(
153  const goto_modelt &,
154  bool xml, std::ostream &);
155 
156  exprt eval(const exprt &src, locationt loc)
157  {
158  return operator[](loc).eval(src, *this);
159  }
160 
161  unsigned get_bit_nr(const exprt &);
162 
165 
166 protected:
167  virtual void initialize(const goto_functionst &_goto_functions)
168  {
170  local_may_alias_factory(_goto_functions);
171  }
172 
174 
176 
177  std::set<exprt> aliases(const exprt &, locationt loc);
178 };
179 
180 #endif // CPROVER_ANALYSES_CUSTOM_BITVECTOR_ANALYSIS_H
custom_bitvector_domaint::modet::CLEAR_MAY
@ CLEAR_MAY
custom_bitvector_domaint::merge
static vectorst merge(const vectorst &a, const vectorst &b)
Definition: custom_bitvector_analysis.h:88
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
custom_bitvector_domaint::assign_lhs
void assign_lhs(const exprt &, const vectorst &)
Definition: custom_bitvector_analysis.cpp:111
custom_bitvector_domaint::object2id
static irep_idt object2id(const exprt &)
Definition: custom_bitvector_analysis.cpp:59
custom_bitvector_domaint::merge
bool merge(const custom_bitvector_domaint &b, trace_ptrt from, trace_ptrt to)
Definition: custom_bitvector_analysis.cpp:607
custom_bitvector_domaint::vectorst::must_bits
bit_vectort must_bits
Definition: custom_bitvector_analysis.h:82
custom_bitvector_domaint::modet::SET_MAY
@ SET_MAY
ai_baset::locationt
goto_programt::const_targett locationt
Definition: ai.h:126
custom_bitvector_domaint::assign_struct_rec
void assign_struct_rec(locationt from, const exprt &lhs, const exprt &rhs, custom_bitvector_analysist &, const namespacet &)
Definition: custom_bitvector_analysis.cpp:227
ait< custom_bitvector_domaint >::operator[]
const custom_bitvector_domaint & operator[](locationt l) const
Find the analysis result for a given location.
Definition: ai.h:595
custom_bitvector_domaint::erase_blank_vectors
void erase_blank_vectors(bitst &)
erase blank bitvectors
Definition: custom_bitvector_analysis.cpp:672
threeval.h
numberingt< irep_idt >
custom_bitvector_domaint::get_rhs
vectorst get_rhs(const exprt &) const
Definition: custom_bitvector_analysis.cpp:154
custom_bitvector_domaint::modet::CLEAR_MUST
@ CLEAR_MUST
custom_bitvector_domaint::must_bits
bitst must_bits
Definition: custom_bitvector_analysis.h:96
custom_bitvector_domaint::make_top
void make_top() final override
all states – the analysis doesn't use this, and domains may refuse to implement it.
Definition: custom_bitvector_analysis.h:46
custom_bitvector_domaint::vectorst::vectorst
vectorst()
Definition: custom_bitvector_analysis.h:83
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
custom_bitvector_analysist::eval
exprt eval(const exprt &src, locationt loc)
Definition: custom_bitvector_analysis.h:156
custom_bitvector_domaint::set_bit
void set_bit(const exprt &, unsigned bit_nr, modet)
Definition: custom_bitvector_analysis.cpp:49
custom_bitvector_analysist::instrument
void instrument(goto_functionst &)
Definition: custom_bitvector_analysis.cpp:763
custom_bitvector_analysist::aliases
std::set< exprt > aliases(const exprt &, locationt loc)
Definition: custom_bitvector_analysis.cpp:192
custom_bitvector_domaint::may_bits
bitst may_bits
Definition: custom_bitvector_analysis.h:96
ai_domain_baset::trace_ptrt
ai_history_baset::trace_ptrt trace_ptrt
Definition: ai_domain.h:74
custom_bitvector_domaint::clear_bit
static void clear_bit(bit_vectort &dest, unsigned bit_nr)
Definition: custom_bitvector_analysis.h:132
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:90
custom_bitvector_domaint::output
void output(std::ostream &out, const ai_baset &ai, const namespacet &ns) const final override
Definition: custom_bitvector_analysis.cpp:560
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
custom_bitvector_domaint::modet
modet
Definition: custom_bitvector_analysis.h:122
custom_bitvector_domaint::modet::SET_MUST
@ SET_MUST
local_may_alias.h
xml
xmlt xml(const irep_idt &property_id, const property_infot &property_info)
Definition: properties.cpp:110
custom_bitvector_domaint
Definition: custom_bitvector_analysis.h:23
custom_bitvector_analysist
Definition: custom_bitvector_analysis.h:148
custom_bitvector_domaint::custom_bitvector_domaint
custom_bitvector_domaint()
Definition: custom_bitvector_analysis.h:112
numbering.h
ai.h
tvt::is_false
bool is_false() const
Definition: threeval.h:26
custom_bitvector_domaint::is_top
bool is_top() const final override
Definition: custom_bitvector_analysis.h:66
tvt
Definition: threeval.h:19
local_may_alias_factoryt
Definition: local_may_alias.h:95
custom_bitvector_domaint::vectorst::may_bits
bit_vectort may_bits
Definition: custom_bitvector_analysis.h:82
custom_bitvector_domaint::make_entry
void make_entry() final override
Make this domain a reasonable entry-point state.
Definition: custom_bitvector_analysis.h:53
ai_baset::initialize
virtual void initialize(const irep_idt &function_id, const goto_programt &goto_program)
Initialize all the abstract states for a single function.
Definition: ai.cpp:195
goto_functionst
A collection of goto functions.
Definition: goto_functions.h:24
custom_bitvector_domaint::has_get_must_or_may
static bool has_get_must_or_may(const exprt &)
Definition: custom_bitvector_analysis.cpp:685
ai_domain_baset::locationt
goto_programt::const_targett locationt
Definition: ai_domain.h:73
custom_bitvector_analysist::bitst
numberingt< irep_idt > bitst
Definition: custom_bitvector_analysis.h:163
custom_bitvector_domaint::bit_vectort
unsigned long long bit_vectort
Definition: custom_bitvector_analysis.h:76
custom_bitvector_domaint::vectorst
Definition: custom_bitvector_analysis.h:80
custom_bitvector_analysist::local_may_alias_factory
local_may_alias_factoryt local_may_alias_factory
Definition: custom_bitvector_analysis.h:175
custom_bitvector_analysist::initialize
virtual void initialize(const goto_functionst &_goto_functions)
Initialize all the abstract states for a whole program.
Definition: custom_bitvector_analysis.h:167
ai_baset
This is the basic interface of the abstract interpreter with default implementations of the core func...
Definition: ai.h:118
custom_bitvector_domaint::eval
exprt eval(const exprt &src, custom_bitvector_analysist &) const
Definition: custom_bitvector_analysis.cpp:697
custom_bitvector_analysist::check
void check(const goto_modelt &, bool xml, std::ostream &)
Definition: custom_bitvector_analysis.cpp:767
custom_bitvector_domaint::set_bit
static void set_bit(bit_vectort &dest, unsigned bit_nr)
Definition: custom_bitvector_analysis.h:127
custom_bitvector_domaint::is_bottom
bool is_bottom() const final override
Definition: custom_bitvector_analysis.h:58
ai_domain_baset
The interface offered by a domain, allows code to manipulate domains without knowing their exact type...
Definition: ai_domain.h:54
custom_bitvector_analysist::bits
bitst bits
Definition: custom_bitvector_analysis.h:164
custom_bitvector_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: custom_bitvector_analysis.cpp:269
custom_bitvector_domaint::bitst
std::map< irep_idt, bit_vectort > bitst
Definition: custom_bitvector_analysis.h:78
custom_bitvector_domaint::has_values
tvt has_values
Definition: custom_bitvector_analysis.h:110
custom_bitvector_analysist::get_bit_nr
unsigned get_bit_nr(const exprt &)
Definition: custom_bitvector_analysis.cpp:177
tvt::is_true
bool is_true() const
Definition: threeval.h:25
custom_bitvector_domaint::get_bit
static bool get_bit(const bit_vectort src, unsigned bit_nr)
Definition: custom_bitvector_analysis.h:138
custom_bitvector_domaint::make_bottom
void make_bottom() final override
no states
Definition: custom_bitvector_analysis.h:39