Skip to content

Commit 9f4b2e1

Browse files
committed
Nondet-static: also update symbol table
This is to make sure that that re-creating initialisation functions restores non-deterministic values.
1 parent 6f14542 commit 9f4b2e1

File tree

2 files changed

+16
-28
lines changed

2 files changed

+16
-28
lines changed

Diff for: src/goto-instrument/nondet_static.cpp

+16-24
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,17 @@ bool is_nondet_initializable_static(
7777
/// assigned to nondet-initializable static variables with nondeterministic
7878
/// values.
7979
/// \param ns: Namespace for resolving type information.
80-
/// \param [out] goto_functions: Existing goto-functions to be updated.
80+
/// \param [inout] goto_model: Existing goto-functions and symbol table to
81+
/// be updated.
8182
/// \param fct_name: Name of the goto-function to be updated.
8283
static void nondet_static(
8384
const namespacet &ns,
84-
goto_functionst &goto_functions,
85+
goto_modelt &goto_model,
8586
const irep_idt &fct_name)
8687
{
8788
goto_functionst::function_mapt::iterator fct_entry =
88-
goto_functions.function_map.find(fct_name);
89-
CHECK_RETURN(fct_entry != goto_functions.function_map.end());
89+
goto_model.goto_functions.function_map.find(fct_name);
90+
CHECK_RETURN(fct_entry != goto_model.goto_functions.function_map.end());
9091

9192
goto_programt &init = fct_entry->second.body;
9293

@@ -99,11 +100,11 @@ static void nondet_static(
99100

100101
if(is_nondet_initializable_static(sym, ns))
101102
{
102-
const auto source_location = instruction.source_location();
103-
instruction = goto_programt::make_assignment(
104-
code_assignt(
105-
sym, side_effect_expr_nondett(sym.type(), source_location)),
106-
source_location);
103+
side_effect_expr_nondett nondet{
104+
sym.type(), instruction.source_location()};
105+
instruction.assign_rhs_nonconst() = nondet;
106+
goto_model.symbol_table.get_writeable_ref(sym.get_identifier()).value =
107+
nondet;
107108
}
108109
}
109110
else if(instruction.is_function_call())
@@ -114,33 +115,24 @@ static void nondet_static(
114115
if(has_prefix(
115116
id2string(fsym.get_identifier()), "#cpp_dynamic_initialization#"))
116117
{
117-
nondet_static(ns, goto_functions, fsym.get_identifier());
118+
nondet_static(ns, goto_model, fsym.get_identifier());
118119
}
119120
}
120121
}
121122

122123
// update counters etc.
123-
goto_functions.update();
124-
}
125-
126-
/// Nondeterministically initializes global scope variables in
127-
/// CPROVER_initialize function.
128-
/// \param ns: Namespace for resolving type information.
129-
/// \param [out] goto_functions: Existing goto-functions to be updated.
130-
void nondet_static(const namespacet &ns, goto_functionst &goto_functions)
131-
{
132-
nondet_static(ns, goto_functions, INITIALIZE_FUNCTION);
124+
goto_model.goto_functions.update();
133125
}
134126

135127
/// First main entry point of the module. Nondeterministically initializes
136128
/// global scope variables, except for constants (such as string literals, final
137129
/// fields) and internal variables (such as CPROVER and symex variables,
138130
/// language specific internal variables).
139-
/// \param [out] goto_model: Existing goto-model to be updated.
131+
/// \param [inout] goto_model: Existing goto-model to be updated.
140132
void nondet_static(goto_modelt &goto_model)
141133
{
142134
const namespacet ns(goto_model.symbol_table);
143-
nondet_static(ns, goto_model.goto_functions);
135+
nondet_static(ns, goto_model, INITIALIZE_FUNCTION);
144136
}
145137

146138
/// Second main entry point of the module. Nondeterministically initializes
@@ -200,7 +192,7 @@ void nondet_static(
200192
}
201193
}
202194

203-
nondet_static(ns, goto_model.goto_functions, INITIALIZE_FUNCTION);
195+
nondet_static(ns, goto_model, INITIALIZE_FUNCTION);
204196
}
205197

206198
/// Nondeterministically initializes global scope variables that
@@ -228,5 +220,5 @@ void nondet_static_matching(goto_modelt &goto_model, const std::string &regex)
228220
}
229221

230222
const namespacet ns(goto_model.symbol_table);
231-
nondet_static(ns, goto_model.goto_functions, INITIALIZE_FUNCTION);
223+
nondet_static(ns, goto_model, INITIALIZE_FUNCTION);
232224
}

Diff for: src/goto-instrument/nondet_static.h

-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ bool is_nondet_initializable_static(
3232
const symbol_exprt &symbol_expr,
3333
const namespacet &ns);
3434

35-
void nondet_static(
36-
const namespacet &ns,
37-
goto_functionst &goto_functions);
38-
3935
void nondet_static(goto_modelt &);
4036

4137
void nondet_static(goto_modelt &, const std::set<std::string> &);

0 commit comments

Comments
 (0)