Skip to content

Commit 7214340

Browse files
committed
Simplification of nested pointer arithmetic: improve readability
Use temporaries to ensure const-access where possible and name subexpressions. This helps navigate the various uses of opX() in this code. No change in behaviour is expected. This code is covered by at least 33 of the regression/cbmc/ tests as well as several other regression tests.
1 parent 3f175c9 commit 7214340

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/util/simplify_expr_int.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,16 +439,20 @@ simplify_exprt::resultt<> simplify_exprt::simplify_plus(const plus_exprt &expr)
439439
expr.op0().id() == ID_plus && expr.op0().type().id() == ID_pointer &&
440440
expr.op0().operands().size() == 2)
441441
{
442-
plus_exprt op0 = to_plus_expr(expr.op0());
442+
plus_exprt result = to_plus_expr(expr.op0());
443+
const exprt &op1 = as_const(result).op1();
443444

444-
if(op0.op1().id() == ID_plus)
445-
to_plus_expr(op0.op1()).add_to_operands(expr.op1());
445+
if(op1.id() == ID_plus)
446+
{
447+
plus_exprt new_op1 = to_plus_expr(op1);
448+
new_op1.add_to_operands(expr.op1());
449+
result.op1() = simplify_plus(new_op1);
450+
}
446451
else
447-
op0.op1()=plus_exprt(op0.op1(), expr.op1());
448-
449-
auto result = op0;
450-
451-
result.op1() = simplify_plus(to_plus_expr(result.op1()));
452+
{
453+
plus_exprt new_op1{op1, expr.op1()};
454+
result.op1() = simplify_plus(new_op1);
455+
}
452456

453457
return changed(simplify_plus(result));
454458
}

0 commit comments

Comments
 (0)