@@ -129,15 +129,10 @@ void dfcc_instrument_loopt::operator()(
129
129
write_set_populate_instrs,
130
130
nof_targets);
131
131
132
- // Replace bound variables by fresh instances in quantified formulas.
133
- exprt invariant = loop.invariant ;
134
- if (has_subexpr (invariant, ID_exists) || has_subexpr (invariant, ID_forall))
135
- add_quantified_variable (symbol_table, invariant, language_mode);
136
-
137
132
// ---------- Add instrumented instructions ----------
138
133
goto_programt::targett loop_latch =
139
134
loop.find_latch (goto_function.body ).value ();
140
-
135
+ exprt invariant (loop. invariant );
141
136
const auto history_var_map = add_prehead_instructions (
142
137
loop_id,
143
138
goto_function,
@@ -240,7 +235,9 @@ dfcc_instrument_loopt::add_prehead_instructions(
240
235
// GOTO HEAD;
241
236
// ```
242
237
243
-
238
+ // Replace bound variables by fresh instances in quantified formulas.
239
+ if (has_subexpr (invariant, ID_exists) || has_subexpr (invariant, ID_forall))
240
+ add_quantified_variable (symbol_table, invariant, language_mode);
244
241
// initialize loop_entry history vars;
245
242
auto replace_history_result = replace_history_loop_entry (
246
243
symbol_table, invariant, loop_head_location, language_mode);
@@ -329,7 +326,7 @@ dfcc_instrument_loopt::add_step_instructions(
329
326
goto_programt::targett loop_head,
330
327
goto_programt::targett loop_latch,
331
328
goto_programt &havoc_instrs,
332
- const exprt &invariant,
329
+ exprt &invariant,
333
330
const exprt::operandst &decreases_clauses,
334
331
const symbol_exprt &addr_of_loop_write_set,
335
332
const exprt &outer_write_set,
@@ -432,6 +429,9 @@ dfcc_instrument_loopt::add_step_instructions(
432
429
dfcc_utilst::get_function_symbol (symbol_table, function_id).mode ;
433
430
{
434
431
// Assume the loop invariant after havocing the state.
432
+ // Replace bound variables by fresh instances in quantified formulas.
433
+ if (has_subexpr (invariant, ID_exists) || has_subexpr (invariant, ID_forall))
434
+ add_quantified_variable (symbol_table, invariant, language_mode);
435
435
code_assumet assumption{invariant};
436
436
assumption.add_source_location () = loop_head_location;
437
437
converter.goto_convert (assumption, step_instrs, language_mode);
@@ -461,7 +461,7 @@ void dfcc_instrument_loopt::add_body_instructions(
461
461
symbol_table_baset &symbol_table,
462
462
goto_programt::targett loop_head,
463
463
goto_programt::targett loop_latch,
464
- const exprt &invariant,
464
+ exprt &invariant,
465
465
const exprt::operandst &decreases_clauses,
466
466
const symbol_exprt &entered_loop,
467
467
const symbol_exprt &in_base_case,
@@ -512,6 +512,10 @@ void dfcc_instrument_loopt::add_body_instructions(
512
512
" Check invariant after step for loop " +
513
513
id2string (check_location.get_function ()) + " ." +
514
514
std::to_string (cbmc_loop_id));
515
+ // Assume the loop invariant after havocing the state.
516
+ // Replace bound variables by fresh instances in quantified formulas.
517
+ if (has_subexpr (invariant, ID_exists) || has_subexpr (invariant, ID_forall))
518
+ add_quantified_variable (symbol_table, invariant, language_mode);
515
519
code_assertt assertion{invariant};
516
520
assertion.add_source_location () = check_location;
517
521
converter.goto_convert (assertion, pre_loop_latch_instrs, language_mode);
0 commit comments