Skip to content

Commit b4def86

Browse files
committed
Support (T)bv-typed conversion when T has smaller bit width
We can safely reduce the number of bits of a bv (and not just signed/unsigned bv) typed expression by just cutting off more-significant bits. Fixes: #7426
1 parent 92b4d65 commit b4def86

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/solvers/flattening/boolbv_typecast.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ bool boolbvt::type_conversion(
187187
return false;
188188

189189
case bvtypet::IS_BV:
190-
INVARIANT(
191-
src_width == dest_width,
192-
"source bitvector size shall equal the destination bitvector size");
190+
INVARIANT(src_width >= dest_width, "cannot extend bv-typed bitvector");
193191
dest = src;
192+
if(dest_width < src_width)
193+
dest.resize(dest_width);
194194
return false;
195195

196196
case bvtypet::IS_C_BIT_FIELD:
@@ -265,10 +265,10 @@ bool boolbvt::type_conversion(
265265
}
266266
else if(src_bvtype == bvtypet::IS_BV)
267267
{
268-
INVARIANT(
269-
src_width == dest_width,
270-
"source bitvector width shall equal the destination bitvector width");
268+
INVARIANT(src_width >= dest_width, "cannot extend bv-typed bitvector");
271269
dest = src;
270+
if(dest_width < src_width)
271+
dest.resize(dest_width);
272272
return false;
273273
}
274274
else if(
@@ -424,10 +424,10 @@ bool boolbvt::type_conversion(
424424
break;
425425

426426
case bvtypet::IS_BV:
427-
INVARIANT(
428-
src_width == dest_width,
429-
"source bitvector width shall equal the destination bitvector width");
427+
INVARIANT(src_width >= dest_width, "cannot extend bv-typed bitvector");
430428
dest = src;
429+
if(dest_width < src_width)
430+
dest.resize(dest_width);
431431
return false;
432432

433433
case bvtypet::IS_RANGE:
@@ -506,10 +506,10 @@ bool boolbvt::type_conversion(
506506
break;
507507

508508
case bvtypet::IS_BV:
509-
INVARIANT(
510-
src_width == dest_width,
511-
"source bitvector width shall equal the destination bitvector width");
509+
INVARIANT(src_width >= dest_width, "cannot extend bv-typed bitvector");
512510
dest = src;
511+
if(dest_width < src_width)
512+
dest.resize(dest_width);
513513
return false;
514514

515515
case bvtypet::IS_C_BOOL:

0 commit comments

Comments
 (0)