Skip to content

Commit 69e5c2d

Browse files
Use to_plus_expr instead of assert in simplify_plus
to_plus_expr should check if an expression is a plus_exprt, this avoids duplicating checks across the codebase
1 parent fdc4680 commit 69e5c2d

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/util/simplify_expr_int.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -446,20 +446,18 @@ bool simplify_exprt::simplify_mod(exprt &expr)
446446

447447
bool simplify_exprt::simplify_plus(exprt &expr)
448448
{
449-
if(!is_number(expr.type()) &&
450-
expr.type().id()!=ID_pointer)
449+
auto const &plus_expr = to_plus_expr(expr);
450+
if(!is_number(plus_expr.type()) && plus_expr.type().id() != ID_pointer)
451451
return true;
452452

453453
bool result=true;
454454

455455
exprt::operandst &operands=expr.operands();
456456

457-
assert(expr.id()==ID_plus);
458-
459457
// floating-point addition is _NOT_ associative; thus,
460458
// there is special case for float
461459

462-
if(ns.follow(expr.type()).id()==ID_floatbv)
460+
if(ns.follow(plus_expr.type()).id() == ID_floatbv)
463461
{
464462
// we only merge neighboring constants!
465463
Forall_expr(it, operands)
@@ -482,14 +480,13 @@ bool simplify_exprt::simplify_plus(exprt &expr)
482480
else
483481
{
484482
// ((T*)p+a)+b -> (T*)p+(a+b)
485-
if(expr.type().id()==ID_pointer &&
486-
expr.operands().size()==2 &&
487-
expr.op0().id()==ID_plus &&
488-
expr.op0().operands().size()==2)
483+
if(
484+
plus_expr.type().id() == ID_pointer && plus_expr.operands().size() == 2 &&
485+
plus_expr.op0().id() == ID_plus && plus_expr.op0().operands().size() == 2)
489486
{
490-
exprt op0=expr.op0();
487+
exprt op0 = plus_expr.op0();
491488

492-
if(expr.op0().op1().id()==ID_plus)
489+
if(plus_expr.op0().op1().id() == ID_plus)
493490
op0.op1().copy_to_operands(expr.op1());
494491
else
495492
op0.op1()=plus_exprt(op0.op1(), expr.op1());
@@ -504,7 +501,7 @@ bool simplify_exprt::simplify_plus(exprt &expr)
504501

505502
// count the constants
506503
size_t count=0;
507-
forall_operands(it, expr)
504+
forall_operands(it, plus_expr)
508505
if(is_number(it->type()) && it->is_constant())
509506
count++;
510507

@@ -588,7 +585,7 @@ bool simplify_exprt::simplify_plus(exprt &expr)
588585

589586
if(operands.empty())
590587
{
591-
expr=from_integer(0, expr.type());
588+
expr = from_integer(0, plus_expr.type());
592589
CHECK_RETURN(expr.is_not_nil());
593590
return false;
594591
}

0 commit comments

Comments
 (0)