Skip to content

Commit 0249ba0

Browse files
Petr BauchPetr Bauch
Petr Bauch
authored and
Petr Bauch
committed
Reflect the existence of wrappers
Most of the sanity checks are in the wrappers and the `get_target` function is now redundant.
1 parent 6643eb4 commit 0249ba0

File tree

3 files changed

+42
-101
lines changed

3 files changed

+42
-101
lines changed

src/goto-harness/memory_snapshot_harness_generator.cpp

Lines changed: 35 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -66,106 +66,51 @@ void memory_snapshot_harness_generatort::validate_options(
6666
"--harness-type initialise-from-memory-snapshot");
6767
}
6868

69-
if(entry_function_name.empty())
69+
if(initial_source_location_line.empty() == initial_goto_location_line.empty())
7070
{
71-
INVARIANT(
72-
!location_number.has_value(),
73-
"when `function` is empty then the option --initial-location was not "
74-
"given and thus `location_number` was not set");
75-
7671
throw invalid_command_line_argument_exceptiont(
77-
"option --initial-location is required",
78-
"--harness-type initialise-from-memory-snapshot");
72+
"choose either source or goto location to specify the entry point",
73+
"--initial-source/goto-location");
7974
}
8075

81-
const auto &goto_functions = goto_model.goto_functions;
82-
const auto &goto_function =
83-
goto_functions.function_map.find(entry_function_name);
84-
if(goto_function == goto_functions.function_map.end())
76+
if(!initial_source_location_line.empty())
8577
{
86-
throw invalid_command_line_argument_exceptiont(
87-
"unknown initial location specification", "--initial-location");
78+
entry_location = initialize_entry_via_source(
79+
parse_source_location(initial_source_location_line),
80+
goto_model.goto_functions);
8881
}
89-
90-
if(!goto_function->second.body_available())
91-
{
92-
throw invalid_command_line_argument_exceptiont(
93-
"given function `" + id2string(entry_function_name) +
94-
"` does not have a body",
95-
"--initial-location");
96-
}
97-
98-
if(location_number.has_value())
99-
{
100-
const auto &goto_program = goto_function->second.body;
101-
const auto opt_it = goto_program.get_target(*location_number);
102-
103-
if(!opt_it.has_value())
104-
{
105-
throw invalid_command_line_argument_exceptiont(
106-
"no instruction with location number " +
107-
std::to_string(*location_number) + " in function " +
108-
id2string(entry_function_name),
109-
"--initial-location");
110-
}
111-
}
112-
113-
if(goto_functions.function_map.count(INITIALIZE_FUNCTION) == 0)
82+
else
11483
{
115-
throw invalid_command_line_argument_exceptiont(
116-
"invalid input program: " + std::string(INITIALIZE_FUNCTION) +
117-
" not found",
118-
"<in>");
84+
entry_location = initialize_entry_via_goto(
85+
parse_goto_location(initial_goto_location_line),
86+
goto_model.goto_functions);
11987
}
12088

12189
const symbol_tablet &symbol_table = goto_model.symbol_table;
90+
12291
const symbolt *called_function_symbol =
123-
symbol_table.lookup(entry_function_name);
92+
symbol_table.lookup(entry_location.function_name);
12493

12594
if(called_function_symbol == nullptr)
12695
{
12796
throw invalid_command_line_argument_exceptiont(
128-
"function `" + id2string(entry_function_name) +
97+
"function `" + id2string(entry_location.function_name) +
12998
"` not found in the symbol table",
13099
"--initial-location");
131100
}
132101
}
133102

134103
void memory_snapshot_harness_generatort::add_init_section(
104+
const symbol_exprt &func_init_done_var,
135105
goto_modelt &goto_model) const
136106
{
137107
goto_functionst &goto_functions = goto_model.goto_functions;
138-
symbol_tablet &symbol_table = goto_model.symbol_table;
139108

140109
goto_functiont &goto_function =
141-
goto_functions.function_map[entry_function_name];
142-
const symbolt &function_symbol = symbol_table.lookup_ref(entry_function_name);
110+
goto_functions.function_map[entry_location.function_name];
143111

144112
goto_programt &goto_program = goto_function.body;
145113

146-
// introduce a symbol for a Boolean variable to indicate the point at which
147-
// the function initialisation is completed
148-
symbolt &func_init_done_symbol = get_fresh_aux_symbol(
149-
bool_typet(),
150-
id2string(entry_function_name),
151-
"func_init_done",
152-
function_symbol.location,
153-
function_symbol.mode,
154-
symbol_table);
155-
func_init_done_symbol.is_static_lifetime = true;
156-
func_init_done_symbol.value = false_exprt();
157-
158-
const symbol_exprt func_init_done_var = func_init_done_symbol.symbol_expr();
159-
160-
// initialise func_init_done_var in __CPROVER_initialize if it is present
161-
// so that it's FALSE value is visible before the harnessed function is called
162-
goto_programt &cprover_initialize =
163-
goto_functions.function_map.find(INITIALIZE_FUNCTION)->second.body;
164-
cprover_initialize.insert_before(
165-
std::prev(cprover_initialize.instructions.end()),
166-
goto_programt::make_assignment(
167-
code_assignt(func_init_done_var, false_exprt())));
168-
169114
const goto_programt::const_targett start_it =
170115
goto_program.instructions.begin();
171116

@@ -182,9 +127,8 @@ void memory_snapshot_harness_generatort::add_init_section(
182127
goto_program.compute_location_numbers();
183128
goto_program.insert_after(
184129
ins_it2,
185-
goto_programt::make_goto(goto_program.const_cast_target(
186-
location_number.has_value() ? *goto_program.get_target(*location_number)
187-
: start_it)));
130+
goto_programt::make_goto(
131+
goto_program.const_cast_target(entry_location.start_instruction)));
188132
}
189133

190134
code_blockt memory_snapshot_harness_generatort::add_assignments_to_globals(
@@ -310,13 +254,28 @@ void memory_snapshot_harness_generatort::generate(
310254
goto_functionst &goto_functions = goto_model.goto_functions;
311255

312256
const symbolt *called_function_symbol =
313-
symbol_table.lookup(entry_function_name);
257+
symbol_table.lookup(entry_location.function_name);
258+
259+
// introduce a symbol for a Boolean variable to indicate the point at which
260+
// the function initialisation is completed
261+
auto &func_init_done_symbol = get_fresh_aux_symbol(
262+
bool_typet(),
263+
id2string(entry_location.function_name),
264+
"func_init_done",
265+
source_locationt::nil(),
266+
called_function_symbol->mode,
267+
symbol_table);
268+
func_init_done_symbol.is_static_lifetime = true;
269+
func_init_done_symbol.value = false_exprt();
270+
symbol_exprt func_init_done_var = func_init_done_symbol.symbol_expr();
314271

315-
add_init_section(goto_model);
272+
add_init_section(func_init_done_var, goto_model);
316273

317274
code_blockt harness_function_body =
318275
add_assignments_to_globals(snapshot, goto_model);
319276

277+
harness_function_body.add(code_assignt{func_init_done_var, false_exprt{}});
278+
320279
add_call_with_nondet_arguments(
321280
*called_function_symbol, harness_function_body);
322281

src/goto-harness/memory_snapshot_harness_generator.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
9999

100100
/// Parse a command line option to extract the user specified entry goto
101101
/// location
102-
/// \param cmdl_option: a string of the format <func[:<n>]>
102+
/// \param cmdl_option: a string of the format `name:number`
103103
/// \return correctly constructed entry goto location
104104
entry_goto_locationt parse_goto_location(const std::string &cmdl_option);
105105

@@ -126,7 +126,7 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
126126

127127
/// Parse a command line option to extract the user specified entry source
128128
/// location
129-
/// \param cmdl_option: a string of the format <file:n>
129+
/// \param cmdl_option: a string of the format `name:number`
130130
/// \return correctly constructed entry source location
131131
entry_source_locationt parse_source_location(const std::string &cmdl_option);
132132

@@ -214,8 +214,12 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
214214
/// ..second_part..
215215
/// }
216216
///
217+
/// \param func_init_done_var: symbol expression for the `func_init_done`
218+
/// variable
217219
/// \param goto_model: Model where the modification takes place
218-
void add_init_section(goto_modelt &goto_model) const;
220+
void add_init_section(
221+
const symbol_exprt &func_init_done_var,
222+
goto_modelt &goto_model) const;
219223

220224
/// For each global symbol in the \p snapshot symbol table either:
221225
/// 1) add \ref code_assignt assigning a value from the \p snapshot to the

src/goto-programs/goto_program.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -588,28 +588,6 @@ class goto_programt
588588
return t;
589589
}
590590

591-
optionalt<const_targett> get_target(const unsigned location_number) const
592-
{
593-
PRECONDITION(!instructions.empty());
594-
595-
const unsigned start_location_number = instructions.front().location_number;
596-
597-
if(
598-
location_number < start_location_number ||
599-
location_number > instructions.back().location_number)
600-
{
601-
return nullopt;
602-
}
603-
604-
auto location_target =
605-
std::next(instructions.begin(), location_number - start_location_number);
606-
607-
// location numbers are contiguous unless new instructions are inserted
608-
// here we check that nobody inserted any instruction into our function
609-
CHECK_RETURN(location_target->location_number == location_number);
610-
return location_target;
611-
}
612-
613591
template <typename Target>
614592
std::list<Target> get_successors(Target target) const;
615593

0 commit comments

Comments
 (0)