Skip to content

Commit 3658b21

Browse files
committed
implement address expressions in solver
This adds support for the three new address expressions in the solver, using the obvious flattening.
1 parent 2eea327 commit 3658b21

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/solvers/flattening/bv_pointers.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,56 @@ bvt bv_pointerst::convert_bitvector(const exprt &expr)
692692

693693
return bv_utils.zero_extension(op0, width);
694694
}
695+
else if(expr.id() == ID_object_address)
696+
{
697+
const auto &object_address_expr = to_object_address_expr(expr);
698+
return add_addr(object_address_expr.object_expr());
699+
}
700+
else if(expr.id() == ID_field_address)
701+
{
702+
const auto &field_address_expr = to_field_address_expr(expr);
703+
const typet &compound_type = ns.follow(field_address_expr.compound_type());
704+
705+
// recursive call
706+
auto bv = convert_bitvector(field_address_expr.base());
707+
708+
if(compound_type.id() == ID_struct)
709+
{
710+
auto offset = member_offset(
711+
to_struct_type(compound_type), field_address_expr.component_name(), ns);
712+
CHECK_RETURN(offset.has_value());
713+
714+
// add offset
715+
bv = offset_arithmetic(field_address_expr.type(), bv, *offset);
716+
}
717+
else if(compound_type.id() == ID_union)
718+
{
719+
// nothing to do, all fields have offset 0
720+
}
721+
else
722+
{
723+
INVARIANT(false, "field address expressions operate on struct or union");
724+
}
725+
726+
return bv;
727+
}
728+
else if(expr.id() == ID_element_address)
729+
{
730+
const auto &element_address_expr = to_element_address_expr(expr);
731+
732+
// recursive call
733+
auto bv = convert_bitvector(element_address_expr.base());
734+
735+
// get element size
736+
auto size = pointer_offset_size(element_address_expr.element_type(), ns);
737+
CHECK_RETURN(size.has_value() && *size >= 0);
738+
739+
// add offset
740+
bv = offset_arithmetic(
741+
element_address_expr.type(), bv, *size, element_address_expr.index());
742+
743+
return bv;
744+
}
695745

696746
return SUB::convert_bitvector(expr);
697747
}

0 commit comments

Comments
 (0)