36 bool _add_safety_assertion,
93 bool return_value_used,
98 const typet &call_type,
99 const typet &function_type);
111 bool _add_safety_assertion,
112 bool only_resolve_const_fps,
114 : log(_message_handler),
116 symbol_table(_symbol_table),
117 add_safety_assertion(_add_safety_assertion),
118 only_resolve_const_fps(only_resolve_const_fps)
134 const typet &call_type,
135 const typet &function_type)
137 if(call_type == function_type)
142 call_type.
id() == ID_signedbv || call_type.
id() == ID_unsigned ||
143 call_type.
id() == ID_bool || call_type.
id() == ID_c_bool ||
144 call_type.
id() == ID_c_enum_tag || call_type.
id() == ID_c_enum ||
145 call_type.
id() == ID_pointer)
147 return function_type.
id() == ID_signedbv ||
148 function_type.
id() == ID_unsigned || function_type.
id() == ID_bool ||
149 function_type.
id() == ID_c_bool ||
150 function_type.
id() == ID_pointer ||
151 function_type.
id() == ID_c_enum ||
152 function_type.
id() == ID_c_enum_tag;
160 bool return_value_used,
166 if(!return_value_used)
185 function_parameters.empty())
190 call_parameters.empty())
197 if(call_parameters.size()!=function_parameters.size())
200 for(std::size_t i=0; i<call_parameters.size(); i++)
202 function_parameters[i].type()))
220 for(std::size_t i=0; i<function_parameters.size(); i++)
222 if(i<call_arguments.size())
224 if(call_arguments[i].type() != function_parameters[i].type())
248 const symbolt &function_symbol =
256 function_symbol.
mode,
262 function_call.
lhs()=tmp_symbol_expr;
283 for(
const auto &argument :
as_const(*target).call_arguments())
289 bool found_functions;
291 const exprt &pointer =
function.pointer();
294 const auto does_remove_const = const_removal_check();
295 if(does_remove_const.first)
298 log.
warning() <<
"cast from const to non-const pointer found, "
299 <<
"only worst case function pointer removal will be done."
301 found_functions=
false;
308 found_functions=fpr(pointer, functions);
316 if(functions.size()==1)
318 target->call_function() = *functions.cbegin();
336 bool return_value_used =
as_const(*target).call_lhs().is_not_nil();
350 if(t.first==
"pthread_mutex_cleanup")
354 functions.insert(expr);
367 const exprt &
function = target->call_function();
380 for(
const auto &fun : functions)
401 const auto casted_address =
413 t->source_location.set_property_class(
"pointer dereference");
414 t->source_location.set_comment(
"invalid function pointer");
432 source_location = target->source_location;
433 if(!property_class.
empty())
448 target->code_nonconst().
swap(code_expression);
453 log.
statistics() <<
"replacing function pointer by " << functions.size()
459 mstream <<
"targets: ";
462 for(const auto &function : functions)
467 mstream << function.get_identifier();
479 bool did_something=
false;
482 if(target->is_function_call())
484 if(target->call_function().id() == ID_dereference)
494 return did_something;
499 bool did_something=
false;
501 for(goto_functionst::function_mapt::iterator f_it=
522 bool add_safety_assertion,
523 bool only_remove_const_fps)
529 add_safety_assertion,
530 only_remove_const_fps,
540 bool add_safety_assertion,
541 bool only_remove_const_fps)
547 add_safety_assertion,
548 only_remove_const_fps,
556 bool add_safety_assertion,
557 bool only_remove_const_fps)
563 add_safety_assertion,
564 only_remove_const_fps);
const T & as_const(T &value)
Return a reference to the same object but ensures the type is const.
pointer_typet pointer_type(const typet &subtype)
Operator to return the address of an object.
A codet representing an assignment in the program.
codet representation of an expression statement.
codet representation of a function call statement.
exprt::operandst argumentst
std::vector< parametert > parameterst
const typet & return_type() const
bool has_ellipsis() const
const parameterst & parameters() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
source_locationt & add_source_location()
const source_locationt & source_location() const
typet & type()
Return the type of the expression.
The Boolean constant false.
A collection of goto functions.
function_mapt function_map
void compute_location_numbers()
symbol_tablet symbol_table
Symbol table.
goto_functionst goto_functions
GOTO functions.
A generic container class for the GOTO intermediate representation of one function.
static instructiont make_assumption(const exprt &g, const source_locationt &l=source_locationt::nil())
instructionst instructions
The list of instructions in the goto program.
void destructive_insert(const_targett target, goto_programt &p)
Inserts the given program p before target.
instructionst::iterator targett
void destructive_append(goto_programt &p)
Appends the given program p to *this. p is destroyed.
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
static instructiont make_skip(const source_locationt &l=source_locationt::nil())
static instructiont make_function_call(const code_function_callt &_code, const source_locationt &l=source_locationt::nil())
Create a function call instruction.
targett add(instructiont &&instruction)
Adds a given instruction at the end.
static instructiont make_goto(targett _target, const source_locationt &l=source_locationt::nil())
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
const irep_idt & id() const
source_locationt source_location
Class that provides messages with a built-in verbosity 'level'.
mstreamt & statistics() const
mstreamt & warning() const
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...
message_handlert & get_message_handler()
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
std::unordered_set< symbol_exprt, irep_hash > functionst
std::map< irep_idt, code_typet > type_mapt
void operator()(goto_functionst &goto_functions)
bool is_type_compatible(bool return_value_used, const code_typet &call_type, const code_typet &function_type)
bool add_safety_assertion
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)
symbol_tablet & symbol_table
void fix_return_type(const irep_idt &in_function_id, code_function_callt &function_call, goto_programt &dest)
bool arg_is_type_compatible(const typet &call_type, const typet &function_type)
std::unordered_set< irep_idt > address_taken
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...
remove_const_function_pointerst::functionst functionst
bool only_resolve_const_fps
void fix_argument_types(code_function_callt &function_call)
bool remove_function_pointers(goto_programt &goto_program, const irep_idt &function_id)
void set_comment(const irep_idt &comment)
const irep_idt & get_comment() const
void set_property_class(const irep_idt &property_class)
const irep_idt & get_property_class() const
Expression to hold a symbol (variable)
const irep_idt & get_identifier() const
const symbolst & symbols
Read-only field, used to look up symbols given their names.
irep_idt base_name
Base (non-scoped) name.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
irep_idt mode
Language mode.
The Boolean constant true.
Semantic type conversion.
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
void compute_address_taken_functions(const exprt &src, std::unordered_set< irep_idt > &address_taken)
get all functions whose address is taken
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.
#define Forall_goto_program_instructions(it, program)
const std::string & id2string(const irep_idt &d)
API to expression classes for Pointers.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
optionalt< mp_integer > pointer_offset_bits(const typet &type, const namespacet &ns)
static std::string comment(const rw_set_baset::entryt &entry, bool write)
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)
Remove Indirect Function Calls.
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
#define CHECK_RETURN(CONDITION)
API to expression classes.
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.