Skip to content

Commit 5814594

Browse files
Petr BauchPetr Bauch
Petr Bauch
authored and
Petr Bauch
committed
Havoc global variables in memory snapshot harness
Basically just grabs a list of var-names from command line and calls recursive initialize on them instead of assigning their value.
1 parent 1a61365 commit 5814594

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/goto-harness/memory_snapshot_harness_generator.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Author: Daniel Poetzl
2222
#include <util/symbol_table.h>
2323

2424
#include "goto_harness_generator_factory.h"
25+
#include "recursive_initialization.h"
2526

2627
void memory_snapshot_harness_generatort::handle_option(
2728
const std::string &option,
@@ -54,6 +55,10 @@ void memory_snapshot_harness_generatort::handle_option(
5455
location_number = optionalt<unsigned>(safe_string2unsigned(start.back()));
5556
}
5657
}
58+
else if(option == "havoc-variables")
59+
{
60+
variables_to_havoc.insert(values.begin(), values.end());
61+
}
5762
else
5863
{
5964
throw invalid_command_line_argument_exceptiont(
@@ -157,18 +162,29 @@ void memory_snapshot_harness_generatort::add_init_section(
157162

158163
void memory_snapshot_harness_generatort::add_assignments_to_globals(
159164
const symbol_tablet &snapshot,
165+
goto_modelt &goto_model,
160166
code_blockt &code) const
161167
{
168+
recursive_initialization_configt recursive_initialization_config;
169+
auto recursive_initialization = util_make_unique<recursive_initializationt>(
170+
recursive_initialization_config, goto_model);
171+
162172
for(const auto &pair : snapshot)
163173
{
164174
const symbolt &symbol = pair.second;
165175

166176
if(!symbol.is_static_lifetime)
167177
continue;
168178

169-
code_assignt code_assign(symbol.symbol_expr(), symbol.value);
170-
171-
code.add(code_assign);
179+
if(variables_to_havoc.count(symbol.base_name) == 0)
180+
{
181+
code_assignt code_assign(symbol.symbol_expr(), symbol.value);
182+
code.add(code_assign);
183+
}
184+
else
185+
{
186+
recursive_initialization->initialize(symbol.symbol_expr(), 0, {}, code);
187+
}
172188
}
173189
}
174190

@@ -282,7 +298,7 @@ void memory_snapshot_harness_generatort::generate(
282298

283299
code_blockt harness_function_body;
284300

285-
add_assignments_to_globals(snapshot, harness_function_body);
301+
add_assignments_to_globals(snapshot, goto_model, harness_function_body);
286302

287303
add_call_with_nondet_arguments(
288304
*called_function_symbol, harness_function_body);

src/goto-harness/memory_snapshot_harness_generator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Author: Daniel Poetzl
3131
"--initial-location <func[:<n>]>\n" \
3232
" use given function and location number as " \
3333
"entry\n point\n" \
34+
"--havoc-variables vars initialise variables from vars to\n" \
35+
" non-deterministic values" \
3436
// MEMORY_SNAPSHOT_HARNESS_GENERATOR_HELP
3537
// clang-format on
3638

@@ -63,6 +65,7 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
6365

6466
void add_assignments_to_globals(
6567
const symbol_tablet &snapshot,
68+
goto_modelt &goto_model,
6669
code_blockt &code) const;
6770

6871
void add_call_with_nondet_arguments(
@@ -75,6 +78,7 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
7578

7679
irep_idt function;
7780
optionalt<unsigned> location_number;
81+
std::unordered_set<irep_idt> variables_to_havoc;
7882

7983
message_handlert &message_handler;
8084
};

0 commit comments

Comments
 (0)