@@ -877,8 +877,12 @@ static exprt unpack_rec(
877
877
auto element_bits = pointer_offset_bits (subtype, ns);
878
878
CHECK_RETURN (element_bits.has_value ());
879
879
880
- if (!unpack_byte_array && *element_bits == bits_per_byte)
880
+ if (
881
+ !unpack_byte_array && *element_bits == bits_per_byte &&
882
+ can_cast_type<bitvector_typet>(subtype))
883
+ {
881
884
return src;
885
+ }
882
886
883
887
const auto constant_size_opt = numeric_cast<mp_integer>(array_type.size ());
884
888
return unpack_array_vector (
@@ -899,8 +903,12 @@ static exprt unpack_rec(
899
903
auto element_bits = pointer_offset_bits (subtype, ns);
900
904
CHECK_RETURN (element_bits.has_value ());
901
905
902
- if (!unpack_byte_array && *element_bits == bits_per_byte)
906
+ if (
907
+ !unpack_byte_array && *element_bits == bits_per_byte &&
908
+ can_cast_type<bitvector_typet>(subtype))
909
+ {
903
910
return src;
911
+ }
904
912
905
913
return unpack_array_vector (
906
914
src,
@@ -1455,17 +1463,27 @@ static exprt lower_byte_update_byte_array_vector_non_const(
1455
1463
src.offset (), non_const_update_bound.type ()),
1456
1464
non_const_update_bound}};
1457
1465
1466
+ PRECONDITION (
1467
+ src.id () == ID_byte_update_little_endian ||
1468
+ src.id () == ID_byte_update_big_endian);
1469
+ const bool little_endian = src.id () == ID_byte_update_little_endian;
1470
+ endianness_mapt map (
1471
+ to_array_type (value_as_byte_array.type ()).element_type (),
1472
+ little_endian,
1473
+ ns);
1458
1474
if_exprt array_comprehension_body{
1459
1475
or_exprt{std::move (lower_bound), std::move (upper_bound)},
1460
1476
index_exprt{src.op (), array_comprehension_index},
1461
- typecast_exprt::conditional_cast (
1477
+ bv_to_expr (
1462
1478
index_exprt{
1463
1479
value_as_byte_array,
1464
1480
minus_exprt{
1465
1481
array_comprehension_index,
1466
1482
typecast_exprt::conditional_cast (
1467
1483
src.offset (), array_comprehension_index.type ())}},
1468
- subtype)};
1484
+ subtype,
1485
+ map,
1486
+ ns)};
1469
1487
1470
1488
return simplify_expr (
1471
1489
array_comprehension_exprt{
@@ -1491,6 +1509,11 @@ static exprt lower_byte_update_byte_array_vector(
1491
1509
const optionalt<exprt> &non_const_update_bound,
1492
1510
const namespacet &ns)
1493
1511
{
1512
+ PRECONDITION (
1513
+ src.id () == ID_byte_update_little_endian ||
1514
+ src.id () == ID_byte_update_big_endian);
1515
+ const bool little_endian = src.id () == ID_byte_update_little_endian;
1516
+
1494
1517
// apply 'array-update-with' num_elements times
1495
1518
exprt result = src.op ();
1496
1519
@@ -1511,21 +1534,18 @@ static exprt lower_byte_update_byte_array_vector(
1511
1534
continue ;
1512
1535
}
1513
1536
1514
- exprt update_value;
1537
+ endianness_mapt map (element.type (), little_endian, ns);
1538
+ exprt update_value = bv_to_expr (element, subtype, map, ns);
1515
1539
if (non_const_update_bound.has_value ())
1516
1540
{
1517
- update_value = typecast_exprt::conditional_cast (
1518
- if_exprt{
1519
- binary_predicate_exprt{
1520
- from_integer (i, non_const_update_bound->type ()),
1521
- ID_lt,
1522
- *non_const_update_bound},
1523
- element,
1524
- index_exprt{src.op (), where}},
1525
- subtype);
1541
+ update_value = if_exprt{
1542
+ binary_predicate_exprt{
1543
+ from_integer (i, non_const_update_bound->type ()),
1544
+ ID_lt,
1545
+ *non_const_update_bound},
1546
+ update_value,
1547
+ index_exprt{src.op (), where}};
1526
1548
}
1527
- else
1528
- update_value = typecast_exprt::conditional_cast (element, subtype);
1529
1549
1530
1550
if (result.id () != ID_with)
1531
1551
result = with_exprt{result, std::move (where), std::move (update_value)};
0 commit comments