Skip to content

Commit aa975d0

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 658d542 commit aa975d0

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

src/goto-harness/memory_snapshot_harness_generator.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Author: Daniel Poetzl
2424
#include <linking/static_lifetime_init.h>
2525

2626
#include "goto_harness_generator_factory.h"
27+
#include "recursive_initialization.h"
2728

2829
void memory_snapshot_harness_generatort::handle_option(
2930
const std::string &option,
@@ -56,6 +57,10 @@ void memory_snapshot_harness_generatort::handle_option(
5657
location_number = optionalt<unsigned>(safe_string2unsigned(start.back()));
5758
}
5859
}
60+
else if(option == "havoc-variables")
61+
{
62+
variables_to_havoc.insert(values.begin(), values.end());
63+
}
5964
else
6065
{
6166
throw invalid_command_line_argument_exceptiont(
@@ -196,17 +201,28 @@ void memory_snapshot_harness_generatort::add_init_section(
196201
}
197202

198203
code_blockt memory_snapshot_harness_generatort::add_assignments_to_globals(
199-
const symbol_tablet &snapshot) const
204+
const symbol_tablet &snapshot,
205+
goto_modelt &goto_model) const
200206
{
207+
recursive_initialization_configt recursive_initialization_config;
208+
auto recursive_initialization = util_make_unique<recursive_initializationt>(
209+
recursive_initialization_config, goto_model);
210+
201211
code_blockt code;
202212
for(const auto &pair : snapshot)
203213
{
204214
const symbolt &symbol = pair.second;
205-
206215
if(!symbol.is_static_lifetime)
207216
continue;
208217

209-
code.add(code_assignt{symbol.symbol_expr(), symbol.value});
218+
if(variables_to_havoc.count(symbol.base_name) == 0)
219+
{
220+
code.add(code_assignt{symbol.symbol_expr(), symbol.value});
221+
}
222+
else
223+
{
224+
recursive_initialization->initialize(symbol.symbol_expr(), 0, {}, code);
225+
}
210226
}
211227
return code;
212228
}
@@ -312,7 +328,8 @@ void memory_snapshot_harness_generatort::generate(
312328

313329
add_init_section(goto_model);
314330

315-
code_blockt harness_function_body = add_assignments_to_globals(snapshot);
331+
code_blockt harness_function_body =
332+
add_assignments_to_globals(snapshot, goto_model);
316333

317334
add_call_with_nondet_arguments(
318335
*called_function_symbol, harness_function_body);

src/goto-harness/memory_snapshot_harness_generator.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ Author: Daniel Poetzl
2121

2222
#define MEMORY_SNAPSHOT_HARNESS_GENERATOR_OPTIONS \
2323
"(memory-snapshot):" \
24-
"(initial-location):" // MEMORY_SNAPSHOT_HARNESS_GENERATOR_OPTIONS
24+
"(initial-location):" \
25+
"(havoc-variables):" // MEMORY_SNAPSHOT_HARNESS_GENERATOR_OPTIONS
2526

2627
// clang-format off
2728
#define MEMORY_SNAPSHOT_HARNESS_GENERATOR_HELP \
@@ -31,6 +32,8 @@ Author: Daniel Poetzl
3132
"--initial-location <func[:<n>]>\n" \
3233
" use given function and location number as " \
3334
"entry\n point\n" \
35+
"--havoc-variables vars initialise variables from vars to\n" \
36+
" non-deterministic values" \
3437
// MEMORY_SNAPSHOT_HARNESS_GENERATOR_HELP
3538
// clang-format on
3639

@@ -61,8 +64,9 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
6164

6265
void add_init_section(goto_modelt &goto_model) const;
6366

64-
code_blockt add_assignments_to_globals(const symbol_tablet &snapshot) const;
65-
67+
code_blockt add_assignments_to_globals(
68+
const symbol_tablet &snapshot,
69+
goto_modelt &goto_model) const;
6670
void add_call_with_nondet_arguments(
6771
const symbolt &called_function_symbol,
6872
code_blockt &code) const;
@@ -75,6 +79,7 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
7579

7680
irep_idt entry_function_name;
7781
optionalt<unsigned> location_number;
82+
std::unordered_set<irep_idt> variables_to_havoc;
7883

7984
message_handlert &message_handler;
8085
};

0 commit comments

Comments
 (0)