Skip to content

Commit e2598d2

Browse files
Petr BauchPetr Bauch
authored andcommitted
Modify the user option to take file name as well
To prevent the line number occurring in multiple files and us choosing the wrong initial instruction.
1 parent 1f0d7e9 commit e2598d2

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

regression/goto-harness/havoc-global-int-03/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
--harness-type initialise-with-memory-snapshot --memory-snapshot ../load-snapshot-json-snapshots/global-int-x-1-snapshot.json --initial-line 6 --havoc-variables x
3+
--harness-type initialise-with-memory-snapshot --memory-snapshot ../load-snapshot-json-snapshots/global-int-x-1-snapshot.json --initial-file-line main.c:6 --havoc-variables x
44
^EXIT=10$
55
^SIGNAL=0$
66
\[main.assertion.1\] line [0-9]+ assertion x == 1: SUCCESS

src/goto-harness/memory_snapshot_harness_generator.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,23 @@ void memory_snapshot_harness_generatort::handle_option(
6363
{
6464
variables_to_havoc.insert(values.begin(), values.end());
6565
}
66-
else if(option == "initial-line")
66+
else if(option == "initial-file-line")
6767
{
68-
const std::string initial_line = require_exactly_one_value(option, values);
69-
line_number = optionalt<unsigned>(safe_string2unsigned(initial_line));
68+
const std::string initial_file_line =
69+
require_exactly_one_value(option, values);
70+
71+
std::vector<std::string> start;
72+
split_string(initial_file_line, ':', start, true);
73+
74+
if(start.size() != 2 || start.front().empty() || start.back().empty())
75+
{
76+
throw invalid_command_line_argument_exceptiont(
77+
"invalid initial location specification", "--initial-file-line");
78+
}
79+
80+
initial_file_name = start.front();
81+
initial_line_number =
82+
optionalt<unsigned>(safe_string2unsigned(start.back()));
7083
}
7184
else
7285
{
@@ -81,7 +94,7 @@ memory_snapshot_harness_generatort::get_start_instruction(
8194
const goto_modelt &goto_model)
8295
{
8396
const auto &goto_functions = goto_model.goto_functions;
84-
if(line_number.has_value())
97+
if(initial_line_number.has_value())
8598
{
8699
// by line: iterate over all instructions until source location match
87100
for(const auto &entry : goto_functions.function_map)
@@ -96,8 +109,10 @@ memory_snapshot_harness_generatort::get_start_instruction(
96109
goto_program.instructions.begin(),
97110
goto_program.instructions.end(),
98111
[this](const goto_programt::instructiont &instruction) {
99-
return safe_string2unsigned(id2string(
100-
instruction.source_location.get_line())) >= *line_number;
112+
return instruction.source_location.get_file() == initial_file_name &&
113+
safe_string2unsigned(
114+
id2string(instruction.source_location.get_line())) >=
115+
*initial_line_number;
101116
});
102117

103118
if(it != goto_program.instructions.end())

src/goto-harness/memory_snapshot_harness_generator.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Author: Daniel Poetzl
2323
#define MEMORY_SNAPSHOT_HARNESS_GENERATOR_OPTIONS \
2424
"(memory-snapshot):" \
2525
"(initial-location):" \
26-
"(initial-line):" \
26+
"(initial-file-line):" \
2727
"(havoc-variables):" // MEMORY_SNAPSHOT_HARNESS_GENERATOR_OPTIONS
2828
// clang-format on
2929

@@ -35,7 +35,7 @@ Author: Daniel Poetzl
3535
"--initial-location <func[:<n>]>\n" \
3636
" use given function and location number as " \
3737
"entry\n point\n" \
38-
"--initial-line <n> use given line as entry point\n" \
38+
"--initial-file-line <file:n> use given file and line as entry point\n" \
3939
"--havoc-variables vars initialise variables from vars to\n" \
4040
" non-deterministic values" \
4141
// MEMORY_SNAPSHOT_HARNESS_GENERATOR_HELP
@@ -156,7 +156,9 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
156156
irep_idt entry_function_name;
157157
optionalt<unsigned> location_number;
158158
std::unordered_set<irep_idt> variables_to_havoc;
159-
optionalt<unsigned> line_number;
159+
irep_idt initial_file_name;
160+
optionalt<unsigned> initial_line_number;
161+
160162
optionalt<goto_programt::const_targett> start_instruction;
161163

162164
symbol_exprt func_init_done_var;

0 commit comments

Comments
 (0)