CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 std::list<lazy_constraintt>::iterator it=lazy_array_constraints.begin();
44 while(it!=lazy_array_constraints.end())
45 {
49
50 exprt current=(*it).lazy;
51
52 // some minor simplifications
53 // check if they are worth having
54 if(current.id()==ID_implies)
55 {
59 {
60 ++it;
61 continue;
62 }
63 }
64
65 if(current.id()==ID_or)
66 {
67 or_exprt orexp=to_or_expr(current);
69 orexp.operands().size() == 2, "only treats the case of a binary or");
70 exprt o1=get(orexp.op0());
71 exprt o2=get(orexp.op1());
72 if(o1==true_exprt() || o2 == true_exprt())
73 {
74 ++it;
75 continue;
76 }
77 }
78
79 exprt simplified=get(current);
81
82 switch(static_cast<decision_proceduret::resultt>(sat_check.prop_solve()))
83 {
85 ++it;
86 break;
88 prop.l_set_to_true(convert(current));
89 nb_active++;
90 lazy_array_constraints.erase(it++);
91 break;
93 INVARIANT(false, "error in array over approximation check");
94 }
95 }
96
97 log.debug() << "BV-Refinement: " << nb_active
98 << " array expressions become active" << messaget::eom;
99 log.debug() << "BV-Refinement: " << lazy_array_constraints.size()
100 << " inactive array expressions" << messaget::eom;
101 if(nb_active > 0)
102 progress=true;
103}
104
105
108{
109 if(!lazy_arrays)
110 return;
111
112 for(const auto &constraint : lazy_array_constraints)
113 {
114 for(const auto &symbol : find_symbols(constraint.lazy))
115 {
116 if(!bv_width.get_width_opt(symbol.type()).has_value())
117 continue;
118 const bvt bv=convert_bv(symbol);
119 for(const auto &literal : bv)
120 if(!literal.is_constant())
122 }
123 }
124}
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:562
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:280
void update_index_map(bool update_all)
Definition arrays.cpp:407
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:39
boolbv_widtht bv_width
Definition boolbv.h:117
exprt get(const exprt &expr) const override
Return expr with variables replaced by values from satisfying assignment if available.
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:56
The Boolean constant false.
Definition std_expr.h:3199
Boolean implication.
Definition std_expr.h:2225
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.
Definition std_expr.h:2270
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:3190
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:2317
const implies_exprt & to_implies_expr(const exprt &expr)
Cast an exprt to a implies_exprt.
Definition std_expr.h:2250
bool refine_arrays
Enable array refinement.