CBMC
Loading...
Searching...
No Matches
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
15#include <util/mp_arith.h>
16
19
21
22#include "synthesizer_utils.h"
23
24class messaget;
25
27class cext
28{
29public:
39
41 {
42 in_loop,
45 };
46
48 const std::unordered_map<exprt, mp_integer, irep_hash> &object_sizes,
49 const std::unordered_map<exprt, mp_integer, irep_hash> &havoced_values,
50 const std::unordered_map<exprt, mp_integer, irep_hash>
52 const std::unordered_map<exprt, mp_integer, irep_hash> &loop_entry_values,
53 const std::unordered_map<exprt, mp_integer, irep_hash> &loop_entry_offsets,
54 const std::set<exprt> &live_variables)
61 {
62 }
63
68
69 // pointer that failed the null pointer check
72
73 // Location where the violation happens
75
76 // We collect havoced evaluations of havoced variables and their object sizes
77 // and pointer offsets.
78
79 // __CPROVER_OBJECT_SIZE
80 std::unordered_map<exprt, mp_integer, irep_hash> object_sizes;
81 // all the valuation of havoced variables with primitive type.
82 std::unordered_map<exprt, mp_integer, irep_hash> havoced_values;
83 // __CPROVER_POINTER_OFFSET
84 std::unordered_map<exprt, mp_integer, irep_hash> havoced_pointer_offsets;
85
86 // We also collect loop-entry evaluations of havoced variables.
87 // __CPROVER_loop_entry
88 std::unordered_map<exprt, mp_integer, irep_hash> loop_entry_values;
89 // __CPROVER_POINTER_OFFSET(__CPROVER_loop_entry( ))
90 std::unordered_map<exprt, mp_integer, irep_hash> loop_entry_offsets;
91
92 // Set of live variables upon loop head.
93 std::set<exprt> live_variables;
94
96 std::list<loop_idt> cause_loop_ids;
97};
98
102{
103public:
106 const std::map<loop_idt, std::set<exprt>> &assigns_map,
108 const optionst &options,
109 messaget &log)
114 log(log),
115 ns(goto_model.symbol_table)
116 {
117 }
118
121 std::optional<cext> verify();
122
126
127protected:
128 // Compute the cause loops of `violation`.
129 // We say a loop is the cause loop if the violated predicate is dependent
130 // upon the write set of the loop.
131 std::list<loop_idt> get_cause_loop_id(
132 const goto_tracet &goto_trace,
134
135 // Compute the cause loops of a assignable-violation.
136 // We say a loop is the cause loop if the assignable check is in the loop.
137 std::list<loop_idt>
139
140 // Extract the violation type from violation description.
141 cext::violation_typet extract_violation_type(const std::string &description);
142
143 // Compute the location of the violation.
145 const loop_idt &loop_id,
146 const goto_functiont &function,
148
150 void restore_functions();
151
152 // Build counterexample from trace, and store it in `return_cex`.
154 const goto_tracet &goto_trace,
156
160 const loop_idt &loop_id,
161 const goto_functiont &function,
163
167 const loop_idt &loop_id,
168 const goto_functiont &function,
170
173
175 const std::map<loop_idt, std::set<exprt>> &assigns_map;
180
183 std::unordered_map<irep_idt, goto_programt> original_functions;
184
187 std::unordered_map<goto_programt::const_targett, unsigned, const_target_hash>
189
191 std::unordered_set<goto_programt::const_targett, const_target_hash>
193};
194
195#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:566
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:57
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:30