83 typedef std::vector<std::pair<
106 "remove_exceptions needs a class hierarchy to remove instanceof "
107 "statements (either supply one, or don't use REMOVE_ADDED_INSTANCEOF)");
145 const irep_idt &function_identifier,
149 const std::vector<symbol_exprt> &locals);
152 const irep_idt &function_identifier,
156 const std::vector<symbol_exprt> &);
159 const irep_idt &function_identifier,
163 const std::vector<symbol_exprt> &);
166 const irep_idt &function_identifier,
178 "Java frontend should have created @inflight_exception variable");
190 for(
const auto &instruction : goto_program.
instructions)
192 if(instruction.is_throw())
197 if(instruction.is_function_call())
202 "identifier expected to be a symbol");
321 const irep_idt &function_identifier,
325 const std::vector<symbol_exprt> &locals)
387 for(
const auto &local : locals)
397 const irep_idt &function_identifier,
401 const std::vector<symbol_exprt> &locals)
428 const irep_idt &function_identifier,
432 const std::vector<symbol_exprt> &locals)
440 const auto &function =
instr_it->call_function();
443 function.id() ==
ID_symbol,
"function call expected to be a symbol");
486 const irep_idt &function_identifier,
491 std::vector<symbol_exprt> locals;
493 if(goto_program.
empty())
506 locals.push_back(
instr_it->decl_symbol());
535 std::cout <<
"Remove exceptions: empty stack\n";
559 exception_list.size()==
instr_it->targets.size(),
560 "`exception_list` should contain current instruction's targets");
564 for(
auto target :
instr_it->targets)
567 std::make_pair(exception_list[i].
get_tag(), target));
575 "CATCH opcode should be one of push-catch, pop-catch, landingpad");
629 std::map<irep_idt, std::set<irep_idt>> exceptions_map;
634 [&exceptions_map](
const irep_idt &id) {
635 return !exceptions_map[id].empty();
639 symbol_table,
nullptr, function_may_throw,
false, message_handler);
657 const irep_idt &function_identifier,
663 [](
const irep_idt &) {
return true; };
694 std::map<irep_idt, std::set<irep_idt>> exceptions_map;
699 [&exceptions_map](
const irep_idt &id) {
700 return !exceptions_map[id].empty();
704 symbol_table, &class_hierarchy, function_may_throw,
true, message_handler);
724 const irep_idt &function_identifier,
731 [](
const irep_idt &) {
return true; };
pointer_typet pointer_type(const typet &subtype)
virtual void clear()
Reset the abstract state.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Non-graph-based representation of the class hierarchy.
A goto_instruction_codet representing an assignment in the program.
std::vector< exception_list_entryt > exception_listt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
A collection of goto functions.
function_mapt function_map
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.
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 get_end_function()
Get an instruction iterator pointing to the END_FUNCTION instruction of the goto program.
targett insert_after(const_targett target)
Insertion after the instruction pointed-to by the given instruction iterator target.
static instructiont make_goto(targett _target, const source_locationt &l=source_locationt::nil())
bool empty() const
Is the program empty?
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
The null pointer constant.
Lowers high-level exception descriptions into low-level operations suitable for symex and other analy...
const class_hierarchyt * class_hierarchy
std::vector< catch_handlerst > stack_catcht
function_may_throwt function_may_throw
symbol_exprt get_inflight_exception_global()
Create a global named java::@inflight_exception that holds any exception that has been thrown but not...
void add_exception_dispatch_sequence(const irep_idt &function_identifier, goto_programt &goto_program, const goto_programt::targett &instr_it, const stack_catcht &stack_catch, const std::vector< symbol_exprt > &locals)
Emit the code: if (exception instanceof ExnA) then goto handlerA else if (exception instanceof ExnB) ...
message_handlert & message_handler
void instrument_exception_handler(goto_programt &goto_program, const goto_programt::targett &, bool may_catch)
Translates an exception landing-pad into instructions that copy the in-flight exception pointer to a ...
@ ADDED_CODE_WITHOUT_MAY_THROW
@ ADDED_CODE_WITH_MAY_THROW
std::vector< std::pair< irep_idt, goto_programt::targett > > catch_handlerst
bool function_or_callees_may_throw(const goto_programt &) const
Checks whether a function may ever experience an exception (whether or not it catches),...
goto_programt::targett find_universal_exception(const remove_exceptionst::stack_catcht &stack_catch, goto_programt &goto_program, std::size_t &universal_try, std::size_t &universal_catch)
Find the innermost universal exception handler for the current program location which may throw (i....
remove_exceptionst(symbol_table_baset &_symbol_table, const class_hierarchyt *_class_hierarchy, function_may_throwt _function_may_throw, bool _remove_added_instanceof, message_handlert &_message_handler)
std::function< bool(const irep_idt &)> function_may_throwt
instrumentation_resultt instrument_function_call(const irep_idt &function_identifier, goto_programt &goto_program, const goto_programt::targett &, const stack_catcht &, const std::vector< symbol_exprt > &)
instruments each function call that may escape exceptions with conditional GOTOS to the corresponding...
bool instrument_throw(const irep_idt &function_identifier, goto_programt &goto_program, const goto_programt::targett &, const stack_catcht &, const std::vector< symbol_exprt > &)
instruments each throw with conditional GOTOS to the corresponding exception handlers
void instrument_exceptions(const irep_idt &function_identifier, goto_programt &goto_program)
instruments throws, function calls that may escape exceptions and exception handlers.
bool remove_added_instanceof
symbol_table_baset & symbol_table
void operator()(goto_functionst &goto_functions)
A struct tag type, i.e., struct_typet with an identifier.
Expression to hold a symbol (variable)
The symbol table base class interface.
const symbolt * lookup(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
The Boolean constant true.
Semantic type conversion.
static exprt get_exception_symbol(const exprt &exor)
Returns the symbol corresponding to an exception.
#define Forall_goto_program_instructions(it, program)
Java-specific exprt subclasses.
static irep_idt get_tag(const typet &type)
empty_typet java_void_type()
API to expression classes for Pointers.
void remove_exceptions_using_instanceof(symbol_table_baset &symbol_table, goto_functionst &goto_functions, message_handlert &message_handler)
removes throws/CATCH-POP/CATCH-PUSH
void remove_exceptions(symbol_table_baset &symbol_table, goto_functionst &goto_functions, const class_hierarchyt &class_hierarchy, message_handlert &message_handler)
removes throws/CATCH-POP/CATCH-PUSH
Remove function exceptional returns.
#define INFLIGHT_EXCEPTION_VARIABLE_NAME
void remove_instanceof(const irep_idt &function_identifier, goto_programt::targett target, goto_programt &goto_program, symbol_table_baset &symbol_table, const class_hierarchyt &class_hierarchy, message_handlert &message_handler)
Replace an instanceof in the expression or guard of the passed instruction of the given function body...
Remove Instance-of Operators.
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
#define INITIALIZE_FUNCTION
static code_push_catcht & to_code_push_catch(codet &code)
static code_landingpadt & to_code_landingpad(codet &code)
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
void uncaught_exceptions(const goto_functionst &goto_functions, const namespacet &ns, std::map< irep_idt, std::set< irep_idt > > &exceptions_map)
Applies the uncaught exceptions analysis and outputs the result.
Over-approximative uncaught exceptions analysis.