CBMC
path_storage.h
Go to the documentation of this file.
1 
5 #ifndef CPROVER_GOTO_SYMEX_PATH_STORAGE_H
6 #define CPROVER_GOTO_SYMEX_PATH_STORAGE_H
7 
8 #include <util/invariant.h>
9 
10 #include <analyses/dirty.h>
11 #include <analyses/local_safe_pointers.h> // IWYU pragma: keep
12 
13 #include "goto_symex_state.h"
14 #include "symex_target_equation.h"
15 
16 #include <memory>
17 
18 class cmdlinet;
19 class optionst;
20 
23 {
24 public:
26 
27 private:
28  std::size_t nondet_count = 0;
29 };
30 
38 {
39 public:
41  struct patht
42  {
45 
47  : equation(e), state(s, &equation)
48  {
49  }
50 
51  explicit patht(const patht &other)
52  : equation(other.equation), state(other.state, &equation)
53  {
54  }
55  };
56 
57  virtual ~path_storaget() = default;
58 
61  {
62  PRECONDITION(!empty());
63  return private_peek();
64  }
65 
72  virtual void clear() = 0;
73 
75  virtual void push(const patht &) = 0;
76 
78  void pop()
79  {
80  PRECONDITION(!empty());
81  private_pop();
82  }
83 
85  virtual std::size_t size() const = 0;
86 
88  bool empty() const
89  {
90  return size() == 0;
91  };
92 
95 
100  std::unordered_map<irep_idt, local_safe_pointerst> safe_pointers;
101 
104  std::size_t get_unique_l1_index(const irep_idt &id, std::size_t minimum_index)
105  {
106  return get_unique_index(l1_indices, id, minimum_index);
107  }
108 
109  std::size_t get_unique_l2_index(const irep_idt &id)
110  {
111  return get_unique_index(l2_indices, id, 1);
112  }
113 
117 
120  void add_function_loops(const irep_idt &identifier, const goto_programt &body)
121  {
122  auto loop_iter = loop_analysis_map.find(identifier);
123  if(loop_iter == loop_analysis_map.end())
124  {
125  loop_analysis_map[identifier] =
126  std::make_shared<lexical_loopst>(lexical_loopst(body));
127  }
128  }
129 
130  inline std::shared_ptr<lexical_loopst>
131  get_loop_analysis(const irep_idt &function_id)
132  {
133  return loop_analysis_map.at(function_id);
134  }
135 
136 private:
137  std::unordered_map<irep_idt, std::shared_ptr<lexical_loopst>>
139 
140  // Derived classes should override these methods, allowing the base class to
141  // enforce preconditions.
142  virtual patht &private_peek() = 0;
143  virtual void private_pop() = 0;
144 
145  typedef std::unordered_map<irep_idt, std::size_t> name_index_mapt;
146 
147  std::size_t get_unique_index(
148  name_index_mapt &unique_index_map,
149  const irep_idt &id,
150  std::size_t minimum_index)
151  {
152  auto entry = unique_index_map.emplace(id, minimum_index);
153 
154  if(!entry.second)
155  entry.first->second = std::max(entry.first->second + 1, minimum_index);
156 
157  return entry.first->second;
158  }
159 
163 };
164 
166 class path_lifot : public path_storaget
167 {
168 public:
169  void push(const patht &) override;
170  std::size_t size() const override;
171  void clear() override;
172 
173 protected:
174  std::list<path_storaget::patht>::iterator last_peeked;
175  std::list<patht> paths;
176 
177 private:
178  patht &private_peek() override;
179  void private_pop() override;
180 };
181 
183 class path_fifot : public path_storaget
184 {
185 public:
186  void push(const patht &) override;
187  std::size_t size() const override;
188  void clear() override;
189 
190 protected:
191  std::list<patht> paths;
192 
193 private:
194  patht &private_peek() override;
195  void private_pop() override;
196 };
197 
199 std::string show_path_strategies();
200 
202 bool is_valid_path_strategy(const std::string strategy);
203 
206 std::unique_ptr<path_storaget> get_path_strategy(const std::string strategy);
207 
211  const cmdlinet &,
212  optionst &,
213  message_handlert &);
214 
215 #endif /* CPROVER_GOTO_SYMEX_PATH_STORAGE_H */
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:73
Central data structure: state.
Wrapper for dirtyt that permits incremental population, ensuring each function is analysed exactly on...
Definition: dirty.h:118
Expression to hold a nondeterministic choice.
Definition: std_expr.h:292
FIFO save queue: paths are resumed in the order that they were saved.
Definition: path_storage.h:184
void clear() override
Clear all saved paths.
void private_pop() override
patht & private_peek() override
std::list< patht > paths
Definition: path_storage.h:191
void push(const patht &) override
Add a path to resume to the storage.
std::size_t size() const override
How many paths does this storage contain?
LIFO save queue: depth-first search, try to finish paths.
Definition: path_storage.h:167
std::list< patht > paths
Definition: path_storage.h:175
void private_pop() override
std::list< path_storaget::patht >::iterator last_peeked
Definition: path_storage.h:174
void push(const patht &) override
Add a path to resume to the storage.
patht & private_peek() override
std::size_t size() const override
How many paths does this storage contain?
void clear() override
Clear all saved paths.
Storage for symbolic execution paths to be resumed later.
Definition: path_storage.h:38
std::size_t get_unique_l2_index(const irep_idt &id)
Definition: path_storage.h:109
incremental_dirtyt dirty
Local variables are considered 'dirty' if they've had an address taken and therefore may be referred ...
Definition: path_storage.h:116
std::size_t get_unique_l1_index(const irep_idt &id, std::size_t minimum_index)
Provide a unique L1 index for a given id, starting from minimum_index.
Definition: path_storage.h:104
std::unordered_map< irep_idt, std::shared_ptr< lexical_loopst > > loop_analysis_map
Definition: path_storage.h:138
virtual void clear()=0
Clear all saved paths.
virtual void private_pop()=0
std::shared_ptr< lexical_loopst > get_loop_analysis(const irep_idt &function_id)
Definition: path_storage.h:131
std::unordered_map< irep_idt, local_safe_pointerst > safe_pointers
Map function identifiers to local_safe_pointerst instances.
Definition: path_storage.h:100
virtual patht & private_peek()=0
virtual void push(const patht &)=0
Add a path to resume to the storage.
std::unordered_map< irep_idt, std::size_t > name_index_mapt
Definition: path_storage.h:145
std::size_t get_unique_index(name_index_mapt &unique_index_map, const irep_idt &id, std::size_t minimum_index)
Definition: path_storage.h:147
void pop()
Remove the next path to resume from the storage.
Definition: path_storage.h:78
patht & peek()
Reference to the next path to resume.
Definition: path_storage.h:60
virtual std::size_t size() const =0
How many paths does this storage contain?
name_index_mapt l1_indices
Storage used by get_unique_index.
Definition: path_storage.h:161
virtual ~path_storaget()=default
void add_function_loops(const irep_idt &identifier, const goto_programt &body)
Generates a loop analysis for the instructions in goto_programt and keys it against function ID.
Definition: path_storage.h:120
symex_nondet_generatort build_symex_nondet
Counter for nondet objects, which require unique names.
Definition: path_storage.h:91
name_index_mapt l2_indices
Definition: path_storage.h:162
bool empty() const
Is this storage empty?
Definition: path_storage.h:88
Functor generating fresh nondet symbols.
Definition: path_storage.h:23
std::size_t nondet_count
Definition: path_storage.h:28
nondet_symbol_exprt operator()(typet type, source_locationt location)
Inheriting the interface of symex_targett this class represents the SSA form of the input program as ...
The type of an expression, extends irept.
Definition: type.h:29
Variables whose address is taken.
Symbolic Execution.
lexical_loops_templatet< const goto_programt, goto_programt::const_targett, goto_programt::target_less_than > lexical_loopst
Local safe pointer analysis.
std::unique_ptr< path_storaget > get_path_strategy(const std::string strategy)
Ensure that is_valid_strategy() returns true for a particular string before calling this function on ...
void parse_path_strategy_options(const cmdlinet &, optionst &, message_handlert &)
add paths and exploration-strategy option, suitable to be invoked from front-ends.
bool is_valid_path_strategy(const std::string strategy)
is there a factory constructor for the named strategy?
std::string show_path_strategies()
suitable for displaying as a front-end help message
#define PRECONDITION(CONDITION)
Definition: invariant.h:463
Information saved at a conditional goto to resume execution.
Definition: path_storage.h:42
symex_target_equationt equation
Definition: path_storage.h:43
patht(const symex_target_equationt &e, const goto_symex_statet &s)
Definition: path_storage.h:46
patht(const patht &other)
Definition: path_storage.h:51
goto_symex_statet state
Definition: path_storage.h:44
Generate Equation using Symbolic Execution.