Go to the documentation of this file.
37 bool _add_safety_assertion,
94 bool return_value_used,
99 const typet &call_type,
100 const typet &function_type);
112 bool _add_safety_assertion,
113 bool only_resolve_const_fps,
115 : log(_message_handler),
117 symbol_table(_symbol_table),
118 add_safety_assertion(_add_safety_assertion),
119 only_resolve_const_fps(only_resolve_const_fps)
128 type_map.emplace(f_it->first, f_it->second.type);
132 const typet &call_type,
133 const typet &function_type)
135 if(call_type == function_type)
140 call_type.
id() == ID_signedbv || call_type.
id() == ID_unsigned ||
141 call_type.
id() == ID_bool || call_type.
id() == ID_c_bool ||
142 call_type.
id() == ID_c_enum_tag || call_type.
id() == ID_c_enum ||
143 call_type.
id() == ID_pointer)
145 return function_type.
id() == ID_signedbv ||
146 function_type.
id() == ID_unsigned || function_type.
id() == ID_bool ||
147 function_type.
id() == ID_c_bool ||
148 function_type.
id() == ID_pointer ||
149 function_type.
id() == ID_c_enum ||
150 function_type.
id() == ID_c_enum_tag;
158 bool return_value_used,
164 if(!return_value_used)
183 function_parameters.empty())
188 call_parameters.empty())
195 if(call_parameters.size()!=function_parameters.size())
198 for(std::size_t i=0; i<call_parameters.size(); i++)
200 function_parameters[i].type()))
218 for(std::size_t i=0; i<function_parameters.size(); i++)
220 if(i<call_arguments.size())
222 if(call_arguments[i].type() != function_parameters[i].type())
246 const symbolt &function_symbol =
254 function_symbol.
mode,
260 function_call.
lhs()=tmp_symbol_expr;
288 bool found_functions;
290 const exprt &pointer =
function.pointer();
293 const auto does_remove_const = const_removal_check();
294 if(does_remove_const.first)
297 log.
warning() <<
"cast from const to non-const pointer found, "
298 <<
"only worst case function pointer removal will be done."
300 found_functions=
false;
307 found_functions=fpr(pointer, functions);
315 if(functions.size()==1)
317 auto call = target->get_function_call();
318 call.function() = *functions.cbegin();
319 target->set_function_call(call);
351 if(t.first==
"pthread_mutex_cleanup")
355 functions.insert(expr);
383 for(
const auto &fun : functions)
386 auto new_call = code;
404 const auto casted_address =
416 t->source_location.set_property_class(
"pointer dereference");
417 t->source_location.set_comment(
"invalid function pointer");
431 irep_idt property_class=it->source_location.get_property_class();
433 it->source_location=target->source_location;
434 if(!property_class.
empty())
435 it->source_location.set_property_class(property_class);
437 it->source_location.set_comment(
comment);
449 target->code.
swap(code_expression);
454 log.
statistics() <<
"replacing function pointer by " << functions.size()
460 mstream <<
"targets: ";
463 for(const auto &function : functions)
468 mstream << function.get_identifier();
480 bool did_something=
false;
483 if(target->is_function_call())
497 return did_something;
502 bool did_something=
false;
504 for(goto_functionst::function_mapt::iterator f_it=
525 bool add_safety_assertion,
526 bool only_remove_const_fps)
532 add_safety_assertion,
533 only_remove_const_fps,
543 bool add_safety_assertion,
544 bool only_remove_const_fps)
550 add_safety_assertion,
551 only_remove_const_fps,
559 bool add_safety_assertion,
560 bool only_remove_const_fps)
566 add_safety_assertion,
567 only_remove_const_fps);
Class that provides messages with a built-in verbosity 'level'.
#define Forall_goto_program_instructions(it, program)
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
bool has_ellipsis() const
static exprt conditional_cast(const exprt &expr, const typet &type)
void operator()(goto_functionst &goto_functions)
std::unordered_set< irep_idt > address_taken
#define CHECK_RETURN(CONDITION)
The type of an expression, extends irept.
std::vector< parametert > parameterst
Fresh auxiliary symbol creation.
remove_function_pointerst(message_handlert &_message_handler, symbol_tablet &_symbol_table, bool _add_safety_assertion, bool only_resolve_const_fps, const goto_functionst &goto_functions)
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
void fix_return_type(const irep_idt &in_function_id, code_function_callt &function_call, goto_programt &dest)
remove_const_function_pointerst::functionst functionst
targett add(instructiont &&instruction)
Adds a given instruction at the end.
void compute_location_numbers()
Base class for all expressions.
irep_idt base_name
Base (non-scoped) name.
function_mapt function_map
Expression to hold a symbol (variable)
void fix_argument_types(code_function_callt &function_call)
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
static instructiont make_goto(targett _target, const source_locationt &l=source_locationt::nil())
std::unordered_set< symbol_exprt, irep_hash > functionst
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
static instructiont make_function_call(const code_function_callt &_code, const source_locationt &l=source_locationt::nil())
Create a function call instruction.
bool arg_is_type_compatible(const typet &call_type, const typet &function_type)
typet & type()
Return the type of the expression.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
codet representation of a function call statement.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
void remove_function_pointer(goto_programt &goto_program, const irep_idt &function_id, goto_programt::targett target, const functionst &functions)
Replace a call to a dynamic function at location target in the given goto-program by a case-split ove...
symbol_tablet & symbol_table
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
irep_idt mode
Language mode.
void destructive_insert(const_targett target, goto_programt &p)
Inserts the given program p before target.
const std::string & id2string(const irep_idt &d)
source_locationt source_location
static instructiont make_skip(const source_locationt &l=source_locationt::nil())
const irep_idt & get_identifier() const
optionalt< mp_integer > pointer_offset_bits(const typet &type, const namespacet &ns)
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
pointer_typet pointer_type(const typet &subtype)
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const irep_idt & id() const
exprt::operandst argumentst
The Boolean constant false.
const parameterst & parameters() const
void destructive_append(goto_programt &p)
Appends the given program p to *this. p is destroyed.
A collection of goto functions.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
message_handlert & get_message_handler()
goto_functionst goto_functions
GOTO functions.
void compute_address_taken_functions(const exprt &src, std::unordered_set< irep_idt > &address_taken)
get all functions whose address is taken
const symbolst & symbols
Read-only field, used to look up symbols given their names.
void conditional_output(mstreamt &mstream, const std::function< void(mstreamt &)> &output_generator) const
Generate output to message_stream using output_generator if the configured verbosity is at least as h...
bool only_resolve_const_fps
A generic container class for the GOTO intermediate representation of one function.
bool add_safety_assertion
const typet & return_type() const
#define forall_goto_functions(it, functions)
static instructiont make_assumption(const exprt &g, const source_locationt &l=source_locationt::nil())
#define forall_expr(it, expr)
Operator to return the address of an object.
source_locationt & add_source_location()
bool is_type_compatible(bool return_value_used, const code_typet &call_type, const code_typet &function_type)
Semantic type conversion.
A codet representing an assignment in the program.
The Boolean constant true.
bool remove_function_pointers(message_handlert &_message_handler, symbol_tablet &symbol_table, const goto_functionst &goto_functions, goto_programt &goto_program, const irep_idt &function_id, bool add_safety_assertion, bool only_remove_const_fps)
mstreamt & warning() const
static std::string comment(const rw_set_baset::entryt &entry, bool write)
API to expression classes.
Remove Indirect Function Calls.
const source_locationt & source_location() const
symbol_tablet symbol_table
Symbol table.
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 ...
std::map< irep_idt, code_typet > type_mapt
instructionst::iterator targett
codet representation of an expression statement.
mstreamt & statistics() const
bool remove_function_pointers(goto_programt &goto_program, const irep_idt &function_id)