Skip to content

Commit bcd7089

Browse files
author
Daniel Kroening
committed
simplify_popcount now has new interface
This improves memory safety.
1 parent c6ead88 commit bcd7089

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/util/simplify_expr.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ bool simplify_exprt::simplify_sign(exprt &expr)
127127
return true;
128128
}
129129

130-
bool simplify_exprt::simplify_popcount(popcount_exprt &expr)
130+
simplify_exprt::resultt<>
131+
simplify_exprt::simplify_popcount(const popcount_exprt &expr)
131132
{
132133
const exprt &op = expr.op();
133134

@@ -145,14 +146,11 @@ bool simplify_exprt::simplify_popcount(popcount_exprt &expr)
145146
if(get_bvrep_bit(value, width, i))
146147
result++;
147148

148-
auto result_expr = from_integer(result, expr.type());
149-
expr.swap(result_expr);
150-
151-
return false;
149+
return from_integer(result, expr.type());
152150
}
153151
}
154152

155-
return true;
153+
return unchanged(expr);
156154
}
157155

158156
bool simplify_exprt::simplify_function_application(exprt &expr)
@@ -2533,7 +2531,14 @@ bool simplify_exprt::simplify_node(exprt &expr)
25332531
else if(expr.id()==ID_sign)
25342532
no_change = simplify_sign(expr) && no_change;
25352533
else if(expr.id() == ID_popcount)
2536-
no_change = simplify_popcount(to_popcount_expr(expr)) && no_change;
2534+
{
2535+
auto r = simplify_popcount(to_popcount_expr(expr));
2536+
if(r.has_changed())
2537+
{
2538+
no_change = false;
2539+
expr = r.expr;
2540+
}
2541+
}
25372542
else if(expr.id() == ID_function_application)
25382543
no_change = simplify_function_application(expr) && no_change;
25392544
else if(expr.id() == ID_complex_real || expr.id() == ID_complex_imag)

src/util/simplify_expr_class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class simplify_exprt
162162
bool simplify_isnormal(exprt &expr);
163163
resultt<> simplify_abs(const abs_exprt &);
164164
bool simplify_sign(exprt &expr);
165-
bool simplify_popcount(popcount_exprt &expr);
165+
resultt<> simplify_popcount(const popcount_exprt &);
166166
bool simplify_complex(exprt &expr);
167167

168168
/// Attempt to simplify mathematical function applications if we have

0 commit comments

Comments
 (0)