Skip to content

Commit 979d120

Browse files
committed
rewrite_union, adjust_float_expressions: modify expressions only when necessary
1 parent d08c44a commit 979d120

File tree

2 files changed

+103
-5
lines changed

2 files changed

+103
-5
lines changed

src/goto-symex/adjust_float_expressions.cpp

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,18 @@ Author: Daniel Kroening, [email protected]
1919

2020
/*******************************************************************\
2121
22-
Function: adjust_float_expressions
22+
Function: have_to_adjust_float_expressions
2323
2424
Inputs:
2525
2626
Outputs:
2727
28-
Purpose: This adds the rounding mode to floating-point operations,
29-
including those in vectors and complex numbers.
28+
Purpose:
3029
3130
\*******************************************************************/
3231

33-
void adjust_float_expressions(
34-
exprt &expr,
32+
static bool have_to_adjust_float_expressions(
33+
const exprt &expr,
3534
const namespacet &ns)
3635
{
3736
if(expr.id()==ID_floatbv_plus ||
@@ -41,6 +40,68 @@ void adjust_float_expressions(
4140
expr.id()==ID_floatbv_div ||
4241
expr.id()==ID_floatbv_rem ||
4342
expr.id()==ID_floatbv_typecast)
43+
return false;
44+
45+
const typet &type=ns.follow(expr.type());
46+
47+
if(type.id()==ID_floatbv ||
48+
(type.id()==ID_complex &&
49+
ns.follow(type.subtype()).id()==ID_floatbv))
50+
{
51+
if(expr.id()==ID_plus || expr.id()==ID_minus ||
52+
expr.id()==ID_mult || expr.id()==ID_div ||
53+
expr.id()==ID_rem)
54+
return true;
55+
}
56+
57+
if(expr.id()==ID_typecast)
58+
{
59+
const typecast_exprt &typecast_expr=to_typecast_expr(expr);
60+
61+
const typet &src_type=typecast_expr.op().type();
62+
const typet &dest_type=typecast_expr.type();
63+
64+
if(dest_type.id()==ID_floatbv &&
65+
src_type.id()==ID_floatbv)
66+
return true;
67+
else if(dest_type.id()==ID_floatbv &&
68+
(src_type.id()==ID_c_bool ||
69+
src_type.id()==ID_signedbv ||
70+
src_type.id()==ID_unsignedbv ||
71+
src_type.id()==ID_c_enum_tag))
72+
return true;
73+
else if((dest_type.id()==ID_signedbv ||
74+
dest_type.id()==ID_unsignedbv ||
75+
dest_type.id()==ID_c_enum_tag) &&
76+
src_type.id()==ID_floatbv)
77+
return true;
78+
}
79+
80+
forall_operands(it, expr)
81+
if(have_to_adjust_float_expressions(*it, ns))
82+
return true;
83+
84+
return false;
85+
}
86+
87+
/*******************************************************************\
88+
89+
Function: adjust_float_expressions
90+
91+
Inputs:
92+
93+
Outputs:
94+
95+
Purpose: This adds the rounding mode to floating-point operations,
96+
including those in vectors and complex numbers.
97+
98+
\*******************************************************************/
99+
100+
void adjust_float_expressions(
101+
exprt &expr,
102+
const namespacet &ns)
103+
{
104+
if(!have_to_adjust_float_expressions(expr, ns))
44105
return;
45106

46107
Forall_operands(it, expr)

src/goto-symex/rewrite_union.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,40 @@ Author: Daniel Kroening, [email protected]
1919

2020
/*******************************************************************\
2121
22+
Function: have_to_rewrite_union
23+
24+
Inputs:
25+
26+
Outputs:
27+
28+
Purpose:
29+
30+
\*******************************************************************/
31+
32+
static bool have_to_rewrite_union(
33+
const exprt &expr,
34+
const namespacet &ns)
35+
{
36+
if(expr.id()==ID_member)
37+
{
38+
const exprt &op=to_member_expr(expr).struct_op();
39+
const typet &op_type=ns.follow(op.type());
40+
41+
if(op_type.id()==ID_union)
42+
return true;
43+
}
44+
else if(expr.id()==ID_union)
45+
return true;
46+
47+
forall_operands(it, expr)
48+
if(have_to_rewrite_union(*it, ns))
49+
return true;
50+
51+
return false;
52+
}
53+
54+
/*******************************************************************\
55+
2256
Function: rewrite_union
2357
2458
Inputs:
@@ -34,6 +68,9 @@ void rewrite_union(
3468
exprt &expr,
3569
const namespacet &ns)
3670
{
71+
if(!have_to_rewrite_union(expr, ns))
72+
return;
73+
3774
Forall_operands(it, expr)
3875
rewrite_union(*it, ns);
3976

0 commit comments

Comments
 (0)