|
22 | 22 | #include "namespace.h"
|
23 | 23 | #include "pointer_offset_size.h"
|
24 | 24 | #include "pointer_offset_sum.h"
|
| 25 | +#include "range.h" |
25 | 26 | #include "rational.h"
|
26 | 27 | #include "rational_tools.h"
|
27 | 28 | #include "simplify_utils.h"
|
@@ -1392,24 +1393,29 @@ bool simplify_exprt::simplify_if(if_exprt &expr)
|
1392 | 1393 | return false;
|
1393 | 1394 | }
|
1394 | 1395 |
|
| 1396 | + // this pushes the if-then-else into struct and array constructors |
1395 | 1397 | if(((truevalue.id()==ID_struct && falsevalue.id()==ID_struct) ||
|
1396 | 1398 | (truevalue.id()==ID_array && falsevalue.id()==ID_array)) &&
|
1397 | 1399 | truevalue.operands().size()==falsevalue.operands().size())
|
1398 | 1400 | {
|
1399 | 1401 | exprt cond_copy=cond;
|
1400 | 1402 | exprt falsevalue_copy=falsevalue;
|
1401 |
| - expr.swap(truevalue); |
| 1403 | + exprt truevalue_copy = truevalue; |
1402 | 1404 |
|
1403 |
| - exprt::operandst::const_iterator f_it= |
1404 |
| - falsevalue_copy.operands().begin(); |
1405 |
| - Forall_operands(it, expr) |
| 1405 | + auto range_false = make_range(falsevalue_copy.operands()); |
| 1406 | + auto range_true = make_range(truevalue_copy.operands()); |
| 1407 | + auto new_expr = truevalue; |
| 1408 | + new_expr.operands().clear(); |
| 1409 | + |
| 1410 | + for(const auto &pair : range_true.zip(range_false)) |
1406 | 1411 | {
|
1407 |
| - if_exprt if_expr(cond_copy, *it, *f_it); |
1408 |
| - it->swap(if_expr); |
1409 |
| - simplify_if(to_if_expr(*it)); |
1410 |
| - ++f_it; |
| 1412 | + if_exprt if_expr(cond_copy, pair.first, pair.second); |
| 1413 | + simplify_if(if_expr); |
| 1414 | + new_expr.operands().push_back(std::move(if_expr)); |
1411 | 1415 | }
|
1412 | 1416 |
|
| 1417 | + expr.swap(new_expr); |
| 1418 | + |
1413 | 1419 | return false;
|
1414 | 1420 | }
|
1415 | 1421 |
|
|
0 commit comments