Skip to content

Commit f71c0ae

Browse files
committed
bv_get_unbounded_array: consider model-specific size
For arrays with symbolic size, a particular model returned by the solver need not have a size large enough to contain indices across all possible paths. Only those relevant for the path taken in this model will be part of the result.
1 parent ffdf10f commit f71c0ae

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/solvers/flattening/boolbv_get.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,11 @@ exprt boolbvt::bv_get_unbounded_array(const exprt &expr) const
297297
exprt size=simplify_expr(get(size_expr), ns);
298298

299299
// get the numeric value, unless it's infinity
300-
mp_integer size_mpint = 0;
300+
const auto size_opt = numeric_cast<mp_integer>(size);
301301

302-
if(size.is_not_nil() && size.id() != ID_infinity)
303-
{
304-
const auto size_opt = numeric_cast<mp_integer>(size);
305-
if(size_opt.has_value() && *size_opt >= 0)
306-
size_mpint = *size_opt;
307-
}
308-
309-
// search array indices
302+
// search array indices, and only use those applicable to a particular model
303+
// (array theory may have seen other indices, which might only be live under a
304+
// different model)
310305

311306
typedef std::map<mp_integer, exprt> valuest;
312307
valuest values;
@@ -336,7 +331,9 @@ exprt boolbvt::bv_get_unbounded_array(const exprt &expr) const
336331
{
337332
const auto index_mpint = numeric_cast<mp_integer>(index_value);
338333

339-
if(index_mpint.has_value())
334+
if(
335+
index_mpint.has_value() && *index_mpint >= 0 &&
336+
(!size_opt.has_value() || *index_mpint < *size_opt))
340337
{
341338
if(value.is_nil())
342339
values[*index_mpint] =
@@ -350,7 +347,7 @@ exprt boolbvt::bv_get_unbounded_array(const exprt &expr) const
350347

351348
exprt result;
352349

353-
if(values.size() != size_mpint)
350+
if(!size_opt.has_value() || values.size() != *size_opt)
354351
{
355352
result = array_list_exprt({}, to_array_type(type));
356353

@@ -370,17 +367,18 @@ exprt boolbvt::bv_get_unbounded_array(const exprt &expr) const
370367
result=exprt(ID_array, type);
371368

372369
// allocate operands
373-
std::size_t size_int = numeric_cast_v<std::size_t>(size_mpint);
370+
std::size_t size_int = numeric_cast_v<std::size_t>(*size_opt);
374371
result.operands().resize(size_int, exprt{ID_unknown});
375372

376373
// search uninterpreted functions
377374

378375
for(valuest::iterator it=values.begin();
379376
it!=values.end();
380377
it++)
381-
if(it->first>=0 && it->first<size_mpint)
382-
result.operands()[numeric_cast_v<std::size_t>(it->first)].swap(
383-
it->second);
378+
{
379+
result.operands()[numeric_cast_v<std::size_t>(it->first)].swap(
380+
it->second);
381+
}
384382
}
385383

386384
return result;

0 commit comments

Comments
 (0)