@@ -129,15 +129,10 @@ void dfcc_instrument_loopt::operator()(
129129 write_set_populate_instrs,
130130 nof_targets);
131131
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-
137132 // ---------- Add instrumented instructions ----------
138133 goto_programt::targett loop_latch =
139134 loop.find_latch (goto_function.body ).value ();
140-
135+ exprt invariant (loop. invariant );
141136 const auto history_var_map = add_prehead_instructions (
142137 loop_id,
143138 goto_function,
@@ -240,7 +235,9 @@ dfcc_instrument_loopt::add_prehead_instructions(
240235 // GOTO HEAD;
241236 // ```
242237
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);
244241 // initialize loop_entry history vars;
245242 auto replace_history_result = replace_history_loop_entry (
246243 symbol_table, invariant, loop_head_location, language_mode);
@@ -329,7 +326,7 @@ dfcc_instrument_loopt::add_step_instructions(
329326 goto_programt::targett loop_head,
330327 goto_programt::targett loop_latch,
331328 goto_programt &havoc_instrs,
332- const exprt &invariant,
329+ exprt &invariant,
333330 const exprt::operandst &decreases_clauses,
334331 const symbol_exprt &addr_of_loop_write_set,
335332 const exprt &outer_write_set,
@@ -432,6 +429,9 @@ dfcc_instrument_loopt::add_step_instructions(
432429 dfcc_utilst::get_function_symbol (symbol_table, function_id).mode ;
433430 {
434431 // 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);
435435 code_assumet assumption{invariant};
436436 assumption.add_source_location () = loop_head_location;
437437 converter.goto_convert (assumption, step_instrs, language_mode);
@@ -461,7 +461,7 @@ void dfcc_instrument_loopt::add_body_instructions(
461461 symbol_table_baset &symbol_table,
462462 goto_programt::targett loop_head,
463463 goto_programt::targett loop_latch,
464- const exprt &invariant,
464+ exprt &invariant,
465465 const exprt::operandst &decreases_clauses,
466466 const symbol_exprt &entered_loop,
467467 const symbol_exprt &in_base_case,
@@ -512,6 +512,10 @@ void dfcc_instrument_loopt::add_body_instructions(
512512 " Check invariant after step for loop " +
513513 id2string (check_location.get_function ()) + " ." +
514514 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);
515519 code_assertt assertion{invariant};
516520 assertion.add_source_location () = check_location;
517521 converter.goto_convert (assertion, pre_loop_latch_instrs, language_mode);
0 commit comments