Skip to content

Commit 38f7ae0

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 e54f7de commit 38f7ae0

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
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 & 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 \
@@ -63,6 +64,7 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
6364

6465
void add_assignments_to_globals(
6566
const symbol_tablet &snapshot,
67+
goto_modelt &goto_model,
6668
code_blockt &code) const;
6769

6870
void add_call_with_nondet_arguments(
@@ -75,6 +77,7 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
7577

7678
irep_idt function;
7779
optionalt<unsigned> location_number;
80+
std::unordered_set<irep_idt> variables_to_havoc;
7881

7982
message_handlert &message_handler;
8083
};

0 commit comments

Comments
 (0)