Skip to content

Commit f240f27

Browse files
polgreenDaniel Kroening
authored and
Daniel Kroening
committed
fix: add missing integer casts and operations
adds: integer->bool cast bool -> integer cast integer minus operation
1 parent 33bf9eb commit f240f27

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/solvers/smt2/smt2_conv.cpp

+23-3
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,8 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr)
18291829
src_type.id()==ID_unsignedbv ||
18301830
src_type.id()==ID_c_bool ||
18311831
src_type.id()==ID_fixedbv ||
1832-
src_type.id()==ID_pointer)
1832+
src_type.id()==ID_pointer ||
1833+
src_type.id()==ID_integer)
18331834
{
18341835
out << "(not (= ";
18351836
convert_expr(src);
@@ -2274,6 +2275,17 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr)
22742275
else
22752276
UNEXPECTEDCASE("Unknown typecast "+src_type.id_string()+" -> float");
22762277
}
2278+
else if(dest_type.id()==ID_integer)
2279+
{
2280+
if(src_type.id()==ID_bool)
2281+
{
2282+
out << "(ite ";
2283+
convert_expr(src);
2284+
out <<" 1 0 )";
2285+
}
2286+
else
2287+
UNEXPECTEDCASE("Unknown typecast "+src_type.id_string()+" -> integer");
2288+
}
22772289
else if(dest_type.id()==ID_c_bit_field)
22782290
{
22792291
std::size_t from_width=boolbv_width(src_type);
@@ -2917,7 +2929,7 @@ void smt2_convt::convert_plus(const plus_exprt &expr)
29172929

29182930
mp_integer element_size=
29192931
pointer_offset_size(expr.type().subtype(), ns);
2920-
assert(element_size>0);
2932+
CHECK_RETURN(element_size>0);
29212933

29222934
out << "(bvadd ";
29232935
convert_expr(p);
@@ -3084,7 +3096,15 @@ void smt2_convt::convert_minus(const minus_exprt &expr)
30843096
{
30853097
assert(expr.operands().size()==2);
30863098

3087-
if(expr.type().id()==ID_unsignedbv ||
3099+
if(expr.type().id()==ID_integer)
3100+
{
3101+
out << "(- ";
3102+
convert_expr(expr.op0());
3103+
out << " ";
3104+
convert_expr(expr.op1());
3105+
out << ")";
3106+
}
3107+
else if(expr.type().id()==ID_unsignedbv ||
30883108
expr.type().id()==ID_signedbv ||
30893109
expr.type().id()==ID_fixedbv)
30903110
{

0 commit comments

Comments
 (0)