CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cegis_verifier.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Verifier for Counterexample-Guided Synthesis
4
5Author: Qinheping Hu
6
7\*******************************************************************/
8
11
12#ifndef CPROVER_GOTO_SYNTHESIZER_CEGIS_VERIFIER_H
13#define CPROVER_GOTO_SYNTHESIZER_CEGIS_VERIFIER_H
14
17
19
20#include "synthesizer_utils.h"
21
22class messaget;
23
25class cext
26{
27public:
37
39 {
40 in_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
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{
101public:
104 const std::map<loop_idt, std::set<exprt>> &assigns_map,
106 const optionst &options,
107 messaget &log)
112 log(log),
113 ns(goto_model.symbol_table)
114 {
115 }
116
119 std::optional<cext> verify();
120
124
125protected:
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,
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>
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,
146
148 void restore_functions();
149
150 // Build counterexample from trace, and store it in `return_cex`.
152 const goto_tracet &goto_trace,
154
158 const loop_idt &loop_id,
159 const goto_functiont &function,
161
165 const loop_idt &loop_id,
166 const goto_functiont &function,
168
171
173 const std::map<loop_idt, std::set<exprt>> &assigns_map;
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.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
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.
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.
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)
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
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...
instructionst::const_iterator const_targett
Trace of a GOTO program.
Definition goto_trace.h:177
Class that provides messages with a built-in verbosity 'level'.
Definition message.h:154
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
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:32