Skip to content

Commit afaff93

Browse files
committed
SMT2: fix for ranges that do not start from 0
This fixes the encoding of addition for ranges that do not start from 0. This fixes the translation from SMT-LIB models into a satisfying assignment for ranges that do not start from 0.
1 parent f9a7807 commit afaff93

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/solvers/smt2/smt2_conv.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,14 @@ constant_exprt smt2_convt::parse_literal(
517517
std::size_t width=boolbv_width(type);
518518
return constant_exprt(integer2bvrep(value, width), type);
519519
}
520-
else if(type.id()==ID_integer ||
521-
type.id()==ID_range)
520+
else if(type.id() == ID_integer)
522521
{
523522
return from_integer(value, type);
524523
}
524+
else if(type.id() == ID_range)
525+
{
526+
return from_integer(value + to_range_type(type).get_from(), type);
527+
}
525528
else
526529
UNREACHABLE_BECAUSE(
527530
"smt2_convt::parse_literal should not be of unsupported type " +
@@ -3783,7 +3786,7 @@ void smt2_convt::convert_plus(const plus_exprt &expr)
37833786
}
37843787
else if(
37853788
expr.type().id() == ID_unsignedbv || expr.type().id() == ID_signedbv ||
3786-
expr.type().id() == ID_fixedbv || expr.type().id() == ID_range)
3789+
expr.type().id() == ID_fixedbv)
37873790
{
37883791
// These could be chained, i.e., need not be binary,
37893792
// but at least MathSat doesn't like that.
@@ -3800,6 +3803,31 @@ void smt2_convt::convert_plus(const plus_exprt &expr)
38003803
convert_plus(to_plus_expr(make_binary(expr)));
38013804
}
38023805
}
3806+
else if(expr.type().id() == ID_range)
3807+
{
3808+
auto &range_type = to_range_type(expr.type());
3809+
3810+
// These could be chained, i.e., need not be binary,
3811+
// but at least MathSat doesn't like that.
3812+
if(expr.operands().size() == 2)
3813+
{
3814+
// add: lhs + from + rhs + from - from = lhs + rhs + from
3815+
mp_integer from = range_type.get_from();
3816+
const auto size = range_type.get_to() - range_type.get_from() + 1;
3817+
const auto width = address_bits(size);
3818+
3819+
out << "(bvadd ";
3820+
convert_expr(expr.op0());
3821+
out << " (bvadd ";
3822+
convert_expr(expr.op1());
3823+
out << " (_ bv" << range_type.get_from() << ' ' << width
3824+
<< ")))"; // bv, bvadd, bvadd
3825+
}
3826+
else
3827+
{
3828+
convert_plus(to_plus_expr(make_binary(expr)));
3829+
}
3830+
}
38033831
else if(expr.type().id() == ID_floatbv)
38043832
{
38053833
// Floating-point additions should have be been converted

0 commit comments

Comments
 (0)