Skip to content

Commit be64fc1

Browse files
author
Daniel Kroening
committed
implement cast bv -> floatbv
This case was missing but is used in our lowering of floating-point operations.
1 parent 3a9b5e0 commit be64fc1

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

regression/cbmc/Float-div3/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
22
main.c
33
--floatbv
44
^EXIT=0$

regression/cbmc/Float-smt2-1/test.desc

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

regression/cbmc/Float-to-double2/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
22
main.c
33
--floatbv --no-simplify
44
^EXIT=0$

src/solvers/smt2/smt2_conv.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2280,12 +2280,13 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr)
22802280
// adding the rounding mode. See
22812281
// smt2_convt::convert_floatbv_typecast.
22822282
// The exception is bool and c_bool to float.
2283+
const auto &dest_floatbv_type = to_floatbv_type(dest_type);
22832284

22842285
if(src_type.id()==ID_bool)
22852286
{
22862287
constant_exprt val(irep_idt(), dest_type);
22872288

2288-
ieee_floatt a(to_floatbv_type(dest_type));
2289+
ieee_floatt a(dest_floatbv_type);
22892290

22902291
mp_integer significand;
22912292
mp_integer exponent;
@@ -2316,6 +2317,23 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr)
23162317
const typecast_exprt tmp(src, bool_typet());
23172318
convert_typecast(typecast_exprt(tmp, dest_type));
23182319
}
2320+
else if(src_type.id() == ID_bv)
2321+
{
2322+
if(to_bv_type(src_type).get_width() != dest_floatbv_type.get_width())
2323+
{
2324+
UNEXPECTEDCASE("Typecast bv -> float with wrong width");
2325+
}
2326+
2327+
if(use_FPA_theory)
2328+
{
2329+
out << "((_ to_fp " << dest_floatbv_type.get_e() << " "
2330+
<< dest_floatbv_type.get_f() + 1 << ") ";
2331+
convert_expr(src);
2332+
out << ')';
2333+
}
2334+
else
2335+
convert_expr(src);
2336+
}
23192337
else
23202338
UNEXPECTEDCASE("Unknown typecast "+src_type.id_string()+" -> float");
23212339
}

0 commit comments

Comments
 (0)