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  bool is_bottom() const final override
54  {
56  (may_bits.empty() && must_bits.empty()),
57  "If the domain is bottom, it must have no bits set");
58  return has_values.is_false();
59  }
60 
61  bool is_top() const final override
62  {
64  (may_bits.empty() && must_bits.empty()),
65  "If the domain is top, it must have no bits set");
66  return has_values.is_true();
67  }
68 
69  bool merge(const custom_bitvector_domaint &b, trace_ptrt from, trace_ptrt to);
70 
71  typedef unsigned long long bit_vectort;
72 
73  typedef std::map<irep_idt, bit_vectort> bitst;
74 
75  struct vectorst
76  {
79  {
80  }
81  };
82 
83  static vectorst merge(const vectorst &a, const vectorst &b)
84  {
85  vectorst result;
86  result.may_bits=a.may_bits|b.may_bits;
87  result.must_bits=a.must_bits&b.must_bits;
88  return result;
89  }
90 
92 
93  void assign_struct_rec(
94  locationt from,
95  const exprt &lhs,
96  const exprt &rhs,
98  const namespacet &);
99 
100  void assign_lhs(const exprt &, const vectorst &);
101  void assign_lhs(const irep_idt &, const vectorst &);
102  vectorst get_rhs(const exprt &) const;
103  vectorst get_rhs(const irep_idt &) const;
104 
106 
108  {
109  }
110 
111  static bool has_get_must_or_may(const exprt &);
112  exprt eval(
113  const exprt &src,
115 
116 private:
118 
119  void set_bit(const exprt &, unsigned bit_nr, modet);
120  void set_bit(const irep_idt &, unsigned bit_nr, modet);
121 
122  static inline void set_bit(bit_vectort &dest, unsigned bit_nr)
123  {
124  dest|=(1ll<<bit_nr);
125  }
126 
127  static inline void clear_bit(bit_vectort &dest, unsigned bit_nr)
128  {
129  dest|=(1ll<<bit_nr);
130  dest^=(1ll<<bit_nr);
131  }
132 
133  static inline bool get_bit(const bit_vectort src, unsigned bit_nr)
134  {
135  return (src&(1ll<<bit_nr))!=0;
136  }
137 
138  void erase_blank_vectors(bitst &);
139 
140  static irep_idt object2id(const exprt &);
141 };
142 
143 class custom_bitvector_analysist:public ait<custom_bitvector_domaint>
144 {
145 public:
146  void instrument(goto_functionst &);
147  void check(
148  const goto_modelt &,
149  bool xml, std::ostream &);
150 
151  exprt eval(const exprt &src, locationt loc)
152  {
153  return operator[](loc).eval(src, *this);
154  }
155 
156  unsigned get_bit_nr(const exprt &);
157 
160 
161 protected:
162  virtual void initialize(const goto_functionst &_goto_functions)
163  {
165  local_may_alias_factory(_goto_functions);
166  }
167 
169 
171 
172  std::set<exprt> aliases(const exprt &, locationt loc);
173 };
174 
175 #endif // CPROVER_ANALYSES_CUSTOM_BITVECTOR_ANALYSIS_H
Abstract Interpretation.
This is the basic interface of the abstract interpreter with default implementations of the core func...
Definition: ai.h:117
goto_programt::const_targett locationt
Definition: ai.h:124
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:194
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
goto_programt::const_targett locationt
Definition: ai_domain.h:72
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition: ai.h:562
const custom_bitvector_domaint & operator[](locationt l) const
Find the analysis result for a given location.
Definition: ai.h:593
std::set< exprt > aliases(const exprt &, locationt loc)
local_may_alias_factoryt local_may_alias_factory
exprt eval(const exprt &src, locationt loc)
void check(const goto_modelt &, bool xml, std::ostream &)
virtual void initialize(const goto_functionst &_goto_functions)
Initialize all the abstract states for a whole program.
static void set_bit(bit_vectort &dest, unsigned bit_nr)
void set_bit(const exprt &, unsigned bit_nr, modet)
bool merge(const custom_bitvector_domaint &b, trace_ptrt from, trace_ptrt to)
std::map< irep_idt, bit_vectort > bitst
bool is_bottom() const final override
static irep_idt object2id(const exprt &)
bool is_top() const final override
void assign_struct_rec(locationt from, const exprt &lhs, const exprt &rhs, custom_bitvector_analysist &, const namespacet &)
void make_top() final override
all states – the analysis doesn't use this directly (see make_entry) and domains may refuse to implem...
static bool has_get_must_or_may(const exprt &)
vectorst get_rhs(const exprt &) const
static void clear_bit(bit_vectort &dest, unsigned bit_nr)
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...
void output(std::ostream &out, const ai_baset &ai, const namespacet &ns) const final override
void assign_lhs(const exprt &, const vectorst &)
void erase_blank_vectors(bitst &)
erase blank bitvectors
static bool get_bit(const bit_vectort src, unsigned bit_nr)
void make_bottom() final override
no states
exprt eval(const exprt &src, custom_bitvector_analysist &) const
static vectorst merge(const vectorst &a, const vectorst &b)
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
Base class for all expressions.
Definition: expr.h:56
A collection of goto functions.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
Definition: threeval.h:20
bool is_false() const
Definition: threeval.h:26
bool is_true() const
Definition: threeval.h:25
Field-insensitive, location-sensitive may-alias analysis.
xmlt xml(const irep_idt &property_id, const property_infot &property_info)
Definition: properties.cpp:110
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition: invariant.h:534