@@ -22,6 +22,7 @@ Author: Daniel Kroening, kroening@kroening.com
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,27 @@ 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
+
1408
+ for (auto &pair : range_true.zip (range_false))
1406
1409
{
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;
1410
+ if_exprt if_expr (cond_copy, pair.first , pair.second );
1411
+ simplify_if (if_expr);
1412
+ pair.first = std::move (if_expr);
1411
1413
}
1412
1414
1415
+ expr.swap (truevalue_copy);
1416
+
1413
1417
return false ;
1414
1418
}
1415
1419
0 commit comments