CBMC
refine_arrays.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: 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 
18 #include <solvers/sat/satcheck.h>
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  {
46  satcheck_no_simplifiert sat_check{log.get_message_handler()};
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  {
56  implies_exprt imp=to_implies_expr(current);
57  exprt implies_simplified=get(imp.op0());
58  if(implies_simplified==false_exprt())
59  {
60  ++it;
61  continue;
62  }
63  }
64 
65  if(current.id()==ID_or)
66  {
67  or_exprt orexp=to_or_expr(current);
68  INVARIANT(
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);
80  solver << simplified;
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())
121  prop.set_frozen(literal);
122  }
123  }
124 }
boolbvt::bv_width
boolbv_widtht bv_width
Definition: boolbv.h:116
find_symbols
static bool find_symbols(symbol_kindt, const typet &, std::function< bool(const symbol_exprt &)>, std::unordered_set< irep_idt > &bindings)
Definition: find_symbols.cpp:122
arrayst::log
messaget log
Definition: arrays.h:57
bvt
std::vector< literalt > bvt
Definition: literal.h:201
bv_refinementt::arrays_overapproximated
void arrays_overapproximated()
check whether counterexample is spurious
Definition: refine_arrays.cpp:36
bv_refinement.h
decision_proceduret::resultt::D_UNSATISFIABLE
@ D_UNSATISFIABLE
exprt
Base class for all expressions.
Definition: expr.h:55
propt::l_set_to_true
void l_set_to_true(literalt a)
Definition: prop.h:50
arrayst::collect_indices
void collect_indices()
Definition: arrays.cpp:82
messaget::eom
static eomt eom
Definition: message.h:297
boolbv_widtht::get_width_opt
virtual optionalt< std::size_t > get_width_opt(const typet &type) const
Definition: boolbv_width.h:31
decision_proceduret::resultt::D_SATISFIABLE
@ D_SATISFIABLE
find_symbols.h
or_exprt
Boolean OR.
Definition: std_expr.h:2178
arrayst::add_array_constraints
void add_array_constraints()
Definition: arrays.cpp:275
arrayst::lazy_array_constraints
std::list< lazy_constraintt > lazy_array_constraints
Definition: arrays.h:114
boolbvt::convert_bv
virtual const bvt & convert_bv(const exprt &expr, const optionalt< 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
multi_ary_exprt::op1
exprt & op1()
Definition: std_expr.h:883
arrayst::ns
const namespacet & ns
Definition: arrays.h:56
bv_pointerst
Definition: bv_pointers.h:18
decision_proceduret::resultt::D_ERROR
@ D_ERROR
irept::id
const irep_idt & id() const
Definition: irep.h:396
propt::set_frozen
virtual void set_frozen(literalt)
Definition: prop.h:112
false_exprt
The Boolean constant false.
Definition: std_expr.h:3016
bv_refinementt::progress
bool progress
Definition: bv_refinement.h:107
prop_conv_solvert::convert
literalt convert(const exprt &expr) override
Convert a Boolean expression and return the corresponding literal.
Definition: prop_conv_solver.cpp:156
decision_proceduret::resultt
resultt
Result of running the decision procedure.
Definition: decision_procedure.h:43
to_or_expr
const or_exprt & to_or_expr(const exprt &expr)
Cast an exprt to a or_exprt.
Definition: std_expr.h:2226
bv_refinementt::config_
configt config_
Definition: bv_refinement.h:112
satcheck.h
messaget::get_message_handler
message_handlert & get_message_handler()
Definition: message.h:184
to_implies_expr
const implies_exprt & to_implies_expr(const exprt &expr)
Cast an exprt to a implies_exprt.
Definition: std_expr.h:2159
solver
int solver(std::istream &in)
Definition: smt2_solver.cpp:407
boolbvt::unbounded_arrayt::U_ALL
@ U_ALL
bv_refinementt::freeze_lazy_constraints
void freeze_lazy_constraints()
freeze symbols for incremental solving
Definition: refine_arrays.cpp:107
arrayst::update_index_map
void update_index_map(bool update_all)
Definition: arrays.cpp:402
implies_exprt
Boolean implication.
Definition: std_expr.h:2133
exprt::operands
operandst & operands()
Definition: expr.h:94
messaget::debug
mstreamt & debug() const
Definition: message.h:429
arrayst::lazy_arrays
bool lazy_arrays
Definition: arrays.h:111
true_exprt
The Boolean constant true.
Definition: std_expr.h:3007
multi_ary_exprt::op0
exprt & op0()
Definition: std_expr.h:877
std_expr.h
bv_refinementt::configt::refine_arrays
bool refine_arrays
Enable array refinement.
Definition: bv_refinement.h:28
boolbvt::get
exprt get(const exprt &expr) const override
Return expr with variables replaced by values from satisfying assignment if available.
Definition: boolbv_get.cpp:21
binary_exprt::op0
exprt & op0()
Definition: expr.h:125
validation_modet::INVARIANT
@ INVARIANT
prop_conv_solvert::prop
propt & prop
Definition: prop_conv_solver.h:130
bv_refinementt::finish_eager_conversion_arrays
void finish_eager_conversion_arrays() override
generate array constraints
Definition: refine_arrays.cpp:21