Go to the documentation of this file.
24 #define RETURN_VALUE_SUFFIX "#return_value"
70 const auto symbol_name = symbol_expr.get_identifier();
85 new_symbol.
name = symbol_name;
86 new_symbol.
mode = function_symbol.
mode;
89 new_symbol.
type = return_type;
92 new_symbol.
type.
set(ID_C_no_initialization_required,
true);
119 if(instruction.is_set_return_value())
122 instruction.code().operands().size() == 1,
123 "return instructions should have one operand");
125 if(return_symbol.has_value())
128 code_assignt assignment(*return_symbol, instruction.return_value());
131 auto labels = std::move(instruction.labels);
134 instruction.labels = std::move(labels);
137 instruction.turn_into_skip();
152 bool requires_update =
false;
156 if(i_it->is_function_call())
159 i_it->call_function().id() == ID_symbol,
160 "indirect function calls should have been removed prior to running "
174 bool is_stub = function_is_stub(function_id);
186 *return_value, i_it->call_lhs().type());
191 i_it->call_lhs().type(), i_it->source_location());
200 i_it->call_lhs().make_nil();
209 requires_update =
true;
214 return requires_update;
222 auto function_is_stub = [&goto_functions](
const irep_idt &function_id) {
223 auto findit = goto_functions.
function_map.find(function_id);
226 "called function `" +
id2string(function_id) +
227 "' should have an entry in the function map");
228 return !findit->second.body_available();
246 if(goto_function.body.empty())
279 rr(goto_model_function, function_is_stub);
296 symbol_tablet::symbolst::const_iterator rv_it=
302 irep_idt rv_name_id=rv_it->second.name;
305 bool did_something =
false;
309 if(instruction.is_assign())
312 instruction.assign_lhs().id() != ID_symbol ||
319 const exprt rhs = instruction.assign_rhs();
322 did_something =
true;
340 if(i_it->is_function_call())
343 if(i_it->call_function().id() != ID_symbol)
351 goto_programt::instructionst::iterator next = std::next(i_it);
355 "non-void function call must be followed by #return_value read");
357 if(!next->is_assign())
361 if(next->assign_rhs() != rv_symbol)
365 i_it->call_lhs() = next->assign_lhs();
371 next!=goto_program.
instructions.end() && next->is_dead(),
372 "read from #return_value should be followed by DEAD #return_value");
382 bool unmodified=
true;
#define Forall_goto_program_instructions(it, program)
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
static exprt conditional_cast(const exprt &expr, const typet &type)
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
void restore(goto_functionst &goto_functions)
virtual symbolt * get_writeable(const irep_idt &name)=0
Find a symbol in the symbol table for read-write access.
static instructiont make_dead(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
#define CHECK_RETURN(CONDITION)
The type of an expression, extends irept.
static instructiont make_set_return_value(exprt return_value, const source_locationt &l=source_locationt::nil())
typet type
Type of symbol.
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
const irep_idt & get_function_id()
Get function id.
void compute_location_numbers()
Base class for all expressions.
irep_idt base_name
Base (non-scoped) name.
virtual void erase(const symbolst::const_iterator &entry)=0
Remove a symbol from the symbol table.
std::function< bool(const irep_idt &)> function_is_stubt
Internally generated symbol table entry.
function_mapt function_map
Expression to hold a symbol (variable)
bool has_suffix(const std::string &s, const std::string &suffix)
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
bool is_return_value_identifier(const irep_idt &id)
Returns true if id is a special return-value symbol produced by return_value_identifier.
void undo_function_calls(goto_programt &goto_program)
turns f(...); lhs=f::return_value; into lhs=f(...)
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
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().
#define RETURN_VALUE_SUFFIX
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
irep_idt mode
Language mode.
bool does_function_call_return(const goto_programt::instructiont &function_call)
Check if the function_call returns anything.
const std::string & id2string(const irep_idt &d)
void set(const irep_idt &name, const irep_idt &value)
remove_returnst(symbol_table_baset &_symbol_table)
const irep_idt & get_identifier() const
The symbol table base class interface.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
bool is_return_value_symbol(const symbol_exprt &symbol_expr)
Returns true if symbol_expr is a special return-value symbol produced by return_value_symbol.
bool restore_returns(const irep_idt &function_id, goto_programt &goto_program)
turns an assignment to fkt::return_value back into 'return x'
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
journalling_symbol_tablet & get_symbol_table()
Get symbol table.
const exprt & call_lhs() const
Get the lhs of a FUNCTION_CALL (may be nil)
void compute_location_numbers()
Re-number our goto_function.
nonstd::optional< T > optionalt
symbol_table_baset & symbol_table
A side_effect_exprt that returns a non-deterministically chosen value.
::goto_functiont goto_functiont
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
instructionst instructions
The list of instructions in the goto program.
A collection of goto functions.
irep_idt return_value_identifier(const irep_idt &identifier)
produces the identifier that is used to store the return value of the function with the given identif...
void operator()(goto_functionst &goto_functions)
goto_functionst goto_functions
GOTO functions.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
void remove_returns(symbol_table_baset &symbol_table, goto_functionst &goto_functions)
removes returns
A generic container class for the GOTO intermediate representation of one function.
targett insert_after(const_targett target)
Insertion after the instruction pointed-to by the given instruction iterator target.
symbol_exprt return_value_symbol(const irep_idt &identifier, const namespacet &ns)
produces the symbol that is used to store the return value of the function with the given identifier
optionalt< symbol_exprt > get_or_create_return_value_symbol(const irep_idt &function_id)
const typet & return_type() const
goto_functionst::goto_functiont & get_goto_function()
Get GOTO function.
A goto_instruction_codet representing an assignment in the program.
irep_idt module
Name of module the symbol belongs to.
This class represents an instruction in the GOTO intermediate representation.
const source_locationt & source_location() const
symbol_tablet symbol_table
Symbol table.
void replace_returns(const irep_idt &function_id, goto_functionst::goto_functiont &function)
turns 'return x' into an assignment to fkt::return_value
const exprt & call_function() const
Get the function that is called for FUNCTION_CALL.
irep_idt name
The unique identifier.
Interface providing access to a single function in a GOTO model, plus its associated symbol table.
void restore_returns(goto_modelt &goto_model)
restores return statements
instructionst::iterator targett
bool do_function_calls(function_is_stubt function_is_stub, goto_programt &goto_program)
turns x=f(...) into f(...); lhs=f::return_value;