CBMC
Loading...
Searching...
No Matches
refine_arrays.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9#include "bv_refinement.h"
10
11#ifdef DEBUG
12#include <iostream>
13#endif
14
15#include <util/std_expr.h>
16#include <util/find_symbols.h>
17
19
22{
24 // at this point all indices should in the index set
25
26 // just build the data structure
27 update_index_map(true);
28
29 // we don't actually add any constraints
33}
34
37{
39 return;
40
41 unsigned nb_active=0;
42
43 // Evaluate all lazy constraints while the solver is still in SAT state.
44 // We must not interleave get_value() calls with modifications to the
45 // main solver (prop) because some SAT solvers (e.g., CaDiCaL) only
46 // permit reading model values while in the satisfied state, and adding
47 // clauses invalidates that state.
49 {
50 exprt constraint;
52 std::list<lazy_constraintt>::iterator list_it;
53 };
54 std::vector<evaluated_constraintt> to_check;
55 to_check.reserve(lazy_array_constraints.size());
56
57 for(auto it = lazy_array_constraints.begin();
58 it != lazy_array_constraints.end();
59 ++it)
60 {
61 const exprt &current = it->lazy;
62
63 // some minor simplifications
64 // check if they are worth having
65 if(current.id()==ID_implies)
66 {
70 {
71 continue;
72 }
73 }
74
75 if(current.id()==ID_or)
76 {
77 or_exprt orexp=to_or_expr(current);
79 orexp.operands().size() == 2, "only treats the case of a binary or");
80 exprt o1 = get_value(orexp.op0());
81 exprt o2 = get_value(orexp.op1());
82 if(o1==true_exprt() || o2 == true_exprt())
83 {
84 continue;
85 }
86 }
87
88 to_check.push_back({current, get_value(current), it});
89 }
90
91 // Now check each evaluated constraint using a local solver and activate
92 // violated ones. This phase may modify the main solver (prop).
93 for(auto &entry : to_check)
94 {
98
99 solver << entry.simplified;
100
101 switch(static_cast<decision_proceduret::resultt>(sat_check.prop_solve()))
102 {
104 break;
106 prop.l_set_to_true(convert(entry.constraint));
107 nb_active++;
108 lazy_array_constraints.erase(entry.list_it);
109 break;
111 INVARIANT(false, "error in array over approximation check");
112 }
113 }
114
115 log.debug() << "BV-Refinement: " << nb_active
116 << " array expressions become active" << messaget::eom;
117 log.debug() << "BV-Refinement: " << lazy_array_constraints.size()
118 << " inactive array expressions" << messaget::eom;
119 if(nb_active > 0)
120 progress=true;
121}
122
123
126{
127 if(!lazy_arrays)
128 return;
129
130 for(const auto &constraint : lazy_array_constraints)
131 {
132 // Freeze all symbols in the constraint
133 for(const auto &symbol : find_symbols(constraint.lazy))
134 {
135 if(!bv_width.get_width_opt(symbol.type()).has_value())
136 continue;
137 const bvt bv=convert_bv(symbol);
138 for(const auto &literal : bv)
139 if(!literal.is_constant())
141 }
142
143 // Also freeze the full constraint literal and its sub-expressions
144 // so that convert() during refinement does not hit eliminated
145 // variables.
146 literalt constraint_lit = convert(constraint.lazy);
147 if(!constraint_lit.is_constant())
149 }
150}
static bool convert(const irep_idt &identifier, const std::ostringstream &s, symbol_table_baset &symbol_table, message_handlert &message_handler)
Abstraction Refinement Loop.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:566
std::list< lazy_constraintt > lazy_array_constraints
Definition arrays.h:115
const namespacet & ns
Definition arrays.h:56
bool lazy_arrays
Definition arrays.h:112
void collect_indices()
Definition arrays.cpp:83
void add_array_constraints()
Definition arrays.cpp:277
void update_index_map(bool update_all)
Definition arrays.cpp:404
messaget log
Definition arrays.h:57
virtual std::optional< std::size_t > get_width_opt(const typet &type) const
virtual const bvt & convert_bv(const exprt &expr, const std::optional< std::size_t > expected_width={})
Convert expression to vector of literalts, using an internal cache to speed up conversion if availabl...
Definition boolbv.cpp:40
boolbv_widtht bv_width
Definition boolbv.h:119
mp_integer get_value(const bvt &bv)
Definition boolbv.h:93
void freeze_lazy_constraints()
freeze symbols for incremental solving
void arrays_overapproximated()
check whether counterexample is spurious
void finish_eager_conversion_arrays() override
generate array constraints
resultt
Result of running the decision procedure.
Base class for all expressions.
Definition expr.h:57
The Boolean constant false.
Definition std_expr.h:3125
Boolean implication.
Definition std_expr.h:2144
const irep_idt & id() const
Definition irep.h:388
mstreamt & debug() const
Definition message.h:421
message_handlert & get_message_handler()
Definition message.h:183
static eomt eom
Definition message.h:289
Boolean OR All operands must be boolean, and the result is always boolean.
Definition std_expr.h:2183
void l_set_to_true(literalt a)
Definition prop.h:52
virtual void set_frozen(literalt)
Definition prop.h:117
The Boolean constant true.
Definition std_expr.h:3116
static bool find_symbols(symbol_kindt, const typet &, std::function< bool(const symbol_exprt &)>, std::unordered_set< irep_idt > &bindings, const std::vector< irep_idt > &subs_to_find)
Find identifiers with id ID_symbol of the sub expressions and the subs with ID in subs_to_find consid...
std::vector< literalt > bvt
Definition literal.h:201
void solver(std::vector< framet > &frames, const std::unordered_set< symbol_exprt, irep_hash > &address_taken, const solver_optionst &solver_options, const namespacet &ns, std::vector< propertyt > &properties, std::size_t property_index)
Definition solver.cpp:44
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423
API to expression classes.
const or_exprt & to_or_expr(const exprt &expr)
Cast an exprt to a or_exprt.
Definition std_expr.h:2230
const implies_exprt & to_implies_expr(const exprt &expr)
Cast an exprt to a implies_exprt.
Definition std_expr.h:2164
bool refine_arrays
Enable array refinement.