Skip to content

Commit 77df7ea

Browse files
author
Daniel Kroening
authored
Merge pull request #3552 from diffblue/smt2_floatbv_model_fix
smt2 backend: fix floating-point values
2 parents aab0b9b + 3587d9d commit 77df7ea

File tree

5 files changed

+21
-24
lines changed

5 files changed

+21
-24
lines changed

regression/cbmc/hex_trace/main.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
int main()
22
{
3-
int a;
4-
unsigned int b;
5-
a = 0;
6-
a = -100;
7-
a = 2147483647;
8-
b = a*2;
9-
a = -2147483647;
10-
__CPROVER_assert(0,"");
3+
int a;
4+
unsigned int b;
5+
float f;
116

7+
a = 0;
8+
a = -100;
9+
a = 2147483647;
10+
b = a * 2;
11+
a = -2147483647;
12+
f = 0.1f;
13+
14+
__CPROVER_assert(0, "");
1215
}

regression/cbmc/hex_trace/test.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ a=-100 \s*\(0xFFFFFF9C\)
99
a=2147483647 \s*\(0x7FFFFFFF\)
1010
b=4294967294ul? \s*\(0xFFFFFFFE\)
1111
a=-2147483647 \s*\(0x80000001\)
12+
f=0\.1f \s*\(0x3DCCCCCD\)
1213
^VERIFICATION FAILED$
1314
--
1415
^warning: ignoring

scripts/delete_failing_smt2_solver_tests

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ rm Float13/test.desc
2929
rm Float20/test.desc
3030
rm Float22/test.desc
3131
rm Float23/test.desc
32-
rm Float24/test.desc
3332
rm Float3/test.desc
3433
rm Float4/test.desc
3534
rm Float5/test.desc

src/solvers/floatbv/float_bv.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,19 @@ ieee_float_spect float_bvt::get_spec(const exprt &expr)
103103
exprt float_bvt::abs(const exprt &op, const ieee_float_spect &spec)
104104
{
105105
// we mask away the sign bit, which is the most significant bit
106-
std::string mask_str(spec.width(), '1');
107-
mask_str[0]='0';
106+
const mp_integer v = power(2, spec.width() - 1) - 1;
108107

109-
constant_exprt mask(mask_str, op.type());
108+
const constant_exprt mask(integer2bvrep(v, spec.width()), op.type());
110109

111110
return bitand_exprt(op, mask);
112111
}
113112

114113
exprt float_bvt::negation(const exprt &op, const ieee_float_spect &spec)
115114
{
116115
// we flip the sign bit with an xor
117-
std::string mask_str(spec.width(), '0');
118-
mask_str[0]='1';
116+
const mp_integer v = power(2, spec.width() - 1);
119117

120-
constant_exprt mask(mask_str, op.type());
118+
constant_exprt mask(integer2bvrep(v, spec.width()), op.type());
121119

122120
return bitxor_exprt(op, mask);
123121
}
@@ -150,10 +148,9 @@ exprt float_bvt::is_zero(const exprt &src)
150148
const floatbv_typet &type=to_floatbv_type(src.type());
151149
std::size_t width=type.get_width();
152150

153-
std::string mask_str(width, '1');
154-
mask_str[0]='0';
151+
const mp_integer v = power(2, width - 1) - 1;
155152

156-
constant_exprt mask(mask_str, src.type());
153+
constant_exprt mask(integer2bvrep(v, width), src.type());
157154

158155
ieee_floatt z(type);
159156
z.make_zero();

src/solvers/smt2/smt2_conv.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ constant_exprt smt2_convt::parse_literal(
325325
type.id()==ID_floatbv)
326326
{
327327
std::size_t width=boolbv_width(type);
328-
return constant_exprt(integer2binary(value, width), type);
328+
return constant_exprt(integer2bvrep(value, width), type);
329329
}
330330
else if(type.id()==ID_integer ||
331331
type.id()==ID_range)
@@ -2776,11 +2776,8 @@ void smt2_convt::convert_constant(const constant_exprt &expr)
27762776
else
27772777
{
27782778
// produce corresponding bit-vector
2779-
ieee_float_spect spec(floatbv_type);
2780-
2781-
mp_integer v=binary2integer(
2782-
id2string(expr.get_value()), false);
2783-
2779+
const ieee_float_spect spec(floatbv_type);
2780+
const mp_integer v = bvrep2integer(expr.get_value(), spec.width(), false);
27842781
out << "(_ bv" << v << " " << spec.width() << ")";
27852782
}
27862783
}

0 commit comments

Comments
 (0)