@@ -68,8 +68,9 @@ void goto_symext::apply_goto_condition(
68
68
}
69
69
70
70
// / Try to evaluate a simple pointer comparison.
71
- // / \param [in,out] condition: An expression of the form "symbol_expr == other"
72
- // / or "symbol_expr != other" (or one of those with the lhs and rhs swapped)
71
+ // / \param [in,out] condition: An L2- renamed expression of the form
72
+ // / "symbol_expr == other" or "symbol_expr != other" (or one of those with
73
+ // / the lhs and rhs swapped)
73
74
// / \param symbol_expr: The symbol expression in the condition
74
75
// / \param other_operand: The other expression in the condition - must pass
75
76
// / goto_symex_is_constant, and since it is pointer-typed it must therefore
@@ -79,7 +80,7 @@ void goto_symext::apply_goto_condition(
79
80
// / \param language_mode: The language mode
80
81
// / \param ns: A namespace
81
82
static void try_evaluate_pointer_comparisons_base_case (
82
- exprt &condition,
83
+ renamedt< exprt, L2> &condition,
83
84
const symbol_exprt &symbol_expr,
84
85
const exprt &other_operand,
85
86
const value_sett &value_set,
@@ -141,23 +142,24 @@ static void try_evaluate_pointer_comparisons_base_case(
141
142
{
142
143
// The symbol cannot possibly have the value \p other_operand because it
143
144
// isn't in the symbol's value-set
144
- condition = condition.id () == ID_equal ? static_cast <exprt >(false_exprt{})
145
- : static_cast <exprt >(true_exprt{});
145
+ condition = condition.get (). id () == ID_equal ? make_renamed<L2 >(false_exprt{})
146
+ : make_renamed<L2 >(true_exprt{});
146
147
}
147
148
else if (value_set_elements.size () == 1 )
148
149
{
149
150
// The symbol must have the value \p other_operand because it is the only
150
151
// thing in the symbol's value-set
151
- condition = condition.id () == ID_equal ? static_cast <exprt >(true_exprt{})
152
- : static_cast <exprt >(false_exprt{});
152
+ condition = condition.get (). id () == ID_equal ? make_renamed<L2 >(true_exprt{})
153
+ : make_renamed<L2 >(false_exprt{});
153
154
}
154
155
}
155
156
156
157
157
158
158
159
// / Check if we have a simple pointer comparison, and if so try to evaluate it.
159
- // / \param [in,out] condition: An expression of the form "symbol_expr == other"
160
- // / or "symbol_expr != other" (or one of those with the lhs and rhs swapped)
160
+ // / \param [in,out] condition: An L2- renamed expression of the form
161
+ // / "symbol_expr == other" or "symbol_expr != other" (or one of those with
162
+ // / the lhs and rhs swapped)
161
163
// / \param symbol_expr: The symbol expression in the condition
162
164
// / \param other_operand: The other expression in the condition - must pass
163
165
// / goto_symex_is_constant, and since it is pointer-typed it must therefore
@@ -167,7 +169,7 @@ static void try_evaluate_pointer_comparisons_base_case(
167
169
// / \param language_mode: The language mode
168
170
// / \param ns: A namespace
169
171
static bool try_evaluate_pointer_comparisons_base_case_with_check (
170
- exprt &condition,
172
+ renamedt< exprt, L2> &condition,
171
173
const exprt &symbol_expr,
172
174
const exprt &other_operand,
173
175
const value_sett &value_set,
@@ -194,35 +196,36 @@ static bool try_evaluate_pointer_comparisons_base_case_with_check(
194
196
195
197
// / Try to evaluate pointer comparisons where they can be trivially determined
196
198
// / using the value-set.
197
- // / \param condition: An expression with boolean type, which should be at least
198
- // / L1-renamed
199
+ // / \param [in,out] condition: An L2-renamed expression with boolean type
199
200
// / \param value_set: The value-set for determining what pointer-typed symbols
200
201
// / might possibly point to
201
202
// / \param language_mode: The language mode
202
203
// / \param ns: A namespace
203
204
// / \return The possibly modified condition
204
- static exprt try_evaluate_pointer_comparisons (
205
- exprt condition,
205
+ static renamedt< exprt, L2> try_evaluate_pointer_comparisons (
206
+ renamedt< exprt, L2> condition,
206
207
const value_sett &value_set,
207
208
const irep_idt language_mode,
208
209
const namespacet &ns)
209
210
{
210
- if (condition.id () == ID_equal || condition.id () == ID_notequal)
211
+ const exprt &condition_expr = condition.get ();
212
+ if (condition_expr.id () == ID_equal || condition_expr.id () == ID_notequal)
211
213
{
212
- if (can_cast_type<pointer_typet>(condition .op0 ().type ()))
214
+ if (can_cast_type<pointer_typet>(condition_expr .op0 ().type ()))
213
215
{
216
+ // Check if this is the form "symbol rel constant" or "constant rel symbol"
214
217
if (!try_evaluate_pointer_comparisons_base_case_with_check (
215
218
condition,
216
- condition .op0 (),
217
- condition .op1 (),
219
+ condition_expr .op0 (),
220
+ condition_expr .op1 (),
218
221
value_set,
219
222
language_mode,
220
223
ns))
221
224
{
222
225
try_evaluate_pointer_comparisons_base_case_with_check (
223
226
condition,
224
- condition .op1 (),
225
- condition .op0 (),
227
+ condition_expr .op1 (),
228
+ condition_expr .op0 (),
226
229
value_set,
227
230
language_mode,
228
231
ns);
@@ -231,11 +234,10 @@ static exprt try_evaluate_pointer_comparisons(
231
234
}
232
235
else
233
236
{
234
- for (auto &op : condition.operands ())
235
- {
237
+ condition.operands ().for_each ([&](renamedt<exprt, L2> &op) {
236
238
op = try_evaluate_pointer_comparisons (
237
239
std::move (op), value_set, language_mode, ns);
238
- }
240
+ });
239
241
}
240
242
241
243
return condition;
@@ -249,14 +251,12 @@ void goto_symext::symex_goto(statet &state)
249
251
clean_expr (new_guard, state, false );
250
252
251
253
renamedt<exprt, L2> renamed_guard = state.rename (std::move (new_guard), ns);
254
+ renamed_guard = try_evaluate_pointer_comparisons (
255
+ std::move (renamed_guard), state.value_set , language_mode, ns);
252
256
if (symex_config.simplify_opt )
253
257
renamed_guard.simplify (ns);
254
- new_guard = try_evaluate_pointer_comparisons (
255
- std::move (new_guard), state.value_set , language_mode, ns);
256
258
new_guard = renamed_guard.get ();
257
259
258
- do_simplify (new_guard);
259
-
260
260
if (new_guard.is_false ())
261
261
{
262
262
target.location (state.guard .as_expr (), state.source );
0 commit comments