@@ -1391,44 +1391,28 @@ static exprt substitute_array_access(
1391
1391
&symbol_generator)
1392
1392
{
1393
1393
const typet &char_type = array_expr.type ().subtype ();
1394
+ const std::vector<exprt> &operands = array_expr.operands ();
1394
1395
1395
- // Access to an empty array is undefined (non deterministic result)
1396
- if (array_expr.operands ().empty ())
1397
- return symbol_generator (" out_of_bound_access" , char_type);
1396
+ exprt result = symbol_generator (" out_of_bound_access" , char_type);
1398
1397
1399
- const std::size_t last_index = array_expr.operands ().size () - 1 ;
1400
- exprt ite = array_expr.operands ().back ();
1401
-
1402
- if (ite.type () != char_type)
1403
- {
1404
- // We have to manually set the type for unknown values
1405
- INVARIANT (
1406
- ite.id () == ID_unknown,
1407
- string_refinement_invariantt (
1408
- " the last element can only have type char "
1409
- " or unknown, and it is not char type" ));
1410
- ite.type () = char_type;
1411
- }
1412
-
1413
- auto op_it = ++array_expr.operands ().rbegin ();
1414
-
1415
- for (std::size_t i = last_index - 1 ; op_it != array_expr.operands ().rend ();
1416
- ++op_it, --i)
1398
+ for (std::size_t i = 0 ; i < operands.size (); ++i)
1417
1399
{
1418
- const equal_exprt equals (index, from_integer (i, java_int_type ()));
1419
- if (op_it->type () != char_type)
1400
+ // Go in reverse order so that smaller indexes appear first in the result
1401
+ const std::size_t pos = operands.size () - 1 - i;
1402
+ const equal_exprt equals (index, from_integer (pos, java_int_type ()));
1403
+ if (operands[pos].type () != char_type)
1420
1404
{
1421
1405
INVARIANT (
1422
- op_it-> id () == ID_unknown,
1406
+ operands[pos]. id () == ID_unknown,
1423
1407
string_refinement_invariantt (
1424
1408
" elements can only have type char or "
1425
1409
" unknown, and it is not char type" ));
1426
- ite = if_exprt (equals, exprt (ID_unknown, char_type), ite );
1410
+ result = if_exprt (equals, exprt (ID_unknown, char_type), result );
1427
1411
}
1428
1412
else
1429
- ite = if_exprt (equals, *op_it, ite );
1413
+ result = if_exprt (equals, operands[pos], result );
1430
1414
}
1431
- return ite ;
1415
+ return result ;
1432
1416
}
1433
1417
1434
1418
static exprt substitute_array_access (
0 commit comments