Skip to content

Commit bd525e5

Browse files
committed
Add optional expected_width parameter to convert_bv
1 parent 20f05af commit bd525e5

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/solvers/flattening/boolbv.cpp

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

116-
const bvt &boolbvt::convert_bv(const exprt &expr)
116+
const bvt &boolbvt::convert_bv(
117+
const exprt &expr,
118+
optionalt<std::size_t> expected_width)
117119
{
118120
// check cache first
119121
std::pair<bv_cachet::iterator, bool> cache_result=
@@ -126,18 +128,21 @@ const bvt &boolbvt::convert_bv(const exprt &expr)
126128
// Iterators into hash_maps supposedly stay stable
127129
// even though we are inserting more elements recursively.
128130

129-
cache_result.first->second=convert_bitvector(expr);
131+
const bvt &bv = convert_bitvector(expr);
132+
CHECK_RETURN(!expected_width || bv.size() == *expected_width);
133+
134+
cache_result.first->second = bv;
130135

131136
// check
132137
forall_literals(it, cache_result.first->second)
133138
{
134139
if(freeze_all && !it->is_constant())
135140
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-
}
141+
142+
INVARIANT_WITH_DIAGNOSTICS(
143+
it->var_no() != literalt::unused_var_no(),
144+
"variable number must be different from the unused variable number",
145+
expr.pretty());
141146
}
142147

143148
return cache_result.first->second;

src/solvers/flattening/boolbv.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
1717
#include <util/mp_arith.h>
1818
#include <util/expr.h>
1919
#include <util/byte_operators.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)