@@ -877,8 +877,12 @@ static exprt unpack_rec(
877877 auto element_bits = pointer_offset_bits (subtype, ns);
878878 CHECK_RETURN (element_bits.has_value ());
879879
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+ {
881884 return src;
885+ }
882886
883887 const auto constant_size_opt = numeric_cast<mp_integer>(array_type.size ());
884888 return unpack_array_vector (
@@ -899,8 +903,12 @@ static exprt unpack_rec(
899903 auto element_bits = pointer_offset_bits (subtype, ns);
900904 CHECK_RETURN (element_bits.has_value ());
901905
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+ {
903910 return src;
911+ }
904912
905913 return unpack_array_vector (
906914 src,
@@ -1455,17 +1463,27 @@ static exprt lower_byte_update_byte_array_vector_non_const(
14551463 src.offset (), non_const_update_bound.type ()),
14561464 non_const_update_bound}};
14571465
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);
14581474 if_exprt array_comprehension_body{
14591475 or_exprt{std::move (lower_bound), std::move (upper_bound)},
14601476 index_exprt{src.op (), array_comprehension_index},
1461- typecast_exprt::conditional_cast (
1477+ bv_to_expr (
14621478 index_exprt{
14631479 value_as_byte_array,
14641480 minus_exprt{
14651481 array_comprehension_index,
14661482 typecast_exprt::conditional_cast (
14671483 src.offset (), array_comprehension_index.type ())}},
1468- subtype)};
1484+ subtype,
1485+ map,
1486+ ns)};
14691487
14701488 return simplify_expr (
14711489 array_comprehension_exprt{
@@ -1491,6 +1509,11 @@ static exprt lower_byte_update_byte_array_vector(
14911509 const optionalt<exprt> &non_const_update_bound,
14921510 const namespacet &ns)
14931511{
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+
14941517 // apply 'array-update-with' num_elements times
14951518 exprt result = src.op ();
14961519
@@ -1511,21 +1534,18 @@ static exprt lower_byte_update_byte_array_vector(
15111534 continue ;
15121535 }
15131536
1514- exprt update_value;
1537+ endianness_mapt map (element.type (), little_endian, ns);
1538+ exprt update_value = bv_to_expr (element, subtype, map, ns);
15151539 if (non_const_update_bound.has_value ())
15161540 {
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}};
15261548 }
1527- else
1528- update_value = typecast_exprt::conditional_cast (element, subtype);
15291549
15301550 if (result.id () != ID_with)
15311551 result = with_exprt{result, std::move (where), std::move (update_value)};
0 commit comments