Skip to content

Commit 9bfb0dd

Browse files
Petr Bauchpetr-bauch
Petr Bauch
authored andcommitted
Extend memory-snapshot options
To handle treating pointers as arrays together with their sizes (similar to function arguments in function-call harness).
1 parent f55ab5d commit 9bfb0dd

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/goto-harness/memory_snapshot_harness_generator.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,46 @@ void memory_snapshot_harness_generatort::handle_option(
3434
if(recursive_initialization_config.handle_option(option, values))
3535
{
3636
}
37+
else if(option == MEMORY_SNAPSHOT_HARNESS_TREAT_POINTER_AS_ARRAY_OPT)
38+
{
39+
recursive_initialization_config.pointers_to_treat_as_arrays.insert(
40+
values.begin(), values.end());
41+
}
42+
else if(option == MEMORY_SNAPSHOT_HARNESS_ASSOCIATED_ARRAY_SIZE_OPT)
43+
{
44+
for(auto const &array_size_pair : values)
45+
{
46+
try
47+
{
48+
std::string array;
49+
std::string size;
50+
split_string(array_size_pair, ':', array, size);
51+
// --associated-array-size implies --treat-pointer-as-array
52+
// but it is not an error to specify both, so we don't check
53+
// for duplicates here
54+
recursive_initialization_config.pointers_to_treat_as_arrays.insert(
55+
array);
56+
auto const inserted =
57+
recursive_initialization_config
58+
.array_name_to_associated_array_size_variable.emplace(array, size);
59+
if(!inserted.second)
60+
{
61+
throw invalid_command_line_argument_exceptiont{
62+
"can not have two associated array sizes for one array",
63+
"--" MEMORY_SNAPSHOT_HARNESS_ASSOCIATED_ARRAY_SIZE_OPT};
64+
}
65+
}
66+
catch(const deserialization_exceptiont &)
67+
{
68+
throw invalid_command_line_argument_exceptiont{
69+
"`" + array_size_pair +
70+
"' is in an invalid format for array size pair",
71+
"--" MEMORY_SNAPSHOT_HARNESS_ASSOCIATED_ARRAY_SIZE_OPT,
72+
"array_name:size_name, where both are the names of global "
73+
"variables"};
74+
}
75+
}
76+
}
3777
else if(option == MEMORY_SNAPSHOT_HARNESS_SNAPSHOT_OPT)
3878
{
3979
memory_snapshot_file = require_exactly_one_value(option, values);

src/goto-harness/memory_snapshot_harness_generator_options.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ Author: Diffblue Ltd.
1414
#define MEMORY_SNAPSHOT_HARNESS_SNAPSHOT_OPT "memory-snapshot"
1515
#define MEMORY_SNAPSHOT_HARNESS_INITIAL_LOCATION_OPT "initial-location"
1616
#define MEMORY_SNAPSHOT_HARNESS_HAVOC_VARIABLES_OPT "havoc-variables"
17+
#define MEMORY_SNAPSHOT_HARNESS_TREAT_POINTER_AS_ARRAY_OPT "pointer-as-array"
18+
#define MEMORY_SNAPSHOT_HARNESS_ASSOCIATED_ARRAY_SIZE_OPT "size-of-array"
1719

1820
// clang-format off
1921
#define MEMORY_SNAPSHOT_HARNESS_GENERATOR_OPTIONS \
2022
"(" MEMORY_SNAPSHOT_HARNESS_SNAPSHOT_OPT "):" \
2123
"(" MEMORY_SNAPSHOT_HARNESS_INITIAL_LOCATION_OPT "):" \
2224
"(" MEMORY_SNAPSHOT_HARNESS_HAVOC_VARIABLES_OPT "):" \
25+
"(" MEMORY_SNAPSHOT_HARNESS_TREAT_POINTER_AS_ARRAY_OPT "):" \
26+
"(" MEMORY_SNAPSHOT_HARNESS_ASSOCIATED_ARRAY_SIZE_OPT "):" \
2327
// MEMORY_SNAPSHOT_HARNESS_GENERATOR_OPTIONS
2428

2529
// clang-format on
@@ -37,6 +41,16 @@ Author: Diffblue Ltd.
3741
" variables from `vars' to\n" \
3842
" non-deterministic values\n" \
3943
COMMON_HARNESS_GENERATOR_HELP \
44+
"--" MEMORY_SNAPSHOT_HARNESS_TREAT_POINTER_AS_ARRAY_OPT \
45+
" p treat the global pointer with the name `p' as\n" \
46+
" an array\n" \
47+
"--" MEMORY_SNAPSHOT_HARNESS_ASSOCIATED_ARRAY_SIZE_OPT \
48+
" array_name:size_name\n" \
49+
" set the parameter <size_name> to the size" \
50+
" of\n the array <array_name>\n" \
51+
" (implies " \
52+
"-- " MEMORY_SNAPSHOT_HARNESS_TREAT_POINTER_AS_ARRAY_OPT \
53+
" <array_name>)\n" \
4054
// MEMORY_SNAPSHOT_HARNESS_GENERATOR_HELP
4155

4256
// clang-format on

0 commit comments

Comments
 (0)