Skip to content

Commit 684b210

Browse files
committed
Add optional expected_width parameter to convert_bv
1 parent 6b7b29a commit 684b210

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
@@ -110,7 +110,8 @@ bool boolbvt::literal(
110110
throw "found no literal for expression";
111111
}
112112

113-
const bvt &boolbvt::convert_bv(const exprt &expr)
113+
const bvt &
114+
boolbvt::convert_bv(const exprt &expr, optionalt<std::size_t> expected_width)
114115
{
115116
// check cache first
116117
std::pair<bv_cachet::iterator, bool> cache_result=
@@ -123,18 +124,27 @@ const bvt &boolbvt::convert_bv(const exprt &expr)
123124
// Iterators into hash_maps supposedly stay stable
124125
// even though we are inserting more elements recursively.
125126

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

128137
// check
129138
forall_literals(it, cache_result.first->second)
130139
{
131140
if(freeze_all && !it->is_constant())
132141
prop.set_frozen(*it);
133-
if(it->var_no()==literalt::unused_var_no())
134-
{
135-
error() << "unused_var_no: " << expr.pretty() << eom;
136-
assert(false);
137-
}
142+
143+
INVARIANT_WITH_DIAGNOSTICS(
144+
it->var_no() != literalt::unused_var_no(),
145+
"variable number must be different from the unused variable number",
146+
expr.find_source_location(),
147+
expr.pretty());
138148
}
139149

140150
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)