@@ -446,20 +446,19 @@ bool simplify_exprt::simplify_mod(exprt &expr)
446
446
447
447
bool simplify_exprt::simplify_plus (exprt &expr)
448
448
{
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 ()) &&
451
+ plus_expr.type ().id ()!=ID_pointer)
451
452
return true ;
452
453
453
454
bool result=true ;
454
455
455
456
exprt::operandst &operands=expr.operands ();
456
457
457
- assert (expr.id ()==ID_plus);
458
-
459
458
// floating-point addition is _NOT_ associative; thus,
460
459
// there is special case for float
461
460
462
- if (ns.follow (expr .type ()).id ()==ID_floatbv)
461
+ if (ns.follow (plus_expr .type ()).id ()==ID_floatbv)
463
462
{
464
463
// we only merge neighboring constants!
465
464
Forall_expr (it, operands)
@@ -482,14 +481,14 @@ bool simplify_exprt::simplify_plus(exprt &expr)
482
481
else
483
482
{
484
483
// ((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 )
484
+ if (plus_expr .type ().id ()==ID_pointer &&
485
+ plus_expr .operands ().size ()==2 &&
486
+ plus_expr .op0 ().id ()==ID_plus &&
487
+ plus_expr .op0 ().operands ().size ()==2 )
489
488
{
490
- exprt op0=expr .op0 ();
489
+ exprt op0=plus_expr .op0 ();
491
490
492
- if (expr .op0 ().op1 ().id ()==ID_plus)
491
+ if (plus_expr .op0 ().op1 ().id ()==ID_plus)
493
492
op0.op1 ().copy_to_operands (expr.op1 ());
494
493
else
495
494
op0.op1 ()=plus_exprt (op0.op1 (), expr.op1 ());
@@ -504,7 +503,7 @@ bool simplify_exprt::simplify_plus(exprt &expr)
504
503
505
504
// count the constants
506
505
size_t count=0 ;
507
- forall_operands (it, expr )
506
+ forall_operands (it, plus_expr )
508
507
if (is_number (it->type ()) && it->is_constant ())
509
508
count++;
510
509
@@ -588,7 +587,7 @@ bool simplify_exprt::simplify_plus(exprt &expr)
588
587
589
588
if (operands.empty ())
590
589
{
591
- expr=from_integer (0 , expr .type ());
590
+ expr=from_integer (0 , plus_expr .type ());
592
591
CHECK_RETURN (expr.is_not_nil ());
593
592
return false ;
594
593
}
0 commit comments