@@ -62,7 +62,7 @@ bvt boolbvt::convert_index(const index_exprt &expr)
62
62
63
63
// Must have a finite size
64
64
mp_integer array_size = numeric_cast_v<mp_integer>(array_type.size ());
65
-
65
+ PRECONDITION (array_size. is_ulong ());
66
66
{
67
67
// see if the index address is constant
68
68
// many of these are compacted by simplify_expr
@@ -117,12 +117,10 @@ bvt boolbvt::convert_index(const index_exprt &expr)
117
117
118
118
binary_relation_exprt lower_bound (
119
119
from_integer (0 , index .type ()), ID_le, index );
120
+ CHECK_RETURN (lower_bound.lhs ().is_not_nil ());
120
121
binary_relation_exprt upper_bound (
121
122
index , ID_lt, from_integer (array_size, index .type ()));
122
-
123
- if (lower_bound.lhs ().is_nil () ||
124
- upper_bound.rhs ().is_nil ())
125
- throw " number conversion failed (2)" ;
123
+ CHECK_RETURN (upper_bound.rhs ().is_not_nil ());
126
124
127
125
and_exprt range_condition (lower_bound, upper_bound);
128
126
implies_exprt implication (range_condition, value_equality);
@@ -174,11 +172,12 @@ bvt boolbvt::convert_index(const index_exprt &expr)
174
172
for (mp_integer i=0 ; i<array_size; i=i+1 )
175
173
{
176
174
index_equality.rhs ()=from_integer (i, index_equality.lhs ().type ());
175
+ CHECK_RETURN (index_equality.rhs ().is_not_nil ());
177
176
178
- if (index_equality. rhs (). is_nil ())
179
- throw " number conversion failed (1) " ;
180
-
181
- assert (it != array. operands (). end () );
177
+ INVARIANT (
178
+ it != array. operands (). end (),
179
+ " this loop iterates over the array, so `it` shouldn't be increased "
180
+ " past the array's end" );
182
181
183
182
value_equality.rhs ()=*it++;
184
183
@@ -200,10 +199,7 @@ bvt boolbvt::convert_index(const index_exprt &expr)
200
199
201
200
// get literals for the whole array
202
201
203
- const bvt &array_bv=convert_bv (array);
204
-
205
- if (array_size*width!=array_bv.size ())
206
- throw " unexpected array size" ;
202
+ const bvt &array_bv = convert_bv (array, array_size.to_ulong () * width);
207
203
208
204
// TODO: maybe a shifter-like construction would be better
209
205
// Would be a lot more compact but propagate worse
@@ -231,9 +227,7 @@ bvt boolbvt::convert_index(const index_exprt &expr)
231
227
for (mp_integer i=0 ; i<array_size; i=i+1 )
232
228
{
233
229
index_equality.rhs ()=from_integer (i, index_equality.lhs ().type ());
234
-
235
- if (index_equality.rhs ().is_nil ())
236
- throw " number conversion failed (1)" ;
230
+ CHECK_RETURN (index_equality.rhs ().is_not_nil ());
237
231
238
232
mp_integer offset=i*width;
239
233
@@ -258,7 +252,9 @@ bvt boolbvt::convert_index(const index_exprt &expr)
258
252
259
253
typet constant_type=index .type (); // type of index operand
260
254
261
- assert (array_size>0 );
255
+ DATA_INVARIANT (
256
+ array_size > 0 ,
257
+ " non-positive array sizes are forbidden by the C standard" );
262
258
263
259
for (mp_integer i=0 ; i<array_size; i=i+1 )
264
260
{
0 commit comments