@@ -625,11 +625,6 @@ bvt bv_pointerst::convert_bitvector(const exprt &expr)
625625 const exprt same_object = ::same_object (minus_expr.lhs (), minus_expr.rhs ());
626626 const literalt same_object_lit = convert (same_object);
627627
628- // compute the object size (again, possibly using cached results)
629- const exprt object_size = ::object_size (minus_expr.lhs ());
630- const bvt object_size_bv =
631- bv_utils.zero_extension (convert_bv (object_size), width);
632-
633628 bvt bv = prop.new_variables (width);
634629
635630 if (!same_object_lit.is_false ())
@@ -639,27 +634,11 @@ bvt bv_pointerst::convert_bitvector(const exprt &expr)
639634 const bvt lhs_offset =
640635 bv_utils.sign_extension (offset_literals (lhs, lhs_pt), width);
641636
642- const literalt lhs_in_bounds = prop.land (
643- !bv_utils.sign_bit (lhs_offset),
644- bv_utils.rel (
645- lhs_offset,
646- ID_le,
647- object_size_bv,
648- bv_utilst::representationt::UNSIGNED));
649-
650637 const pointer_typet &rhs_pt = to_pointer_type (minus_expr.rhs ().type ());
651638 const bvt &rhs = convert_bv (minus_expr.rhs ());
652639 const bvt rhs_offset =
653640 bv_utils.sign_extension (offset_literals (rhs, rhs_pt), width);
654641
655- const literalt rhs_in_bounds = prop.land (
656- !bv_utils.sign_bit (rhs_offset),
657- bv_utils.rel (
658- rhs_offset,
659- ID_le,
660- object_size_bv,
661- bv_utilst::representationt::UNSIGNED));
662-
663642 bvt difference = bv_utils.sub (lhs_offset, rhs_offset);
664643
665644 // Support for void* is a gcc extension, with the size treated as 1 byte
@@ -679,9 +658,39 @@ bvt bv_pointerst::convert_bitvector(const exprt &expr)
679658 }
680659 }
681660
661+ // test for null object (integer constants)
662+ const exprt null_object = ::null_object (minus_expr.lhs ());
663+ literalt in_bounds = convert (null_object);
664+
665+ if (!in_bounds.is_true ())
666+ {
667+ // compute the object size (again, possibly using cached results)
668+ const exprt object_size = ::object_size (minus_expr.lhs ());
669+ const bvt object_size_bv =
670+ bv_utils.zero_extension (convert_bv (object_size), width);
671+
672+ const literalt lhs_in_bounds = prop.land (
673+ !bv_utils.sign_bit (lhs_offset),
674+ bv_utils.rel (
675+ lhs_offset,
676+ ID_le,
677+ object_size_bv,
678+ bv_utilst::representationt::UNSIGNED));
679+
680+ const literalt rhs_in_bounds = prop.land (
681+ !bv_utils.sign_bit (rhs_offset),
682+ bv_utils.rel (
683+ rhs_offset,
684+ ID_le,
685+ object_size_bv,
686+ bv_utilst::representationt::UNSIGNED));
687+
688+ in_bounds =
689+ prop.lor (in_bounds, prop.land (lhs_in_bounds, rhs_in_bounds));
690+ }
691+
682692 prop.l_set_to_true (prop.limplies (
683- prop.land (same_object_lit, prop.land (lhs_in_bounds, rhs_in_bounds)),
684- bv_utils.equal (difference, bv)));
693+ prop.land (same_object_lit, in_bounds), bv_utils.equal (difference, bv)));
685694 }
686695
687696 return bv;
0 commit comments