Skip to content

Commit c98cd43

Browse files
authored
Merge pull request #3835 from tautschnig/function-remove_exceptions
remove_exceptions now takes function identifier [blocks: #3126]
2 parents 0f7a99d + 8b9acc1 commit c98cd43

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

jbmc/src/java_bytecode/remove_exceptions.cpp

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class remove_exceptionst
107107
}
108108

109109
void operator()(goto_functionst &goto_functions);
110-
void operator()(goto_programt &goto_program);
110+
void
111+
operator()(const irep_idt &function_identifier, goto_programt &goto_program);
111112

112113
protected:
113114
symbol_table_baset &symbol_table;
@@ -132,24 +133,28 @@ class remove_exceptionst
132133
std::size_t &universal_catch);
133134

134135
void add_exception_dispatch_sequence(
136+
const irep_idt &function_identifier,
135137
goto_programt &goto_program,
136138
const goto_programt::targett &instr_it,
137139
const stack_catcht &stack_catch,
138140
const std::vector<symbol_exprt> &locals);
139141

140142
bool instrument_throw(
143+
const irep_idt &function_identifier,
141144
goto_programt &goto_program,
142145
const goto_programt::targett &,
143146
const stack_catcht &,
144147
const std::vector<symbol_exprt> &);
145148

146149
bool instrument_function_call(
150+
const irep_idt &function_identifier,
147151
goto_programt &goto_program,
148152
const goto_programt::targett &,
149153
const stack_catcht &,
150154
const std::vector<symbol_exprt> &);
151155

152156
void instrument_exceptions(
157+
const irep_idt &function_identifier,
153158
goto_programt &goto_program);
154159
};
155160

@@ -299,12 +304,14 @@ goto_programt::targett remove_exceptionst::find_universal_exception(
299304
/// if (exception instanceof ExnA) then goto handlerA
300305
/// else if (exception instanceof ExnB) then goto handlerB
301306
/// else goto universal_handler or (dead locals; function exit)
307+
/// \param function_identifier: name of the function containing \p instr_it
302308
/// \param goto_program: body of the function to which instr_it belongs
303309
/// \param instr_it: throw or call instruction that may be an
304310
/// exception source
305311
/// \param stack_catch: exception handlers currently registered
306312
/// \param locals: local variables to kill on a function-exit edge
307313
void remove_exceptionst::add_exception_dispatch_sequence(
314+
const irep_idt &function_identifier,
308315
goto_programt &goto_program,
309316
const goto_programt::targett &instr_it,
310317
const remove_exceptionst::stack_catcht &stack_catch,
@@ -385,6 +392,7 @@ void remove_exceptionst::add_exception_dispatch_sequence(
385392
/// instruments each throw with conditional GOTOS to the corresponding
386393
/// exception handlers
387394
bool remove_exceptionst::instrument_throw(
395+
const irep_idt &function_identifier,
388396
goto_programt &goto_program,
389397
const goto_programt::targett &instr_it,
390398
const remove_exceptionst::stack_catcht &stack_catch,
@@ -396,7 +404,7 @@ bool remove_exceptionst::instrument_throw(
396404
uncaught_exceptions_domaint::get_exception_symbol(instr_it->code);
397405

398406
add_exception_dispatch_sequence(
399-
goto_program, instr_it, stack_catch, locals);
407+
function_identifier, goto_program, instr_it, stack_catch, locals);
400408

401409
// find the symbol where the thrown exception should be stored:
402410
symbol_exprt exc_thrown =
@@ -416,6 +424,7 @@ bool remove_exceptionst::instrument_throw(
416424
/// instruments each function call that may escape exceptions with conditional
417425
/// GOTOS to the corresponding exception handlers
418426
bool remove_exceptionst::instrument_function_call(
427+
const irep_idt &function_identifier,
419428
goto_programt &goto_program,
420429
const goto_programt::targett &instr_it,
421430
const stack_catcht &stack_catch,
@@ -450,7 +459,7 @@ bool remove_exceptionst::instrument_function_call(
450459
else
451460
{
452461
add_exception_dispatch_sequence(
453-
goto_program, instr_it, stack_catch, locals);
462+
function_identifier, goto_program, instr_it, stack_catch, locals);
454463

455464
// add a null check (so that instanceof can be applied)
456465
goto_programt::targett t_null=goto_program.insert_after(instr_it);
@@ -470,6 +479,7 @@ bool remove_exceptionst::instrument_function_call(
470479
/// handlers. Additionally, it re-computes the live-range of local variables in
471480
/// order to add DEAD instructions.
472481
void remove_exceptionst::instrument_exceptions(
482+
const irep_idt &function_identifier,
473483
goto_programt &goto_program)
474484
{
475485
stack_catcht stack_catch; // stack of try-catch blocks
@@ -565,13 +575,13 @@ void remove_exceptionst::instrument_exceptions(
565575
}
566576
else if(instr_it->type==THROW)
567577
{
568-
did_something |=
569-
instrument_throw(goto_program, instr_it, stack_catch, locals);
578+
did_something |= instrument_throw(
579+
function_identifier, goto_program, instr_it, stack_catch, locals);
570580
}
571581
else if(instr_it->type==FUNCTION_CALL)
572582
{
573-
did_something |=
574-
instrument_function_call(goto_program, instr_it, stack_catch, locals);
583+
did_something |= instrument_function_call(
584+
function_identifier, goto_program, instr_it, stack_catch, locals);
575585
}
576586
}
577587

@@ -582,12 +592,13 @@ void remove_exceptionst::instrument_exceptions(
582592
void remove_exceptionst::operator()(goto_functionst &goto_functions)
583593
{
584594
Forall_goto_functions(it, goto_functions)
585-
instrument_exceptions(it->second.body);
595+
instrument_exceptions(it->first, it->second.body);
586596
}
587597

588-
void remove_exceptionst::operator()(goto_programt &goto_program)
598+
void remove_exceptionst::
599+
operator()(const irep_idt &function_identifier, goto_programt &goto_program)
589600
{
590-
instrument_exceptions(goto_program);
601+
instrument_exceptions(function_identifier, goto_program);
591602
}
592603

593604
/// removes throws/CATCH-POP/CATCH-PUSH
@@ -618,12 +629,14 @@ void remove_exceptions_using_instanceof(
618629
/// because we can't inspect other functions to determine whether they throw
619630
/// or not, and therefore must assume they do and always introduce post-call
620631
/// exception dispatch.
632+
/// \param function_identifier: name of the goto function being processed
621633
/// \param goto_program: program to remove exceptions from
622634
/// \param symbol_table: global symbol table. The `@inflight_exception` global
623635
/// may be added if not already present. It will not be initialised; that is
624636
/// the caller's responsibility.
625637
/// \param message_handler: logging output
626638
void remove_exceptions_using_instanceof(
639+
const irep_idt &function_identifier,
627640
goto_programt &goto_program,
628641
symbol_table_baset &symbol_table,
629642
message_handlert &message_handler)
@@ -634,7 +647,7 @@ void remove_exceptions_using_instanceof(
634647
remove_exceptionst remove_exceptions(
635648
symbol_table, nullptr, any_function_may_throw, false, message_handler);
636649

637-
remove_exceptions(goto_program);
650+
remove_exceptions(function_identifier, goto_program);
638651
}
639652

640653
/// removes throws/CATCH-POP/CATCH-PUSH, replacing them with explicit exception
@@ -681,6 +694,7 @@ void remove_exceptions(
681694
/// because we can't inspect other functions to determine whether they throw
682695
/// or not, and therefore must assume they do and always introduce post-call
683696
/// exception dispatch.
697+
/// \param function_identifier: name of the goto function being processed
684698
/// \param goto_program: program to remove exceptions from
685699
/// \param symbol_table: global symbol table. The `@inflight_exception` global
686700
/// may be added if not already present. It will not be initialised; that is
@@ -689,6 +703,7 @@ void remove_exceptions(
689703
/// Only needed if type == REMOVE_ADDED_INSTANCEOF; otherwise may be null.
690704
/// \param message_handler: logging output
691705
void remove_exceptions(
706+
const irep_idt &function_identifier,
692707
goto_programt &goto_program,
693708
symbol_table_baset &symbol_table,
694709
const class_hierarchyt &class_hierarchy,
@@ -704,7 +719,7 @@ void remove_exceptions(
704719
true,
705720
message_handler);
706721

707-
remove_exceptions(goto_program);
722+
remove_exceptions(function_identifier, goto_program);
708723
}
709724

710725
/// removes throws/CATCH-POP/CATCH-PUSH, replacing them with explicit exception

jbmc/src/java_bytecode/remove_exceptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Date: December 2016
2727
/// and adds the required instrumentation (GOTOs and assignments)
2828
/// This introduces instanceof expressions.
2929
void remove_exceptions_using_instanceof(
30+
const irep_idt &function_identifier,
3031
goto_programt &,
3132
symbol_table_baset &,
3233
message_handlert &);
@@ -40,6 +41,7 @@ void remove_exceptions_using_instanceof(goto_modelt &, message_handlert &);
4041
/// and adds the required instrumentation (GOTOs and assignments)
4142
/// This does not introduce instanceof expressions.
4243
void remove_exceptions(
44+
const irep_idt &function_identifier,
4345
goto_programt &,
4446
symbol_table_baset &,
4547
const class_hierarchyt &,

jbmc/src/jbmc/jbmc_parse_options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ void jbmc_parse_optionst::process_goto_function(
799799
// the results are slightly worse than running it in whole-program mode
800800
// (e.g. dead catch sites will be retained)
801801
remove_exceptions(
802+
function.get_function_id(),
802803
goto_function.body,
803804
symbol_table,
804805
*class_hierarchy.get(),

0 commit comments

Comments
 (0)