@@ -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 ;
0 commit comments