28template <
typename Handler,
typename GotoFunctionT>
31 using targett =
decltype(goto_function.body.instructions.begin());
34 [](targett target) {
return target->is_function_call(); },
72 std::unordered_set<symbol_exprt, irep_hash>
candidates;
90 std::string correct_format)
92 correct_format(
std::move(correct_format))
100 res +=
"Invalid restriction";
122 " not found in the symbol table"};
130 auto const &function_type =
132 if(function_type.id() !=
ID_code)
163 type2c(function_type, ns) +
"', but restriction `" +
177 options, goto_model, message_handler);
252 const std::string &option,
271 "' was specified twice"};
289 const std::list<std::string> &filenames,
295 for(
auto const &filename : filenames)
332 std::optional<source_locationt> location;
333 for(
const auto &instruction : it->second.body.instructions)
337 instruction.labels.begin(), instruction.labels.end(), label) !=
338 instruction.labels.end())
340 location = instruction.source_location();
344 instruction.is_function_call() &&
346 location.has_value() && instruction.source_location() == *location)
361 "pointers should be identifiers or <function_name>.<label>"};
370 const std::string &option,
377 "the format for restrictions is "
378 "<pointer_name>/<target[,more_targets]*>";
390 "couldn't find names of targets after '/' in `" +
restriction_opt +
"'",
410 "missing target list for function pointer restriction " +
pointer_name,
422 "leading or trailing comma in restrictions for `" +
pointer_name +
"'",
430std::optional<function_pointer_restrictionst::restrictiont>
438 const exprt &function = location->call_function();
455 "called function pointer must have been assigned at the previous location");
466 return std::optional<function_pointer_restrictionst::restrictiont>(
541 if(!
json.is_object())
553 throw deserialization_exceptiont{
"Value of " + restriction.first +
563 if(!array_element.is_string())
565 throw deserialization_exceptiont{
566 "Value of " + restriction.first +
567 "contains a non-string array element"};
569 return irep_idt{to_json_string(array_element).value};
579 const std::string &filename,
583 auto inFile = std::ifstream{filename};
589 "failed to read function pointer restrictions from " + filename};
615 const std::string &filename)
const
619 auto outFile = std::ofstream{filename};
624 " for writing function pointer restrictions"};
648 const auto restriction = get_by_name_restriction(
649 goto_function.second, by_name_restrictions, it);
653 restrictions.insert(*restriction);
virtual void output(const namespacet &ns, const irep_idt &function_id, const goto_programt &goto_program, std::ostream &out) const
Output the abstract states for a single function.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
virtual bool isset(char option) const
const std::list< std::string > & get_values(const std::string &option) const
Base class for exceptions thrown in the cprover project.
std::string reason
The reason this exception was generated.
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.
Base class for all expressions.
static function_pointer_restrictionst from_options(const optionst &options, const goto_modelt &goto_model, message_handlert &message_handler)
Parse function pointer restrictions from command line.
static restrictionst parse_function_pointer_restrictions_from_command_line(const std::list< std::string > &restriction_opts, const goto_modelt &goto_model)
static restrictionst get_function_pointer_by_name_restrictions(const std::list< std::string > &restriction_name_opts, const goto_modelt &goto_model)
Get function pointer restrictions from restrictions with named pointers.
const restrictionst restrictions
static restrictionst parse_function_pointer_restrictions(const std::list< std::string > &restriction_opts, const std::string &option, const goto_modelt &goto_model)
static restrictionst merge_function_pointer_restrictions(restrictionst lhs, const restrictionst &rhs)
static restrictiont parse_function_pointer_restriction(const std::string &restriction_opt, const std::string &option, const goto_modelt &goto_model)
static function_pointer_restrictionst read_from_file(const std::string &filename, const goto_modelt &goto_model, message_handlert &message_handler)
restrictionst::value_type restrictiont
std::unordered_map< irep_idt, std::unordered_set< irep_idt > > restrictionst
static restrictionst parse_function_pointer_restrictions_from_file(const std::list< std::string > &filenames, const goto_modelt &goto_model, message_handlert &message_handler)
void write_to_file(const std::string &filename) const
static void typecheck_function_pointer_restrictions(const goto_modelt &goto_model, const restrictionst &restrictions)
static function_pointer_restrictionst from_json(const jsont &json, const goto_modelt &goto_model)
static std::optional< restrictiont > get_by_name_restriction(const goto_functiont &goto_function, const function_pointer_restrictionst::restrictionst &by_name_restrictions, const goto_programt::const_targett &location)
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.
A generic container class for the GOTO intermediate representation of one function.
void update()
Update all indices.
instructionst::iterator targett
instructionst::const_iterator const_targett
Thrown when users pass incorrect command line arguments, for example passing no files to analysis or ...
std::string correct_format
invalid_restriction_exceptiont(std::string reason, std::string correct_format="")
std::string what() const override
A human readable description of what went wrong.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
void set_option(const std::string &option, const bool value)
const value_listt & get_list_option(const std::string &option) const
const symbolt * lookup(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
Thrown when some external system fails unexpectedly.
std::string type2c(const typet &type, const namespacet &ns, const expr2c_configurationt &configuration)
void for_each_instruction_if(GotoFunctionT &&goto_function, PredicateT predicate, HandlerT handler)
const std::string & id2string(const irep_idt &d)
json_objectt & to_json_object(jsont &json)
json_arrayt & to_json_array(jsont &json)
bool parse_json(std::istream &in, const std::string &filename, message_handlert &message_handler, jsont &dest)
API to expression classes for Pointers.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
static void json(json_objectT &result, const irep_idt &property_id, const property_infot &property_info)
void remove_function_pointer(message_handlert &message_handler, symbol_tablet &symbol_table, goto_programt &goto_program, const irep_idt &function_id, goto_programt::targett target, const std::unordered_set< symbol_exprt, irep_hash > &functions)
Replace a call to a dynamic function at location target in the given goto-program by a case-split ove...
bool function_is_type_compatible(bool return_value_used, const code_typet &call_type, const code_typet &function_type, const namespacet &ns)
Returns true iff call_type can be converted to produce a function call of the same type as function_t...
Remove Indirect Function Calls.
static std::string resolve_pointer_name(const std::string &candidate, const goto_modelt &goto_model)
Parse candidate to distinguish whether it refers to a function pointer symbol directly (as produced b...
void parse_function_pointer_restriction_options_from_cmdline(const cmdlinet &cmdline, optionst &options)
void restrict_function_pointers(message_handlert &message_handler, goto_modelt &goto_model, const optionst &options)
Apply function pointer restrictions to a goto_model.
Given goto functions and a list of function parameters or globals that are function pointers with lis...
#define RESTRICT_FUNCTION_POINTER_OPT
#define RESTRICT_FUNCTION_POINTER_FROM_FILE_OPT
#define RESTRICT_FUNCTION_POINTER_BY_NAME_OPT
#define PRECONDITION(CONDITION)
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
void split_string(const std::string &s, char delim, std::vector< std::string > &result, bool strip, bool remove_empty)