25 #define RETURN_VALUE_SUFFIX "#return_value"
62 std::optional<symbol_exprt>
66 std::optional<symbol_exprt>
71 const auto symbol_name = symbol_expr.get_identifier();
86 new_symbol.
name = symbol_name;
87 new_symbol.
mode = function_symbol.
mode;
90 new_symbol.
type = return_type;
93 new_symbol.
type.
set(ID_C_no_initialization_required,
true);
120 if(instruction.is_set_return_value())
123 instruction.code().operands().size() == 1,
124 "return instructions should have one operand");
126 if(return_symbol.has_value())
129 code_assignt assignment(*return_symbol, instruction.return_value());
132 auto labels = std::move(instruction.labels);
134 instruction.code_nonconst() = std::move(assignment);
135 instruction.labels = std::move(labels);
138 instruction.turn_into_skip();
153 bool requires_update =
false;
157 if(i_it->is_function_call())
160 i_it->call_function().id() == ID_symbol,
161 "indirect function calls should have been removed prior to running "
175 bool is_stub = function_is_stub(function_id);
176 std::optional<symbol_exprt> return_value;
181 if(return_value.has_value())
187 *return_value, i_it->call_lhs().type());
192 i_it->call_lhs().type(), i_it->source_location());
201 i_it->call_lhs().make_nil();
203 if(return_value.has_value())
210 requires_update =
true;
215 return requires_update;
223 auto function_is_stub = [&goto_functions](
const irep_idt &function_id) {
224 auto findit = goto_functions.
function_map.find(function_id);
227 "called function `" +
id2string(function_id) +
228 "' should have an entry in the function map");
229 return !findit->second.body_available() &&
250 if(goto_function.body.empty())
283 rr(goto_model_function, function_is_stub);
300 symbol_tablet::symbolst::const_iterator rv_it=
306 irep_idt rv_name_id=rv_it->second.name;
309 bool did_something =
false;
313 if(instruction.is_assign())
316 instruction.assign_lhs().id() != ID_symbol ||
323 const exprt rhs = instruction.assign_rhs();
326 did_something =
true;
344 if(i_it->is_function_call())
347 if(i_it->call_function().id() != ID_symbol)
355 goto_programt::instructionst::iterator next = std::next(i_it);
359 "non-void function call must be followed by #return_value read");
361 if(!next->is_assign())
365 if(next->assign_rhs() != rv_symbol)
369 i_it->call_lhs() = next->assign_lhs();
375 next!=goto_program.
instructions.end() && next->is_dead(),
376 "read from #return_value should be followed by DEAD #return_value");
386 bool unmodified=
true;
Internally generated symbol table entryThis is a symbol generated as part of translation to or modifi...
A goto_instruction_codet representing an assignment in the program.
const typet & return_type() const
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
const source_locationt & source_location() const
typet & type()
Return the type of the expression.
A collection of goto functions.
function_mapt function_map
::goto_functiont goto_functiont
void compute_location_numbers()
Interface providing access to a single function in a GOTO model, plus its associated symbol table.
const irep_idt & get_function_id()
Get function id.
goto_functionst::goto_functiont & get_goto_function()
Get GOTO function.
void compute_location_numbers()
Re-number our goto_function.
journalling_symbol_tablet & get_symbol_table()
Get symbol table.
symbol_tablet symbol_table
Symbol table.
goto_functionst goto_functions
GOTO functions.
This class represents an instruction in the GOTO intermediate representation.
const exprt & call_lhs() const
Get the lhs of a FUNCTION_CALL (may be nil)
const exprt & call_function() const
Get the function that is called for FUNCTION_CALL.
A generic container class for the GOTO intermediate representation of one function.
instructionst instructions
The list of instructions in the goto program.
static instructiont make_set_return_value(exprt return_value, const source_locationt &l=source_locationt::nil())
static instructiont make_dead(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
instructionst::iterator targett
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
targett insert_after(const_targett target)
Insertion after the instruction pointed-to by the given instruction iterator target.
void set(const irep_idt &name, const irep_idt &value)
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().
bool restore_returns(const irep_idt &function_id, goto_programt &goto_program)
turns an assignment to fkt::return_value back into 'return x'
void operator()(goto_functionst &goto_functions)
std::optional< symbol_exprt > get_or_create_return_value_symbol(const irep_idt &function_id)
symbol_table_baset & symbol_table
remove_returnst(symbol_table_baset &_symbol_table)
void undo_function_calls(goto_programt &goto_program)
turns f(...); lhs=f::return_value; into lhs=f(...)
void replace_returns(const irep_idt &function_id, goto_functionst::goto_functiont &function)
turns 'return x' into an assignment to fkt::return_value
void restore(goto_functionst &goto_functions)
bool do_function_calls(function_is_stubt function_is_stub, goto_programt &goto_program)
turns x=f(...) into f(...); lhs=f::return_value;
A side_effect_exprt that returns a non-deterministically chosen value.
Expression to hold a symbol (variable)
const irep_idt & get_identifier() const
The symbol table base class interface.
virtual void erase(const symbolst::const_iterator &entry)=0
Remove a symbol from the symbol table.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
virtual symbolt * get_writeable(const irep_idt &name)=0
Find a symbol in the symbol table for read-write access.
irep_idt base_name
Base (non-scoped) name.
irep_idt module
Name of module the symbol belongs to.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
typet type
Type of symbol.
irep_idt name
The unique identifier.
irep_idt mode
Language mode.
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
#define Forall_goto_program_instructions(it, program)
const std::string & id2string(const irep_idt &d)
void restore_returns(goto_modelt &goto_model)
restores return statements
#define RETURN_VALUE_SUFFIX
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
bool is_return_value_identifier(const irep_idt &id)
Returns true if id is a special return-value symbol produced by return_value_identifier.
bool does_function_call_return(const goto_programt::instructiont &function_call)
Check if the function_call returns anything.
void remove_returns(symbol_table_baset &symbol_table, goto_functionst &goto_functions)
removes returns
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.
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...
Replace function returns by assignments to global variables.
std::function< bool(const irep_idt &)> function_is_stubt
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
Symex Shadow Memory Instrumentation.
#define SHADOW_MEMORY_SET_FIELD
#define SHADOW_MEMORY_GET_FIELD
#define SHADOW_MEMORY_FIELD_DECL
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.
bool has_suffix(const std::string &s, const std::string &suffix)