@@ -124,40 +124,47 @@ bool boolbvt::type_conversion(
124124 {
125125 case bvtypet::IS_RANGE:
126126 if (
127- src_bvtype == bvtypet::IS_UNSIGNED || src_bvtype == bvtypet::IS_SIGNED ||
128- src_bvtype == bvtypet::IS_C_BOOL)
127+ src_bvtype == bvtypet::IS_UNSIGNED ||
128+ src_bvtype == bvtypet::IS_C_BOOL) // unsigned to range
129129 {
130- mp_integer dest_from = to_range_type (dest_type).get_from ();
130+ // need to do arithmetic: add -dest_from
131+ mp_integer offset = -to_range_type (dest_type).get_from ();
132+ dest = bv_utils.add (
133+ bv_utils.zero_extension (src, dest_width),
134+ bv_utils.build_constant (offset, dest_width));
131135
132- if (dest_from == 0 )
133- {
134- // do zero extension
135- dest.resize (dest_width);
136- for (std::size_t i = 0 ; i < dest.size (); i++)
137- dest[i] = (i < src.size () ? src[i] : const_literal (false ));
136+ return false ;
137+ }
138+ else if (src_bvtype == bvtypet::IS_SIGNED) // signed to range
139+ {
140+ // need to do arithmetic: add -dest_from
141+ mp_integer offset = -to_range_type (dest_type).get_from ();
142+ dest = bv_utils.add (
143+ bv_utils.sign_extension (src, dest_width),
144+ bv_utils.build_constant (offset, dest_width));
138145
139- return false ;
140- }
146+ return false ;
141147 }
142148 else if (src_bvtype == bvtypet::IS_RANGE) // range to range
143149 {
144150 mp_integer src_from = to_range_type (src_type).get_from ();
145151 mp_integer dest_from = to_range_type (dest_type).get_from ();
146152
147- if (dest_from == src_from)
148- {
149- // do zero extension, if needed
150- dest = bv_utils.zero_extension (src, dest_width);
151- return false ;
152- }
153- else
154- {
155- // need to do arithmetic: add src_from-dest_from
156- mp_integer offset = src_from - dest_from;
157- dest = bv_utils.add (
158- bv_utils.zero_extension (src, dest_width),
159- bv_utils.build_constant (offset, dest_width));
160- }
153+ // need to do arithmetic: add src_from-dest_from
154+ mp_integer offset = src_from - dest_from;
155+ dest = bv_utils.add (
156+ bv_utils.zero_extension (src, dest_width),
157+ bv_utils.build_constant (offset, dest_width));
158+
159+ return false ;
160+ }
161+ else if (src_type.id () == ID_bool) // bool to range
162+ {
163+ // need to do arithmetic: add -dest_from
164+ mp_integer offset = -to_range_type (dest_type).get_from ();
165+ dest = bv_utils.add (
166+ bv_utils.zero_extension (src, dest_width),
167+ bv_utils.build_constant (offset, dest_width));
161168
162169 return false ;
163170 }
0 commit comments