Skip to content

Commit 5bc304c

Browse files
authored
Merge pull request #6409 from tautschnig/cleanup-widest-member-use
Use find_widest_member instead of local code clone
2 parents 29ca8a9 + cd36425 commit 5bc304c

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

src/solvers/lowering/byte_operators.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -834,29 +834,15 @@ static exprt unpack_rec(
834834
else if(src.type().id() == ID_union || src.type().id() == ID_union_tag)
835835
{
836836
const union_typet &union_type = to_union_type(ns.follow(src.type()));
837-
const union_typet::componentst &components = union_type.components();
838837

839-
mp_integer max_width = 0;
840-
typet max_comp_type;
841-
irep_idt max_comp_name;
842-
843-
for(const auto &comp : components)
844-
{
845-
auto element_width = pointer_offset_bits(comp.type(), ns);
846-
847-
if(!element_width.has_value() || *element_width <= max_width)
848-
continue;
849-
850-
max_width = *element_width;
851-
max_comp_type = comp.type();
852-
max_comp_name = comp.get_name();
853-
}
838+
const auto widest_member = union_type.find_widest_union_component(ns);
854839

855-
if(max_width > 0)
840+
if(widest_member.has_value())
856841
{
857-
member_exprt member(src, max_comp_name, max_comp_type);
842+
member_exprt member{
843+
src, widest_member->first.get_name(), widest_member->first.type()};
858844
return unpack_rec(
859-
member, little_endian, offset_bytes, max_bytes, ns, true);
845+
member, little_endian, offset_bytes, widest_member->second, ns, true);
860846
}
861847
}
862848
else if(src.type().id() == ID_pointer)

0 commit comments

Comments
 (0)