Skip to content

Commit 26f8498

Browse files
authored
Merge pull request #7303 from tautschnig/bugfixes/float-z3
SMT back-end: support floatbv to raw bitvector cast
2 parents 52b9097 + 2693a07 commit 26f8498

File tree

9 files changed

+31
-7
lines changed

9 files changed

+31
-7
lines changed

regression/cbmc/Float-no-simp2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE broken-cprover-smt-backend
22
main.c
33
--floatbv --no-simplify
44
^EXIT=0$

regression/cbmc/Float-no-simp3/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE broken-cprover-smt-backend
22
main.c
33
--floatbv --no-simplify
44
^EXIT=0$

regression/cbmc/Float-no-simp5/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE broken-cprover-smt-backend
22
main.c
33
--floatbv --no-simplify
44
^EXIT=0$

regression/cbmc/Float-zero-sum1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE broken-cprover-smt-backend
22
main.c
33
--floatbv --no-simplify
44
^EXIT=0$

regression/cbmc/Float12/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
CORE broken-cprover-smt-backend
22
main.c
33

44
^EXIT=0$

regression/cbmc/Float22/test.desc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
CORE broken-smt-backend
1+
CORE broken-cprover-smt-backend
22
main.c
33
--floatbv
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$
77
--
88
^warning: ignoring
9+
--
10+
Fixing this test for the CPROVER SMT2 solver (or any other SMT2 solver
11+
supporting FPA) requires addressing the TODO "bit-wise floatbv to bv".

regression/cbmc/Float3/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-z3-smt-backend
1+
CORE
22
main.c
33
--floatbv
44
^EXIT=0$

src/solvers/floatbv/float_bv.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,23 @@ exprt float_bvt::convert(const exprt &expr) const
7878
{
7979
return not_exprt(is_zero(to_typecast_expr(expr).op()));
8080
}
81+
else if(
82+
expr.id() == ID_typecast && expr.type().id() == ID_bv &&
83+
to_typecast_expr(expr).op().type().id() == ID_floatbv) // float -> raw bv
84+
{
85+
const typecast_exprt &tc = to_typecast_expr(expr);
86+
const bitvector_typet &dest_type = to_bitvector_type(expr.type());
87+
const floatbv_typet &src_type = to_floatbv_type(tc.op().type());
88+
if(
89+
dest_type.get_width() != src_type.get_width() ||
90+
dest_type.get_width() == 0)
91+
{
92+
return nil_exprt{};
93+
}
94+
95+
return extractbits_exprt{
96+
to_typecast_expr(expr).op(), dest_type.get_width() - 1, 0, dest_type};
97+
}
8198
else if(expr.id()==ID_floatbv_plus)
8299
{
83100
const auto &float_expr = to_ieee_float_op_expr(expr);

src/solvers/smt2/smt2_conv.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,10 @@ std::string smt2_convt::type2id(const typet &type) const
987987
ieee_float_spect spec(to_floatbv_type(type));
988988
return "f"+std::to_string(spec.width())+"_"+std::to_string(spec.f);
989989
}
990+
else if(type.id() == ID_bv)
991+
{
992+
return "B" + std::to_string(to_bitvector_type(type).get_width());
993+
}
990994
else if(type.id()==ID_unsignedbv)
991995
{
992996
return "u"+std::to_string(to_unsignedbv_type(type).get_width());

0 commit comments

Comments
 (0)