|
10 | 10 | #include "goto_symex_is_constant.h"
|
11 | 11 | #include "goto_symex_state.h"
|
12 | 12 |
|
| 13 | +#include <util/arith_tools.h> |
13 | 14 | #include <util/format_expr.h>
|
14 | 15 |
|
15 | 16 | /// Print the constant propagation map in a human-friendly format.
|
@@ -46,16 +47,56 @@ void goto_statet::apply_condition(
|
46 | 47 | {
|
47 | 48 | if(condition.id() == ID_and)
|
48 | 49 | {
|
| 50 | + // A == B && C == D && E == F ... |
| 51 | + // --> |
| 52 | + // Apply each condition individually |
49 | 53 | for(const auto &op : condition.operands())
|
50 | 54 | apply_condition(op, previous_state, ns);
|
51 | 55 | }
|
| 56 | + else if(condition.id() == ID_not) |
| 57 | + { |
| 58 | + if(to_not_expr(condition).op().id() == ID_notequal) |
| 59 | + { |
| 60 | + // !(A != B) |
| 61 | + // --> |
| 62 | + // A == B |
| 63 | + const auto ¬equal_expr = to_notequal_expr(to_not_expr(condition).op()); |
| 64 | + apply_condition( |
| 65 | + equal_exprt(notequal_expr.lhs(), notequal_expr.rhs()), |
| 66 | + previous_state, |
| 67 | + ns); |
| 68 | + } |
| 69 | + else if(to_not_expr(condition).op().id() == ID_equal) |
| 70 | + { |
| 71 | + // !(A == B) |
| 72 | + // --> |
| 73 | + // A != B |
| 74 | + const auto &equal_expr = to_equal_expr(to_not_expr(condition).op()); |
| 75 | + apply_condition( |
| 76 | + notequal_exprt(equal_expr.lhs(), equal_expr.rhs()), previous_state, ns); |
| 77 | + } |
| 78 | + else |
| 79 | + { |
| 80 | + // !A |
| 81 | + // --> |
| 82 | + // A == false |
| 83 | + apply_condition( |
| 84 | + equal_exprt(to_not_expr(condition).op(), false_exprt()), |
| 85 | + previous_state, |
| 86 | + ns); |
| 87 | + } |
| 88 | + } |
52 | 89 | else if(condition.id() == ID_equal)
|
53 | 90 | {
|
| 91 | + // Base case: try to apply a single equality constraint |
54 | 92 | exprt lhs = to_equal_expr(condition).lhs();
|
55 | 93 | exprt rhs = to_equal_expr(condition).rhs();
|
56 |
| - if(is_ssa_expr(rhs)) |
| 94 | + if(is_ssa_expr(skip_typecast(rhs))) |
57 | 95 | std::swap(lhs, rhs);
|
58 | 96 |
|
| 97 | + lhs = skip_typecast(lhs); |
| 98 | + rhs = typecast_exprt::conditional_cast(rhs, lhs.type()); |
| 99 | + |
59 | 100 | if(is_ssa_expr(lhs) && goto_symex_is_constantt()(rhs))
|
60 | 101 | {
|
61 | 102 | const ssa_exprt &ssa_lhs = to_ssa_expr(lhs);
|
@@ -84,4 +125,23 @@ void goto_statet::apply_condition(
|
84 | 125 | }
|
85 | 126 | }
|
86 | 127 | }
|
| 128 | + else if( |
| 129 | + condition.id() == ID_notequal && |
| 130 | + skip_typecast(to_notequal_expr(condition).lhs()).type().id() == ID_c_bool) |
| 131 | + { |
| 132 | + // A != (true|false) |
| 133 | + // --> |
| 134 | + // A == (false|true) |
| 135 | + exprt lhs = to_notequal_expr(condition).lhs(); |
| 136 | + exprt rhs = to_notequal_expr(condition).rhs(); |
| 137 | + if(is_ssa_expr(rhs)) |
| 138 | + std::swap(lhs, rhs); |
| 139 | + |
| 140 | + if(rhs.is_zero()) |
| 141 | + apply_condition(equal_exprt(lhs, from_integer(1, rhs.type())), previous_state, ns); |
| 142 | + else if(rhs.is_one()) |
| 143 | + apply_condition(equal_exprt(lhs, from_integer(0, rhs.type())), previous_state, ns); |
| 144 | + else |
| 145 | + UNREACHABLE; |
| 146 | + } |
87 | 147 | }
|
0 commit comments