Skip to content

Commit f7ce86f

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 d5c94a8 commit f7ce86f

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/goto-harness/memory_snapshot_harness_generator.cpp

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

2424
#include "goto_harness_generator_factory.h"
25+
#include "recursive_initialization.h"
26+
2527

2628
void memory_snapshot_harness_generatort::handle_option(
2729
const std::string &option,
@@ -54,6 +56,10 @@ void memory_snapshot_harness_generatort::handle_option(
5456
location_number = optionalt<unsigned>(safe_string2unsigned(start.back()));
5557
}
5658
}
59+
else if (option == "havoc-variables")
60+
{
61+
variables_to_havoc.insert(values.begin(), values.end());
62+
}
5763
else
5864
{
5965
throw invalid_command_line_argument_exceptiont(
@@ -157,18 +163,29 @@ void memory_snapshot_harness_generatort::add_init_section(
157163

158164
void memory_snapshot_harness_generatort::add_assignments_to_globals(
159165
const symbol_tablet &snapshot,
166+
goto_modelt &goto_model,
160167
code_blockt &code) const
161168
{
169+
recursive_initialization_configt recursive_initialization_config;
170+
auto recursive_initialization = util_make_unique<recursive_initializationt>(
171+
recursive_initialization_config, goto_model);
172+
162173
for(const auto &pair : snapshot)
163174
{
164175
const symbolt &symbol = pair.second;
165176

166177
if(!symbol.is_static_lifetime)
167178
continue;
168179

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

@@ -282,7 +299,7 @@ void memory_snapshot_harness_generatort::generate(
282299

283300
code_blockt harness_function_body;
284301

285-
add_assignments_to_globals(snapshot, harness_function_body);
302+
add_assignments_to_globals(snapshot, goto_model, harness_function_body);
286303

287304
add_call_with_nondet_arguments(
288305
*called_function_symbol, harness_function_body);

src/goto-harness/memory_snapshot_harness_generator.h

Lines changed: 6 additions & 1 deletion
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

@@ -63,6 +66,7 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
6366

6467
void add_assignments_to_globals(
6568
const symbol_tablet &snapshot,
69+
goto_modelt &goto_model,
6670
code_blockt &code) const;
6771

6872
void add_call_with_nondet_arguments(
@@ -75,6 +79,7 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
7579

7680
irep_idt function;
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)