30 const std::string &option,
31 const std::list<std::string> &values)
42 values.begin(), values.end());
46 for(
auto const &array_size_pair : values)
64 "can not have two associated array sizes for one array",
71 "'" + array_size_pair +
72 "' is in an invalid format for array size pair",
74 "array_name:size_name, where both are the names of global "
89 std::vector<std::string> havoc_candidates =
91 for(
const auto &candidate : havoc_candidates)
103 "unrecognized option for memory snapshot harness generator",
114 "option --memory_snapshot is required",
115 "--harness-type initialize-with-memory-snapshot");
121 "choose either source or goto location to specify the entry point",
122 "--initial-source/goto-location");
140 const symbolt *called_function_symbol =
143 if(called_function_symbol ==
nullptr)
147 "` not found in the symbol table",
148 "--initial-location");
184 const symbolt &snapshot_symbol,
188 snapshot_symbol.
type,
192 snapshot_symbol.
mode,
202 if(t.
id() != ID_pointer)
215 std::vector<std::pair<irep_idt, symbolt>> ordered_snapshot_symbols;
220 std::vector<std::pair<irep_idt, symbolt>> selected_snapshot_symbols;
222 relationt reference_relation;
224 for(
const auto &snapshot_pair : snapshot)
226 const auto name =
id2string(snapshot_pair.first);
230 snapshot_pair.second.value,
231 [&reference_relation, &snapshot_pair](
const irep_idt &
id) {
232 reference_relation.insert(std::make_pair(snapshot_pair.first, id));
234 selected_snapshot_symbols.push_back(snapshot_pair);
238 reference_order.
sort(selected_snapshot_symbols, ordered_snapshot_symbols);
246 const auto &global_symbol = pair.second;
249 auto symeexr = global_symbol.symbol_expr();
250 if(symeexr.type() == global_symbol.value.type())
255 for(
const auto &pair : ordered_snapshot_symbols)
257 const symbolt &snapshot_symbol = pair.second;
260 auto should_get_fresh = [&symbol_table](
const symbolt &symbol) {
261 return symbol_table.
lookup(symbol.base_name) ==
nullptr &&
264 const symbolt &fresh_or_snapshot_symbol =
265 should_get_fresh(snapshot_symbol)
270 fresh_or_snapshot_symbol))
276 fresh_or_snapshot_symbol.
value});
280 recursive_initialization.initialize(
290 const symbolt &called_function_symbol,
304 std::move(arguments)});
320 goto_functiont &harness_function = function_iterator_pair.first->second;
328 const std::string &file,
345 for(
auto const &arr_element : jarr)
347 if(!arr_element.is_object())
350 const auto it = json_obj.find(
"symbolTable");
351 if(it != json_obj.end())
358 "JSON memory snapshot does not contain symbol table");
371 const irep_idt &harness_function_name)
379 const symbolt *called_function_symbol =
390 called_function_symbol->
mode,
392 func_init_done_symbol.is_static_lifetime =
true;
394 symbol_exprt func_init_done_var = func_init_done_symbol.symbol_expr();
404 *called_function_symbol, harness_function_body);
408 symbolt harness_function_symbol{
409 harness_function_name,
411 called_function_symbol->
mode};
412 harness_function_symbol.base_name = harness_function_name;
413 harness_function_symbol.pretty_name = harness_function_name;
414 harness_function_symbol.is_lvalue =
true;
415 harness_function_symbol.value = harness_function_body;
425 const std::string &cmdl_option)
427 std::vector<std::string> start =
split_string(cmdl_option,
':',
true);
430 start.empty() || start.front().empty() ||
431 (start.size() == 2 && start.back().empty()) || start.size() > 2)
434 "invalid initial location specification",
"--initial-location");
437 if(start.size() == 2)
451 const std::string &cmdl_option)
453 std::string initial_file_string;
454 std::string initial_line_string;
456 cmdl_option,
':', initial_file_string, initial_line_string,
true);
458 if(initial_file_string.empty() || initial_line_string.empty())
461 "invalid initial location specification",
"--initial-file-line");
479 const auto &goto_function =
483 goto_function->second.body_available())
485 const auto &goto_program = goto_function->second.body;
487 const auto corresponding_instruction =
489 goto_program.instructions);
491 if(corresponding_instruction != goto_program.instructions.end())
495 "could not find the specified entry point",
"--initial-goto-location");
509 const auto &goto_function = entry.second;
511 const auto &goto_program = goto_function.body;
513 const auto candidate_instruction =
515 goto_program.instructions);
517 if(candidate_instruction.first != goto_program.instructions.end())
520 candidate_instruction.second, entry.first, candidate_instruction.first);
528 "could not find the specified entry point",
"--initial-source-location");
535 if(!location_number.has_value())
536 return instructions.begin();
539 instructions.begin(),
542 return *location_number == instruction.location_number;
546 std::pair<goto_programt::const_targett, size_t>
551 auto it = std::find_if(
552 instructions.begin(),
555 return instruction.source_location().get_file() == file_name &&
556 safe_string2unsigned(id2string(
557 instruction.source_location().get_line())) >= line_number;
560 if(it == instructions.end())
A goto_instruction_codet representing an assignment in the program.
A codet representing sequential composition of program statements.
void add(const codet &code)
goto_instruction_codet representation of a function call statement.
exprt::operandst argumentst
const parameterst & parameters() const
Thrown when failing to deserialize a value from some low level format, like JSON or raw bytes.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
typet & type()
Return the type of the expression.
The Boolean constant false.
A collection of goto functions.
function_mapt function_map
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
symbol_tablet symbol_table
Symbol table.
goto_functionst goto_functions
GOTO functions.
This class represents an instruction in the GOTO intermediate representation.
A generic container class for the GOTO intermediate representation of one function.
instructionst instructions
The list of instructions in the goto program.
targett const_cast_target(const_targett t)
Convert a const_targett to a targett - use with care and avoid whenever possible.
static instructiont make_end_function(const source_locationt &l=source_locationt::nil())
instructionst::const_iterator const_targett
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
std::list< instructiont > instructionst
targett insert_after(const_targett target)
Insertion after the instruction pointed-to by the given instruction iterator target.
void compute_location_numbers(unsigned &nr)
Compute location numbers.
targett add(instructiont &&instruction)
Adds a given instruction at the end.
static instructiont make_goto(targett _target, const source_locationt &l=source_locationt::nil())
targett insert_before(const_targett target)
Insertion before the instruction pointed-to by the given instruction iterator target.
Thrown when users pass incorrect command line arguments, for example passing no files to analysis or ...
const irep_idt & id() const
void add_init_section(const symbol_exprt &func_init_done_var, goto_modelt &goto_model) const
Modify the entry-point function to start from the user-specified initial location.
entry_locationt entry_location
data to initialize the entry function
void insert_harness_function_into_goto_model(goto_modelt &goto_model, const symbolt &function) const
Insert the function into the symbol table (and the goto functions map) of the goto_model.
const symbolt & fresh_symbol_copy(const symbolt &snapshot_symbol, symbol_table_baset &symbol_table) const
Introduce a new symbol into symbol_table with the same name and type as snapshot_symbol.
entry_locationt initialize_entry_via_goto(const entry_goto_locationt &entry_goto_location, const goto_functionst &goto_functions)
Find and return the entry instruction (requested by the user as goto location: function name + locati...
entry_source_locationt parse_source_location(const std::string &cmdl_option)
Parse a command line option to extract the user specified entry source location.
entry_locationt initialize_entry_via_source(const entry_source_locationt &entry_source_location, const goto_functionst &goto_functions)
Find and return the entry instruction (requested by the user as source location: file name + line num...
code_blockt add_assignments_to_globals(const symbol_table_baset &snapshot, goto_modelt &goto_model) const
For each global symbol in the snapshot symbol table either: 1) add code_assignt assigning a value fro...
message_handlert & message_handler
void handle_option(const std::string &option, const std::list< std::string > &values) override
Collect the memory-snapshot specific cmdline options (one at a time)
entry_goto_locationt parse_goto_location(const std::string &cmdl_option)
Parse a command line option to extract the user specified entry goto location.
void collect_references(const exprt &expr, Adder &&add_reference) const
void generate(goto_modelt &goto_model, const irep_idt &harness_function_name) override
The main function of this harness, consists of the following:
void add_call_with_nondet_arguments(const symbolt &called_function_symbol, code_blockt &code) const
Create as many non-deterministic arguments as there are arguments of the called_function_symbol and a...
recursive_initialization_configt recursive_initialization_config
std::string initial_goto_location_line
void get_memory_snapshot(const std::string &file, symbol_table_baset &snapshot) const
Parse the snapshot JSON file and initialise the symbol table.
std::string initial_source_location_line
void validate_options(const goto_modelt &goto_model) override
Check that user options make sense: On their own, e.g.
std::string memory_snapshot_file
data to store the command-line options
std::unordered_set< irep_idt > variables_to_havoc
size_t pointer_depth(const typet &t) const
Recursively compute the pointer depth.
Class for generating initialisation code for compound structures.
static bool is_initialization_allowed(const symbolt &symbol)
A side_effect_exprt that returns a non-deterministically chosen value.
static const source_locationt & nil()
Expression to hold a symbol (variable)
The symbol table base class interface.
const symbolt * lookup(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
virtual std::pair< symbolt &, bool > insert(symbolt symbol) override
Author: Diffblue Ltd.
irep_idt base_name
Base (non-scoped) name.
source_locationt location
Source code location of definition of symbol.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
typet type
Type of symbol.
exprt value
Initial value of symbol.
irep_idt mode
Language mode.
The Boolean constant true.
The type of an expression, extends irept.
symbolt & get_fresh_aux_symbol(const typet &type, const std::string &name_prefix, const std::string &basename_prefix, const source_locationt &source_location, const irep_idt &symbol_mode, const namespacet &ns, symbol_table_baset &symbol_table)
Installs a fresh-named symbol with respect to the given namespace ns with the requested name pattern ...
Fresh auxiliary symbol creation.
void goto_convert(const codet &code, symbol_table_baset &symbol_table, goto_programt &dest, message_handlert &message_handler, const irep_idt &mode)
Goto Programs with Functions.
const std::string & id2string(const irep_idt &d)
json_arrayt & to_json_array(jsont &json)
json_objectt & to_json_object(jsont &json)
bool parse_json(std::istream &in, const std::string &filename, message_handlert &message_handler, jsont &dest)
void symbol_table_from_json(const jsont &in, symbol_table_baset &symbol_table)
#define MEMORY_SNAPSHOT_HARNESS_INITIAL_SOURCE_LOC_OPT
#define MEMORY_SNAPSHOT_HARNESS_HAVOC_VARIABLES_OPT
#define MEMORY_SNAPSHOT_HARNESS_ASSOCIATED_ARRAY_SIZE_OPT
#define MEMORY_SNAPSHOT_HARNESS_SNAPSHOT_OPT
#define MEMORY_SNAPSHOT_HARNESS_TREAT_POINTER_AS_ARRAY_OPT
#define MEMORY_SNAPSHOT_HARNESS_INITIAL_GOTO_LOC_OPT
std::string require_exactly_one_value(const std::string &option, const std::list< std::string > &values)
Returns the only value of a single element list, throws an exception if not passed a single element l...
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
static void json(json_objectT &result, const irep_idt &property_id, const property_infot &property_info)
#define CHECK_RETURN(CONDITION)
#define PRECONDITION(CONDITION)
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
std::optional< unsigned > string2optional_unsigned(const std::string &str, int base)
Convert string to unsigned similar to the stoul or stoull functions, return nullopt when the conversi...
unsigned safe_string2unsigned(const std::string &str, int base)
void split_string(const std::string &s, char delim, std::vector< std::string > &result, bool strip, bool remove_empty)
User provided goto location: function name and (maybe) location number; the structure wraps this opti...
goto_programt::const_targett find_first_corresponding_instruction(const goto_programt::instructionst &instructions) const
Returns the first goto_programt::instructiont represented by this goto location, i....
Wraps the information needed to identify the entry point.
goto_programt::const_targett start_instruction
User provided source location: file name and line number; the structure wraps this option with a pars...
std::pair< goto_programt::const_targett, size_t > find_first_corresponding_instruction(const goto_programt::instructionst &instructions) const
Returns the first goto_programt::instructiont represented by this source location,...
Simple structure for linearising posets.
void sort(const std::vector< std::pair< Key, T >> &input, std::vector< std::pair< Key, T >> &output)
std::multimap< Key, Key > relationt
Wraps the information for source location match candidates.
void match_up(const size_t &candidate_distance, const irep_idt &candidate_function_name, const goto_programt::const_targett &candidate_instruction)
goto_programt::const_targett instruction
std::map< irep_idt, irep_idt > array_name_to_associated_array_size_variable
bool handle_option(const std::string &option, const std::list< std::string > &values)
Parse the options specific for recursive initialisation.
std::set< irep_idt > pointers_to_treat_as_arrays