1
+ #include < util/cprover_prefix.h>
2
+
1
3
#include < cegis/cegis-util/string_helper.h>
2
4
#include < cegis/cegis-util/inline_user_program.h>
3
5
#include < cegis/cegis-util/counterexample_vars.h>
4
6
#include < cegis/cegis-util/program_helper.h>
7
+ #include < cegis/instrument/literals.h>
5
8
#include < cegis/control/value/control_vars.h>
6
9
#include < cegis/control/simplify/remove_unused_elements.h>
7
10
#include < cegis/control/preprocessing/propagate_controller_sizes.h>
8
11
#include < cegis/control/preprocessing/control_preprocessing.h>
12
+ #include < goto-programs/remove_returns.h>
9
13
10
14
// XXX: Debug
11
15
#include < iostream>
12
16
// XXX: Debug
13
17
18
+ #define TMP_MARKER " $tmp"
19
+
14
20
control_preprocessingt::control_preprocessingt (const symbol_tablet &st,
15
21
const goto_functionst &gf) :
16
22
control_program(st, gf)
@@ -33,11 +39,34 @@ bool is_meta(const goto_programt::const_targett pos)
33
39
const std::string &func=id2string (loc.get_function ());
34
40
for (const char * const excluded : excluded_functions)
35
41
if (contains (func, excluded)) return true ;
36
- if (goto_program_instruction_typet::ASSIGN != pos->type ) return false ;
37
- const exprt &lhs=to_code_assign (pos->code ).lhs ();
38
- if (ID_symbol != lhs.id ()) return false ;
39
- const std::string &var=id2string (to_symbol_expr (lhs).get_identifier ());
40
- return CEGIS_CONTROL_SOLUTION_VAR_NAME == var;
42
+ if (goto_program_instruction_typet::ASSIGN != pos->type
43
+ && goto_program_instruction_typet::DECL != pos->type ) return false ;
44
+ const std::string &var=id2string (get_affected_variable (*pos));
45
+ if (contains (var, TMP_MARKER) || contains (var, RETURN_VALUE_SUFFIX)
46
+ || contains (var, CPROVER_PREFIX)) return true ;
47
+ return CEGIS_CONTROL_SOLUTION_VAR_NAME == var
48
+ || CEGIS_CONTROL_VECTOR_SOLUTION_VAR_NAME == var;
49
+ }
50
+
51
+ void add_explicit_nondet_for_extern_vars (goto_programt::targetst &locs,
52
+ const symbol_tablet &st, goto_functionst &gf)
53
+ {
54
+ goto_programt &entry_body=get_body (gf, CPROVER_INIT);
55
+ goto_programt::instructionst &instrs=entry_body.instructions ;
56
+ goto_programt::targett pos=std::prev (instrs.end (), 1 );
57
+ for (const symbol_tablet::symbolst::value_type &id_and_symbol : st.symbols )
58
+ {
59
+ const symbolt &symbol=id_and_symbol.second ;
60
+ if (!symbol.is_extern ) continue ;
61
+ const source_locationt &loc=pos->source_location ;
62
+ pos=entry_body.insert_before (pos);
63
+ pos->source_location =loc;
64
+ pos->type =goto_program_instruction_typet::ASSIGN;
65
+ const side_effect_expr_nondett rhs (symbol.type );
66
+ pos->code =code_assignt (symbol.symbol_expr (), rhs);
67
+ }
68
+ entry_body.update ();
69
+ collect_counterexample_locations (locs, entry_body, is_meta, locs.size ());
41
70
}
42
71
}
43
72
@@ -50,6 +79,7 @@ void control_preprocessingt::operator ()()
50
79
goto_programt::targetst &locs=control_program.counterexample_locations ;
51
80
goto_programt &body=get_entry_body (gf);
52
81
collect_counterexample_locations (locs, body, is_meta);
82
+ add_explicit_nondet_for_extern_vars (locs, st, gf);
53
83
// XXX: Debug
54
84
for (const goto_programt::const_targett target : locs)
55
85
{
0 commit comments