Skip to content

Commit f9e72a5

Browse files
author
Daniel Kroening
committed
type simplify_sign
This improves memory safety.
1 parent 7e5fb17 commit f9e72a5

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/util/simplify_expr.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,24 @@ simplify_exprt::resultt<> simplify_exprt::simplify_abs(const abs_exprt &expr)
103103
return unchanged(expr);
104104
}
105105

106-
simplify_exprt::resultt<> simplify_exprt::simplify_sign(const exprt &expr)
106+
simplify_exprt::resultt<> simplify_exprt::simplify_sign(const sign_exprt &expr)
107107
{
108108
if(expr.operands().size()!=1)
109109
return unchanged(expr);
110110

111-
if(expr.op0().is_constant())
111+
if(expr.op().is_constant())
112112
{
113-
const typet &type = expr.op0().type();
113+
const typet &type = expr.op().type();
114114

115115
if(type.id()==ID_floatbv)
116116
{
117-
ieee_floatt value(to_constant_expr(expr.op0()));
117+
ieee_floatt value(to_constant_expr(expr.op()));
118118
return make_boolean_expr(value.get_sign());
119119
}
120120
else if(type.id()==ID_signedbv ||
121121
type.id()==ID_unsignedbv)
122122
{
123-
const auto value = numeric_cast<mp_integer>(expr.op0());
123+
const auto value = numeric_cast<mp_integer>(expr.op());
124124
if(value.has_value())
125125
{
126126
return make_boolean_expr(*value >= 0);
@@ -2276,7 +2276,7 @@ bool simplify_exprt::simplify_node(exprt &expr)
22762276
}
22772277
else if(expr.id()==ID_sign)
22782278
{
2279-
r = simplify_sign(expr);
2279+
r = simplify_sign(to_sign_expr(expr));
22802280
}
22812281
else if(expr.id() == ID_popcount)
22822282
{

src/util/simplify_expr_class.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class namespacet;
5050
class plus_exprt;
5151
class popcount_exprt;
5252
class refined_string_exprt;
53+
class sign_exprt;
5354
class tvt;
5455
class typecast_exprt;
5556
class unary_exprt;
@@ -175,7 +176,7 @@ class simplify_exprt
175176
NODISCARD resultt<> simplify_isnan(const unary_exprt &);
176177
NODISCARD resultt<> simplify_isnormal(const unary_exprt &);
177178
NODISCARD resultt<> simplify_abs(const abs_exprt &);
178-
NODISCARD resultt<> simplify_sign(const exprt &);
179+
NODISCARD resultt<> simplify_sign(const sign_exprt &);
179180
NODISCARD resultt<> simplify_popcount(const popcount_exprt &);
180181
NODISCARD resultt<> simplify_complex(const exprt &);
181182

0 commit comments

Comments
 (0)