Skip to content

Fix accesses to exprt::opX in simplifer #4987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/util/simplify_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,7 @@ simplify_exprt::simplify_typecast(const typecast_exprt &expr)
op_type.id() == ID_pointer && expr.op().id() == ID_plus &&
expr.op().operands().size() == 2 &&
((expr.op().op0().id() == ID_typecast &&
expr.op().op0().operands().size() == 1 &&
expr.op().op0().op0().is_zero()) ||
to_typecast_expr(expr.op().op0()).op().is_zero()) ||
(expr.op().op0().is_constant() &&
to_constant_expr(expr.op().op0()).get_value() == ID_NULL)))
{
Expand Down Expand Up @@ -1076,14 +1075,14 @@ simplify_exprt::simplify_typecast(const typecast_exprt &expr)
{
// (T1)(T2)x ---> (T1)
// where T1 has fewer bits than T2
if(operand.operands().size()==1 &&
op_type_id==expr_type_id &&
(expr_type_id==ID_unsignedbv || expr_type_id==ID_signedbv) &&
to_bitvector_type(expr_type).get_width()<=
to_bitvector_type(operand.type()).get_width())
if(
op_type_id == expr_type_id &&
(expr_type_id == ID_unsignedbv || expr_type_id == ID_signedbv) &&
to_bitvector_type(expr_type).get_width() <=
to_bitvector_type(operand.type()).get_width())
{
auto new_expr = expr;
new_expr.op() = expr.op().op0();
new_expr.op() = to_typecast_expr(operand).op();
// might enable further simplification
return changed(simplify_typecast(new_expr)); // recursive call
}
Expand Down Expand Up @@ -1139,9 +1138,9 @@ simplify_exprt::simplify_dereference(const dereference_exprt &expr)
return changed(simplify_rec(tmp));
}
// rewrite *(&a[0] + x) to a[x]
else if(pointer.id()==ID_plus &&
pointer.operands().size()==2 &&
pointer.op0().id()==ID_address_of)
else if(
pointer.id() == ID_plus && pointer.operands().size() == 2 &&
to_plus_expr(pointer).op0().id() == ID_address_of)
{
const address_of_exprt &address_of=
to_address_of_expr(pointer.op0());
Expand Down