Skip to content

Commit 5ad4962

Browse files
peterschrammelgiulio-garbi
authored andcommitted
Add nondet_static_matching regex
Adds a more general mechanism for selecting which static variables should be initialized nondeterministically. The regex matches the string consisting of the filename and the variable display name separated by a colon, e.g. "main.c:x".
1 parent b5bf362 commit 5ad4962

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/goto-instrument/nondet_static.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Date: November 2011
2626

2727
#include <linking/static_lifetime_init.h>
2828

29+
#include <regex>
30+
2931
/// See the return.
3032
/// \param symbol_expr: The symbol expression to analyze.
3133
/// \param ns: Namespace for resolving type information
@@ -200,3 +202,31 @@ void nondet_static(
200202

201203
nondet_static(ns, goto_model.goto_functions, INITIALIZE_FUNCTION);
202204
}
205+
206+
/// Nondeterministically initializes global scope variables that
207+
/// match the given regex.
208+
/// \param [out] goto_model: Existing goto-model to be updated.
209+
/// \param regex: regex for matching variables in the format
210+
/// "filename:variable" (same format as those of except_values in
211+
/// nondet_static(goto_model, except_values) variant above).
212+
void nondet_static_matching(goto_modelt &goto_model, const std::string &regex)
213+
{
214+
const auto regex_matcher = std::regex(regex);
215+
symbol_tablet &symbol_table = goto_model.symbol_table;
216+
217+
for(symbol_tablet::iteratort symbol_it = symbol_table.begin();
218+
symbol_it != symbol_table.end();
219+
symbol_it++)
220+
{
221+
symbolt &symbol = symbol_it.get_writeable_symbol();
222+
std::string qualified_name = id2string(symbol.location.get_file()) + ":" +
223+
id2string(symbol.display_name());
224+
if(!std::regex_match(qualified_name, regex_matcher))
225+
{
226+
symbol.value.set(ID_C_no_nondet_initialization, 1);
227+
}
228+
}
229+
230+
const namespacet ns(goto_model.symbol_table);
231+
nondet_static(ns, goto_model.goto_functions, INITIALIZE_FUNCTION);
232+
}

src/goto-instrument/nondet_static.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ void nondet_static(goto_modelt &);
4040

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

43+
void nondet_static_matching(goto_modelt &, const std::string &);
44+
4345
#endif // CPROVER_GOTO_INSTRUMENT_NONDET_STATIC_H

0 commit comments

Comments
 (0)