CBMC
cegis_verifier.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Verifier for Counterexample-Guided Synthesis
4 
5 Author: Qinheping Hu
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_GOTO_SYNTHESIZER_CEGIS_VERIFIER_H
13 #define CPROVER_GOTO_SYNTHESIZER_CEGIS_VERIFIER_H
14 
16 #include <goto-programs/loop_ids.h>
17 
19 
20 #include "synthesizer_utils.h"
21 
22 class messaget;
23 
25 class cext
26 {
27 public:
28  enum class violation_typet
29  {
35  cex_other
36  };
37 
39  {
40  in_loop,
41  after_loop,
43  };
44 
46  const std::unordered_map<exprt, mp_integer, irep_hash> &object_sizes,
47  const std::unordered_map<exprt, mp_integer, irep_hash> &havoced_values,
48  const std::unordered_map<exprt, mp_integer, irep_hash>
50  const std::unordered_map<exprt, mp_integer, irep_hash> &loop_entry_values,
51  const std::unordered_map<exprt, mp_integer, irep_hash> &loop_entry_offsets,
52  const std::set<exprt> &live_variables)
59  {
60  }
61 
64  {
65  }
66 
67  // pointer that failed the null pointer check
70 
71  // Location where the violation happens
73 
74  // We collect havoced evaluations of havoced variables and their object sizes
75  // and pointer offsets.
76 
77  // __CPROVER_OBJECT_SIZE
78  std::unordered_map<exprt, mp_integer, irep_hash> object_sizes;
79  // all the valuation of havoced variables with primitive type.
80  std::unordered_map<exprt, mp_integer, irep_hash> havoced_values;
81  // __CPROVER_POINTER_OFFSET
82  std::unordered_map<exprt, mp_integer, irep_hash> havoced_pointer_offsets;
83 
84  // We also collect loop-entry evaluations of havoced variables.
85  // __CPROVER_loop_entry
86  std::unordered_map<exprt, mp_integer, irep_hash> loop_entry_values;
87  // __CPROVER_POINTER_OFFSET(__CPROVER_loop_entry( ))
88  std::unordered_map<exprt, mp_integer, irep_hash> loop_entry_offsets;
89 
90  // Set of live variables upon loop head.
91  std::set<exprt> live_variables;
92 
94  std::list<loop_idt> cause_loop_ids;
95 };
96 
100 {
101 public:
104  const std::map<loop_idt, std::set<exprt>> &assigns_map,
106  const optionst &options,
107  messaget &log)
111  options(options),
112  log(log),
113  ns(goto_model.symbol_table)
114  {
115  }
116 
119  std::optional<cext> verify();
120 
124 
125 protected:
126  // Compute the cause loops of `violation`.
127  // We say a loop is the cause loop if the violated predicate is dependent
128  // upon the write set of the loop.
129  std::list<loop_idt> get_cause_loop_id(
130  const goto_tracet &goto_trace,
131  const goto_programt::const_targett violation);
132 
133  // Compute the cause loops of a assignable-violation.
134  // We say a loop is the cause loop if the assignable check is in the loop.
135  std::list<loop_idt>
136  get_cause_loop_id_for_assigns(const goto_tracet &goto_trace);
137 
138  // Extract the violation type from violation description.
139  cext::violation_typet extract_violation_type(const std::string &description);
140 
141  // Compute the location of the violation.
143  const loop_idt &loop_id,
144  const goto_functiont &function,
145  unsigned location_number_of_target);
146 
148  void restore_functions();
149 
150  // Build counterexample from trace, and store it in `return_cex`.
151  cext build_cex(
152  const goto_tracet &goto_trace,
153  const source_locationt &loop_entry_loc);
154 
158  const loop_idt &loop_id,
159  const goto_functiont &function,
160  unsigned location_number_of_target);
161 
165  const loop_idt &loop_id,
166  const goto_functiont &function,
167  unsigned location_number_of_target);
168 
170  void preprocess_goto_model();
171 
173  const std::map<loop_idt, std::set<exprt>> &assigns_map;
177  const namespacet ns;
178 
181  std::unordered_map<irep_idt, goto_programt> original_functions;
182 
185  std::unordered_map<goto_programt::const_targett, unsigned, const_target_hash>
187 
189  std::unordered_set<goto_programt::const_targett, const_target_hash>
191 };
192 
193 #endif // CPROVER_GOTO_SYNTHESIZER_CEGIS_VERIFIER_H
Goto Verifier for Verifying all Properties.
Verifier that take a goto program as input, and output formatted counterexamples for counterexample-g...
std::optional< cext > verify()
Verify goto_model.
const namespacet ns
irep_idt target_violation_id
void restore_functions()
Restore transformed functions to original functions.
const std::map< loop_idt, std::set< exprt > > & assigns_map
cext build_cex(const goto_tracet &goto_trace, const source_locationt &loop_entry_loc)
cext::violation_locationt get_violation_location(const loop_idt &loop_id, const goto_functiont &function, unsigned location_number_of_target)
std::list< loop_idt > get_cause_loop_id(const goto_tracet &goto_trace, const goto_programt::const_targett violation)
std::unordered_set< goto_programt::const_targett, const_target_hash > loop_havoc_set
Loop havoc instructions instrumented during applying loop contracts.
bool is_instruction_in_transformed_loop(const loop_idt &loop_id, const goto_functiont &function, unsigned location_number_of_target)
Decide whether the target instruction is in the body of the transformed loop specified by loop_id.
const optionst & options
const invariant_mapt & invariant_candidates
std::unordered_map< goto_programt::const_targett, unsigned, const_target_hash > original_loop_number_map
Map from instrumented instructions for loop contracts to their original loop numbers.
cext::violation_typet extract_violation_type(const std::string &description)
goto_modelt & goto_model
std::unordered_map< irep_idt, goto_programt > original_functions
Map from function names to original functions.
void preprocess_goto_model()
Preprocess the goto model to prepare for verification.
cegis_verifiert(const invariant_mapt &invariant_candidates, const std::map< loop_idt, std::set< exprt >> &assigns_map, goto_modelt &goto_model, const optionst &options, messaget &log)
propertiest properties
Result counterexample.
std::list< loop_idt > get_cause_loop_id_for_assigns(const goto_tracet &goto_trace)
bool is_instruction_in_transformed_loop_condition(const loop_idt &loop_id, const goto_functiont &function, unsigned location_number_of_target)
Decide whether the target instruction is between the loop-havoc and the evaluation of the loop guard.
Formatted counterexample.
cext(const std::unordered_map< exprt, mp_integer, irep_hash > &object_sizes, const std::unordered_map< exprt, mp_integer, irep_hash > &havoced_values, const std::unordered_map< exprt, mp_integer, irep_hash > &havoced_pointer_offsets, const std::unordered_map< exprt, mp_integer, irep_hash > &loop_entry_values, const std::unordered_map< exprt, mp_integer, irep_hash > &loop_entry_offsets, const std::set< exprt > &live_variables)
exprt violated_predicate
exprt checked_pointer
std::unordered_map< exprt, mp_integer, irep_hash > loop_entry_values
std::list< loop_idt > cause_loop_ids
violation_locationt violation_location
violation_typet
cext(const violation_typet &violation_type)
violation_locationt
std::unordered_map< exprt, mp_integer, irep_hash > loop_entry_offsets
std::unordered_map< exprt, mp_integer, irep_hash > havoced_values
std::set< exprt > live_variables
std::unordered_map< exprt, mp_integer, irep_hash > havoced_pointer_offsets
std::unordered_map< exprt, mp_integer, irep_hash > object_sizes
violation_typet violation_type
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 goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
Definition: goto_function.h:24
instructionst::const_iterator const_targett
Definition: goto_program.h:615
Trace of a GOTO program.
Definition: goto_trace.h:177
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:155
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
Symbol Table + CFG.
Loop IDs.
std::map< irep_idt, property_infot > propertiest
A map of property IDs to property infos.
Definition: properties.h:76
Loop id used to identify loops.
Definition: loop_ids.h:28
std::map< loop_idt, exprt > invariant_mapt
Definition: utils.h:29