Skip to content

Commit 5fa1c86

Browse files
committed
Add optional expected_width parameter to convert_bv
1 parent 4cd1ae5 commit 5fa1c86

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

src/solvers/flattening/boolbv.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ bool boolbvt::literal(
113113
throw "found no literal for expression";
114114
}
115115

116-
const bvt &boolbvt::convert_bv(const exprt &expr)
116+
const bvt &
117+
boolbvt::convert_bv(const exprt &expr, optionalt<std::size_t> expected_width)
117118
{
118119
// check cache first
119120
std::pair<bv_cachet::iterator, bool> cache_result=
@@ -126,18 +127,27 @@ const bvt &boolbvt::convert_bv(const exprt &expr)
126127
// Iterators into hash_maps supposedly stay stable
127128
// even though we are inserting more elements recursively.
128129

129-
cache_result.first->second=convert_bitvector(expr);
130+
const bvt &bv = convert_bitvector(expr);
131+
132+
INVARIANT_WITH_DIAGNOSTICS(
133+
!expected_width || bv.size() == *expected_width,
134+
"bitvector width shall match the indicated expected width",
135+
expr.find_source_location(),
136+
expr.pretty());
137+
138+
cache_result.first->second = bv;
130139

131140
// check
132141
forall_literals(it, cache_result.first->second)
133142
{
134143
if(freeze_all && !it->is_constant())
135144
prop.set_frozen(*it);
136-
if(it->var_no()==literalt::unused_var_no())
137-
{
138-
error() << "unused_var_no: " << expr.pretty() << eom;
139-
assert(false);
140-
}
145+
146+
INVARIANT_WITH_DIAGNOSTICS(
147+
it->var_no() != literalt::unused_var_no(),
148+
"variable number must be different from the unused variable number",
149+
expr.find_source_location(),
150+
expr.pretty());
141151
}
142152

143153
return cache_result.first->second;

src/solvers/flattening/boolbv.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ Author: Daniel Kroening, [email protected]
1414
// convert expression to boolean formula
1515
//
1616

17-
#include <util/mp_arith.h>
18-
#include <util/expr.h>
1917
#include <util/byte_operators.h>
18+
#include <util/expr.h>
19+
#include <util/mp_arith.h>
20+
#include <util/optional.h>
2021

2122
#include "bv_utils.h"
2223
#include "boolbv_width.h"
@@ -43,7 +44,10 @@ class boolbvt:public arrayst
4344
{
4445
}
4546

46-
virtual const bvt &convert_bv(const exprt &expr); // check cache
47+
virtual const bvt &convert_bv( // check cache
48+
const exprt &expr,
49+
const optionalt<std::size_t> expected_width = nullopt);
50+
4751
virtual bvt convert_bitvector(const exprt &expr); // no cache
4852

4953
// overloading

src/util/optional.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ using optionalt=nonstd::optional<T>; // NOLINT template typedef
3636

3737
typedef nonstd::bad_optional_access bad_optional_accesst;
3838

39+
using nonstd::nullopt;
40+
3941
#endif // CPROVER_UTIL_OPTIONAL_H

0 commit comments

Comments
 (0)