@@ -17,6 +17,7 @@ Author: Daniel Kroening, kroening@kroening.com
1717
1818#include < cassert>
1919
20+ #include < util/invariant.h>
2021#include < util/string2int.h>
2122#include < util/expr_util.h>
2223#include < util/base_type.h>
@@ -858,16 +859,24 @@ bool value_set_dereferencet::memory_model_bytes(
858859 {
859860 // upper bound
860861 {
861- mp_integer from_width=pointer_offset_size (from_type, ns);
862- if (from_width<=0 )
863- throw " unknown or invalid type size:\n " +from_type.pretty ();
864-
865- mp_integer to_width=
866- to_type.id ()==ID_empty?0 : pointer_offset_size (to_type, ns);
867- if (to_width<0 )
868- throw " unknown or invalid type size:\n " +to_type.pretty ();
869-
870- exprt bound=from_integer (from_width-to_width, offset.type ());
862+ exprt from_width=size_of_expr (from_type, ns);
863+ INVARIANT (
864+ from_width.is_not_nil (),
865+ " unknown or invalid type size:\n " +from_type.pretty ());
866+
867+ exprt to_width=
868+ to_type.id ()==ID_empty?
869+ from_integer (0 , size_type ()):size_of_expr (to_type, ns);
870+ INVARIANT (
871+ to_width.is_not_nil (),
872+ " unknown or invalid type size:\n " +to_type.pretty ());
873+ INVARIANT (
874+ from_width.type ()==to_width.type (),
875+ " type mismatch on result of size_of_expr" );
876+
877+ minus_exprt bound (from_width, to_width);
878+ if (bound.type ()!=offset.type ())
879+ bound.make_typecast (offset.type ());
871880
872881 binary_relation_exprt
873882 offset_upper_bound (offset, ID_gt, bound);
0 commit comments