@@ -1579,21 +1579,16 @@ bool simplify_exprt::simplify_update(exprt &expr)
1579
1579
return false ;
1580
1580
}
1581
1581
1582
- bool simplify_exprt::simplify_object (exprt &expr)
1582
+ simplify_exprt::resultt<> simplify_exprt::simplify_object (const exprt &expr)
1583
1583
{
1584
1584
if (expr.id ()==ID_plus)
1585
1585
{
1586
1586
if (expr.type ().id ()==ID_pointer)
1587
1587
{
1588
1588
// kill integers from sum
1589
- Forall_operands (it, expr)
1590
- if (it->type ().id () == ID_pointer)
1591
- {
1592
- exprt tmp=*it;
1593
- expr.swap (tmp);
1594
- simplify_object (expr);
1595
- return false ;
1596
- }
1589
+ for (auto &op : expr.operands ())
1590
+ if (op.type ().id () == ID_pointer)
1591
+ return changed (simplify_object (op)); // recursive call
1597
1592
}
1598
1593
}
1599
1594
else if (expr.id ()==ID_typecast)
@@ -1604,9 +1599,7 @@ bool simplify_exprt::simplify_object(exprt &expr)
1604
1599
if (op_type.id ()==ID_pointer)
1605
1600
{
1606
1601
// cast from pointer to pointer
1607
- expr = typecast_expr.op ();
1608
- simplify_object (expr);
1609
- return false ;
1602
+ return changed (simplify_object (typecast_expr.op ())); // recursive call
1610
1603
}
1611
1604
else if (op_type.id ()==ID_signedbv || op_type.id ()==ID_unsignedbv)
1612
1605
{
@@ -1626,8 +1619,7 @@ bool simplify_exprt::simplify_object(exprt &expr)
1626
1619
cand.operands ().size ()==1 &&
1627
1620
cand.op0 ().id ()==ID_address_of)
1628
1621
{
1629
- expr=cand.op0 ();
1630
- return false ;
1622
+ return cand.op0 ();
1631
1623
}
1632
1624
else if (cand.id ()==ID_typecast &&
1633
1625
cand.operands ().size ()==1 &&
@@ -1637,8 +1629,7 @@ bool simplify_exprt::simplify_object(exprt &expr)
1637
1629
cand.op0 ().op0 ().operands ().size ()==1 &&
1638
1630
cand.op0 ().op0 ().op0 ().id ()==ID_address_of)
1639
1631
{
1640
- expr=cand.op0 ().op0 ().op0 ();
1641
- return false ;
1632
+ return cand.op0 ().op0 ().op0 ();
1642
1633
}
1643
1634
}
1644
1635
}
@@ -1651,22 +1642,18 @@ bool simplify_exprt::simplify_object(exprt &expr)
1651
1642
{
1652
1643
// &some[i] -> &some
1653
1644
address_of_exprt new_expr (expr.op0 ().op0 ());
1654
- expr.swap (new_expr);
1655
- simplify_object (expr); // recursion
1656
- return false ;
1645
+ return changed (simplify_object (new_expr)); // recursion
1657
1646
}
1658
1647
else if (expr.op0 ().id ()==ID_member && expr.op0 ().operands ().size ()==1 )
1659
1648
{
1660
1649
// &some.f -> &some
1661
1650
address_of_exprt new_expr (expr.op0 ().op0 ());
1662
- expr.swap (new_expr);
1663
- simplify_object (expr); // recursion
1664
- return false ;
1651
+ return changed (simplify_object (new_expr)); // recursion
1665
1652
}
1666
1653
}
1667
1654
}
1668
1655
1669
- return true ;
1656
+ return unchanged (expr) ;
1670
1657
}
1671
1658
1672
1659
optionalt<exprt> simplify_exprt::bits2expr (
@@ -2563,17 +2550,50 @@ bool simplify_exprt::simplify_node(exprt &expr)
2563
2550
}
2564
2551
}
2565
2552
else if (expr.id ()==ID_pointer_object)
2566
- no_change = simplify_pointer_object (expr) && no_change;
2553
+ {
2554
+ auto r = simplify_pointer_object (expr);
2555
+ if (r.has_changed ())
2556
+ {
2557
+ no_change = false ;
2558
+ expr = r.expr ;
2559
+ }
2560
+ }
2567
2561
else if (expr.id () == ID_is_dynamic_object)
2568
2562
{
2569
- no_change = simplify_is_dynamic_object (expr) && no_change;
2563
+ auto r = simplify_is_dynamic_object (expr);
2564
+ if (r.has_changed ())
2565
+ {
2566
+ no_change = false ;
2567
+ expr = r.expr ;
2568
+ }
2570
2569
}
2571
2570
else if (expr.id () == ID_is_invalid_pointer)
2572
- no_change = simplify_is_invalid_pointer (expr) && no_change;
2571
+ {
2572
+ auto r = simplify_is_invalid_pointer (expr);
2573
+ if (r.has_changed ())
2574
+ {
2575
+ no_change = false ;
2576
+ expr = r.expr ;
2577
+ }
2578
+ }
2573
2579
else if (expr.id ()==ID_object_size)
2574
- no_change = simplify_object_size (expr) && no_change;
2580
+ {
2581
+ auto r = simplify_object_size (expr);
2582
+ if (r.has_changed ())
2583
+ {
2584
+ no_change = false ;
2585
+ expr = r.expr ;
2586
+ }
2587
+ }
2575
2588
else if (expr.id ()==ID_good_pointer)
2576
- no_change = simplify_good_pointer (expr) && no_change;
2589
+ {
2590
+ auto r = simplify_good_pointer (expr);
2591
+ if (r.has_changed ())
2592
+ {
2593
+ no_change = false ;
2594
+ expr = r.expr ;
2595
+ }
2596
+ }
2577
2597
else if (expr.id ()==ID_div)
2578
2598
no_change = simplify_div (expr) && no_change;
2579
2599
else if (expr.id ()==ID_mod)
@@ -2621,9 +2641,23 @@ bool simplify_exprt::simplify_node(exprt &expr)
2621
2641
}
2622
2642
}
2623
2643
else if (expr.id ()==ID_address_of)
2624
- no_change = simplify_address_of (expr) && no_change;
2644
+ {
2645
+ auto r = simplify_address_of (to_address_of_expr (expr));
2646
+ if (r.has_changed ())
2647
+ {
2648
+ no_change = false ;
2649
+ expr = r.expr ;
2650
+ }
2651
+ }
2625
2652
else if (expr.id ()==ID_pointer_offset)
2626
- no_change = simplify_pointer_offset (expr) && no_change;
2653
+ {
2654
+ auto r = simplify_pointer_offset (expr);
2655
+ if (r.has_changed ())
2656
+ {
2657
+ no_change = false ;
2658
+ expr = r.expr ;
2659
+ }
2660
+ }
2627
2661
else if (expr.id ()==ID_extractbit)
2628
2662
no_change = simplify_extractbit (expr) && no_change;
2629
2663
else if (expr.id ()==ID_concatenation)
0 commit comments