@@ -539,6 +539,51 @@ bvt bv_pointerst::convert_pointer_type(const exprt &expr)
539539 {
540540 return SUB::convert_byte_update (to_byte_update_expr (expr));
541541 }
542+ else if (expr.id () == ID_field_address)
543+ {
544+ const auto &field_address_expr = to_field_address_expr (expr);
545+ const typet &compound_type = ns.follow (field_address_expr.compound_type ());
546+
547+ // recursive call
548+ auto bv = convert_bitvector (field_address_expr.base ());
549+
550+ if (compound_type.id () == ID_struct)
551+ {
552+ auto offset = member_offset (
553+ to_struct_type (compound_type), field_address_expr.component_name (), ns);
554+ CHECK_RETURN (offset.has_value ());
555+
556+ // add offset
557+ bv = offset_arithmetic (field_address_expr.type (), bv, *offset);
558+ }
559+ else if (compound_type.id () == ID_union)
560+ {
561+ // nothing to do, all fields have offset 0
562+ }
563+ else
564+ {
565+ INVARIANT (false , " field address expressions operate on struct or union" );
566+ }
567+
568+ return bv;
569+ }
570+ else if (expr.id () == ID_element_address)
571+ {
572+ const auto &element_address_expr = to_element_address_expr (expr);
573+
574+ // recursive call
575+ auto bv = convert_bitvector (element_address_expr.base ());
576+
577+ // get element size
578+ auto size = pointer_offset_size (element_address_expr.element_type (), ns);
579+ CHECK_RETURN (size.has_value () && *size >= 0 );
580+
581+ // add offset
582+ bv = offset_arithmetic (
583+ element_address_expr.type (), bv, *size, element_address_expr.index ());
584+
585+ return bv;
586+ }
542587
543588 return conversion_failed (expr);
544589}
@@ -702,51 +747,6 @@ bvt bv_pointerst::convert_bitvector(const exprt &expr)
702747 const auto &object_address_expr = to_object_address_expr (expr);
703748 return add_addr (object_address_expr.object_expr ());
704749 }
705- else if (expr.id () == ID_field_address)
706- {
707- const auto &field_address_expr = to_field_address_expr (expr);
708- const typet &compound_type = ns.follow (field_address_expr.compound_type ());
709-
710- // recursive call
711- auto bv = convert_bitvector (field_address_expr.base ());
712-
713- if (compound_type.id () == ID_struct)
714- {
715- auto offset = member_offset (
716- to_struct_type (compound_type), field_address_expr.component_name (), ns);
717- CHECK_RETURN (offset.has_value ());
718-
719- // add offset
720- bv = offset_arithmetic (field_address_expr.type (), bv, *offset);
721- }
722- else if (compound_type.id () == ID_union)
723- {
724- // nothing to do, all fields have offset 0
725- }
726- else
727- {
728- INVARIANT (false , " field address expressions operate on struct or union" );
729- }
730-
731- return bv;
732- }
733- else if (expr.id () == ID_element_address)
734- {
735- const auto &element_address_expr = to_element_address_expr (expr);
736-
737- // recursive call
738- auto bv = convert_bitvector (element_address_expr.base ());
739-
740- // get element size
741- auto size = pointer_offset_size (element_address_expr.element_type (), ns);
742- CHECK_RETURN (size.has_value () && *size >= 0 );
743-
744- // add offset
745- bv = offset_arithmetic (
746- element_address_expr.type (), bv, *size, element_address_expr.index ());
747-
748- return bv;
749- }
750750
751751 return SUB::convert_bitvector (expr);
752752}
0 commit comments