Skip to content

Commit 7eaf157

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 0db1830 commit 7eaf157

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

src/goto-harness/memory_snapshot_harness_generator.cpp

Lines changed: 20 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,27 @@ 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_initializationt recursive_initialization{
208+
recursive_initialization_configt{}, goto_model};
209+
201210
code_blockt code;
202211
for(const auto &pair : snapshot)
203212
{
204213
const symbolt &symbol = pair.second;
205-
206214
if(!symbol.is_static_lifetime)
207215
continue;
208216

209-
code.add(code_assignt{symbol.symbol_expr(), symbol.value});
217+
if(variables_to_havoc.count(symbol.base_name) == 0)
218+
{
219+
code.add(code_assignt{symbol.symbol_expr(), symbol.value});
220+
}
221+
else
222+
{
223+
recursive_initialization.initialize(symbol.symbol_expr(), 0, {}, code);
224+
}
210225
}
211226
return code;
212227
}
@@ -312,7 +327,8 @@ void memory_snapshot_harness_generatort::generate(
312327

313328
add_init_section(goto_model);
314329

315-
code_blockt harness_function_body = add_assignments_to_globals(snapshot);
330+
code_blockt harness_function_body =
331+
add_assignments_to_globals(snapshot, goto_model);
316332

317333
add_call_with_nondet_arguments(
318334
*called_function_symbol, harness_function_body);

src/goto-harness/memory_snapshot_harness_generator.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ Author: Daniel Poetzl
1919
#include <util/message.h>
2020
#include <util/optional.h>
2121

22+
// clang-format off
2223
#define MEMORY_SNAPSHOT_HARNESS_GENERATOR_OPTIONS \
2324
"(memory-snapshot):" \
24-
"(initial-location):" // MEMORY_SNAPSHOT_HARNESS_GENERATOR_OPTIONS
25+
"(initial-location):" \
26+
"(havoc-variables):" // MEMORY_SNAPSHOT_HARNESS_GENERATOR_OPTIONS
27+
// clang-format on
2528

2629
// clang-format off
2730
#define MEMORY_SNAPSHOT_HARNESS_GENERATOR_HELP \
@@ -31,6 +34,8 @@ Author: Daniel Poetzl
3134
"--initial-location <func[:<n>]>\n" \
3235
" use given function and location number as " \
3336
"entry\n point\n" \
37+
"--havoc-variables vars initialise variables from vars to\n" \
38+
" non-deterministic values" \
3439
// MEMORY_SNAPSHOT_HARNESS_GENERATOR_HELP
3540
// clang-format on
3641

@@ -61,8 +66,9 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
6166

6267
void add_init_section(goto_modelt &goto_model) const;
6368

64-
code_blockt add_assignments_to_globals(const symbol_tablet &snapshot) const;
65-
69+
code_blockt add_assignments_to_globals(
70+
const symbol_tablet &snapshot,
71+
goto_modelt &goto_model) const;
6672
void add_call_with_nondet_arguments(
6773
const symbolt &called_function_symbol,
6874
code_blockt &code) const;
@@ -75,6 +81,7 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
7581

7682
irep_idt entry_function_name;
7783
optionalt<unsigned> location_number;
84+
std::unordered_set<irep_idt> variables_to_havoc;
7885

7986
message_handlert &message_handler;
8087
};

0 commit comments

Comments
 (0)