|
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,11 +47,46 @@ 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 | + const exprt &operand = to_not_expr(condition).op(); |
| 59 | + if(operand.id() == ID_notequal) |
| 60 | + { |
| 61 | + // !(A != B) |
| 62 | + // --> |
| 63 | + // A == B |
| 64 | + const auto ¬equal_expr = to_notequal_expr(operand); |
| 65 | + apply_condition( |
| 66 | + equal_exprt{notequal_expr.lhs(), notequal_expr.rhs()}, |
| 67 | + previous_state, |
| 68 | + ns); |
| 69 | + } |
| 70 | + else if(operand.id() == ID_equal) |
| 71 | + { |
| 72 | + // !(A == B) |
| 73 | + // --> |
| 74 | + // A != B |
| 75 | + const auto &equal_expr = to_equal_expr(operand); |
| 76 | + apply_condition( |
| 77 | + notequal_exprt{equal_expr.lhs(), equal_expr.rhs()}, previous_state, ns); |
| 78 | + } |
| 79 | + else |
| 80 | + { |
| 81 | + // !A |
| 82 | + // --> |
| 83 | + // A == false |
| 84 | + apply_condition(equal_exprt{operand, false_exprt{}}, previous_state, ns); |
| 85 | + } |
| 86 | + } |
52 | 87 | else if(condition.id() == ID_equal)
|
53 | 88 | {
|
| 89 | + // Base case: try to apply a single equality constraint |
54 | 90 | exprt lhs = to_equal_expr(condition).lhs();
|
55 | 91 | exprt rhs = to_equal_expr(condition).rhs();
|
56 | 92 | if(is_ssa_expr(rhs))
|
@@ -84,4 +120,33 @@ void goto_statet::apply_condition(
|
84 | 120 | }
|
85 | 121 | }
|
86 | 122 | }
|
| 123 | + else if(condition.id() == ID_symbol) |
| 124 | + { |
| 125 | + if(condition.type() == bool_typet()) |
| 126 | + { |
| 127 | + // A |
| 128 | + // --> |
| 129 | + // A == true |
| 130 | + apply_condition(equal_exprt{condition, true_exprt()}, previous_state, ns); |
| 131 | + } |
| 132 | + } |
| 133 | + else if( |
| 134 | + condition.id() == ID_notequal && |
| 135 | + to_notequal_expr(condition).lhs().type() == bool_typet{}) |
| 136 | + { |
| 137 | + // A != (true|false) |
| 138 | + // --> |
| 139 | + // A == (false|true) |
| 140 | + exprt lhs = to_notequal_expr(condition).lhs(); |
| 141 | + exprt rhs = to_notequal_expr(condition).rhs(); |
| 142 | + if(is_ssa_expr(rhs)) |
| 143 | + std::swap(lhs, rhs); |
| 144 | + |
| 145 | + if(rhs.is_true()) |
| 146 | + apply_condition(equal_exprt{lhs, false_exprt{}}, previous_state, ns); |
| 147 | + else if(rhs.is_false()) |
| 148 | + apply_condition(equal_exprt{lhs, true_exprt{}}, previous_state, ns); |
| 149 | + else |
| 150 | + UNREACHABLE; |
| 151 | + } |
87 | 152 | }
|
0 commit comments