Skip to content

Commit 91e0646

Browse files
Daniel Kroeningtautschnig
Daniel Kroening
authored andcommitted
Fix use of binary irep in smt2_conv
The conversion has still assumed that bitvector contants are represented in binary. This now uses the integer2bvrep interface.
1 parent eef01a1 commit 91e0646

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/solvers/smt2/smt2_conv.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,15 @@ constant_exprt smt2_convt::parse_literal(
275275
parse_literal(src.get_sub()[2], unsignedbv_typet(floatbv_type.get_e()));
276276
constant_exprt s3 =
277277
parse_literal(src.get_sub()[3], unsignedbv_typet(floatbv_type.get_f()));
278+
279+
const auto s1_int = numeric_cast_v<mp_integer>(s1);
280+
const auto s2_int = numeric_cast_v<mp_integer>(s2);
281+
const auto s3_int = numeric_cast_v<mp_integer>(s3);
282+
278283
// stitch the bits together
279-
std::string bits=id2string(s1.get_value())+
280-
id2string(s2.get_value())+
281-
id2string(s3.get_value());
282-
value=binary2integer(bits, false);
284+
value = bitwise_or(
285+
s1_int << (floatbv_type.get_e() + floatbv_type.get_f()),
286+
bitwise_or((s2_int << floatbv_type.get_f()), s3_int));
283287
}
284288
else
285289
value=0;
@@ -414,13 +418,12 @@ exprt smt2_convt::parse_struct(
414418
{
415419
// These are just flattened, i.e., we expect to see a monster bit vector.
416420
std::size_t total_width=boolbv_width(type);
417-
exprt l = parse_literal(src, unsignedbv_typet(total_width));
418-
if(!l.is_constant())
419-
return nil_exprt();
421+
const auto l = parse_literal(src, unsignedbv_typet(total_width));
420422

421-
irep_idt binary=to_constant_expr(l).get_value();
422-
if(binary.size()!=total_width)
423-
return nil_exprt();
423+
const irep_idt binary =
424+
integer2binary(numeric_cast_v<mp_integer>(l), total_width);
425+
426+
CHECK_RETURN(binary.size() == total_width);
424427

425428
std::size_t offset=0;
426429

@@ -2371,15 +2374,15 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr)
23712374
significand = 1;
23722375
exponent = 0;
23732376
a.build(significand, exponent);
2374-
val.set(ID_value, integer2binary(a.pack(), a.spec.width()));
2377+
val.set_value(integer2bvrep(a.pack(), a.spec.width()));
23752378

23762379
convert_constant(val);
23772380
out << " ";
23782381

23792382
significand = 0;
23802383
exponent = 0;
23812384
a.build(significand, exponent);
2382-
val.set(ID_value, integer2binary(a.pack(), a.spec.width()));
2385+
val.set_value(integer2bvrep(a.pack(), a.spec.width()));
23832386

23842387
convert_constant(val);
23852388
out << ")";
@@ -2780,7 +2783,7 @@ void smt2_convt::convert_constant(const constant_exprt &expr)
27802783
}
27812784
else if(expr_type.id()==ID_pointer)
27822785
{
2783-
const irep_idt &value=expr.get(ID_value);
2786+
const irep_idt &value = expr.get_value();
27842787

27852788
if(value==ID_NULL)
27862789
{
@@ -3110,7 +3113,7 @@ void smt2_convt::convert_rounding_mode_FPA(const exprt &expr)
31103113
{
31113114
const constant_exprt &cexpr=to_constant_expr(expr);
31123115

3113-
mp_integer value=binary2integer(id2string(cexpr.get_value()), false);
3116+
mp_integer value = numeric_cast_v<mp_integer>(cexpr);
31143117

31153118
if(value==0)
31163119
out << "roundNearestTiesToEven";

0 commit comments

Comments
 (0)