@@ -54,22 +54,29 @@ bool is_meta(const goto_programt::const_targett pos)
5454void add_explicit_nondet_for_extern_vars (goto_programt::targetst &locs,
5555 const symbol_tablet &st, goto_functionst &gf)
5656{
57- goto_programt &entry_body=get_body (gf, CPROVER_INIT);
58- goto_programt::instructionst &instrs=entry_body.instructions ;
59- goto_programt::targett pos=std::prev (instrs.end (), 1 );
57+ goto_programt &entry_body=get_entry_body (gf);
58+ goto_programt &init_body=get_body (gf, CPROVER_INIT);
59+ goto_programt::targett entry_pos=entry_body.instructions .begin ();
60+ goto_programt::targett init_pos=std::prev (init_body.instructions .end (), 1 );
61+ size_t marker_index=locs.size ();
6062 for (const symbol_tablet::symbolst::value_type &id_and_symbol : st.symbols )
6163 {
6264 const symbolt &symbol=id_and_symbol.second ;
63- if (!symbol.is_extern ) continue ;
65+ const std::string &name=id2string (id_and_symbol.first );
66+ if (!symbol.is_extern || contains (name, CPROVER_PREFIX)) continue ;
67+ const bool is_solution_var=CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME == name
68+ || CEGIS_CONTROL_SOLUTION_VAR_NAME == name;
69+ goto_programt &body=is_solution_var ? init_body : entry_body;
70+ goto_programt::targett &pos=is_solution_var ? init_pos : entry_pos;
6471 const source_locationt &loc=pos->source_location ;
65- pos=entry_body.insert_before (pos);
72+ if (is_solution_var) pos=body.insert_before (pos);
73+ else pos=body.insert_after (pos);
6674 pos->source_location =loc;
6775 pos->type =goto_program_instruction_typet::ASSIGN;
6876 const side_effect_expr_nondett rhs (symbol.type );
6977 pos->code =code_assignt (symbol.symbol_expr (), rhs);
7078 }
7179 entry_body.update ();
72- collect_counterexample_locations (locs, entry_body, is_meta, locs.size ());
7380}
7481}
7582
@@ -81,8 +88,8 @@ void control_preprocessingt::operator ()()
8188 inline_user_program (st, gf);
8289 goto_programt::targetst &locs=control_program.counterexample_locations ;
8390 goto_programt &body=get_entry_body (gf);
84- collect_counterexample_locations (locs, body, is_meta);
8591 add_explicit_nondet_for_extern_vars (locs, st, gf);
92+ collect_counterexample_locations (locs, body, is_meta);
8693 // XXX: Debug
8794 for (const goto_programt::const_targett target : locs)
8895 {
0 commit comments