Skip to content

Commit eb55978

Browse files
author
Owen
committed
Evaluate pointer comparisons directly on renamedt
This ensures it isn't called with a condition that hasn't been L2-renamed
1 parent 3da4e3f commit eb55978

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

src/goto-symex/symex_goto.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ void goto_symext::apply_goto_condition(
6868
}
6969

7070
/// 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)
7374
/// \param symbol_expr: The symbol expression in the condition
7475
/// \param other_operand: The other expression in the condition - must pass
7576
/// goto_symex_is_constant, and since it is pointer-typed it must therefore
@@ -79,7 +80,7 @@ void goto_symext::apply_goto_condition(
7980
/// \param language_mode: The language mode
8081
/// \param ns: A namespace
8182
static void try_evaluate_pointer_comparisons_base_case(
82-
exprt &condition,
83+
renamedt<exprt, L2> &condition,
8384
const symbol_exprt &symbol_expr,
8485
const exprt &other_operand,
8586
const value_sett &value_set,
@@ -141,23 +142,24 @@ static void try_evaluate_pointer_comparisons_base_case(
141142
{
142143
// The symbol cannot possibly have the value \p other_operand because it
143144
// 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{});
146147
}
147148
else if(value_set_elements.size() == 1)
148149
{
149150
// The symbol must have the value \p other_operand because it is the only
150151
// 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{});
153154
}
154155
}
155156

156157

157158

158159
/// 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)
161163
/// \param symbol_expr: The symbol expression in the condition
162164
/// \param other_operand: The other expression in the condition - must pass
163165
/// 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(
167169
/// \param language_mode: The language mode
168170
/// \param ns: A namespace
169171
static bool try_evaluate_pointer_comparisons_base_case_with_check(
170-
exprt &condition,
172+
renamedt<exprt, L2> &condition,
171173
const exprt &symbol_expr,
172174
const exprt &other_operand,
173175
const value_sett &value_set,
@@ -194,35 +196,36 @@ static bool try_evaluate_pointer_comparisons_base_case_with_check(
194196

195197
/// Try to evaluate pointer comparisons where they can be trivially determined
196198
/// 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
199200
/// \param value_set: The value-set for determining what pointer-typed symbols
200201
/// might possibly point to
201202
/// \param language_mode: The language mode
202203
/// \param ns: A namespace
203204
/// \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,
206207
const value_sett &value_set,
207208
const irep_idt language_mode,
208209
const namespacet &ns)
209210
{
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)
211213
{
212-
if(can_cast_type<pointer_typet>(condition.op0().type()))
214+
if(can_cast_type<pointer_typet>(condition_expr.op0().type()))
213215
{
216+
// Check if this is the form "symbol rel constant" or "constant rel symbol"
214217
if(!try_evaluate_pointer_comparisons_base_case_with_check(
215218
condition,
216-
condition.op0(),
217-
condition.op1(),
219+
condition_expr.op0(),
220+
condition_expr.op1(),
218221
value_set,
219222
language_mode,
220223
ns))
221224
{
222225
try_evaluate_pointer_comparisons_base_case_with_check(
223226
condition,
224-
condition.op1(),
225-
condition.op0(),
227+
condition_expr.op1(),
228+
condition_expr.op0(),
226229
value_set,
227230
language_mode,
228231
ns);
@@ -231,11 +234,10 @@ static exprt try_evaluate_pointer_comparisons(
231234
}
232235
else
233236
{
234-
for(auto &op : condition.operands())
235-
{
237+
condition.operands().for_each([&](renamedt<exprt, L2> &op) {
236238
op = try_evaluate_pointer_comparisons(
237239
std::move(op), value_set, language_mode, ns);
238-
}
240+
});
239241
}
240242

241243
return condition;
@@ -249,14 +251,12 @@ void goto_symext::symex_goto(statet &state)
249251
clean_expr(new_guard, state, false);
250252

251253
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);
252256
if(symex_config.simplify_opt)
253257
renamed_guard.simplify(ns);
254-
new_guard = try_evaluate_pointer_comparisons(
255-
std::move(new_guard), state.value_set, language_mode, ns);
256258
new_guard = renamed_guard.get();
257259

258-
do_simplify(new_guard);
259-
260260
if(new_guard.is_false())
261261
{
262262
target.location(state.guard.as_expr(), state.source);

0 commit comments

Comments
 (0)