@@ -26,6 +26,8 @@ Date: December 2016
2626#include < util/std_code.h>
2727#include < util/symbol_table.h>
2828
29+ #include < goto-programs/remove_skip.h>
30+
2931#include < analyses/uncaught_exceptions_analysis.h>
3032
3133// / Lowers high-level exception descriptions into low-level operations suitable
@@ -122,13 +124,13 @@ class remove_exceptionst
122124 const stack_catcht &stack_catch,
123125 const std::vector<exprt> &locals);
124126
125- void instrument_throw (
127+ bool instrument_throw (
126128 goto_programt &goto_program,
127129 const goto_programt::targett &,
128130 const stack_catcht &,
129131 const std::vector<exprt> &);
130132
131- void instrument_function_call (
133+ bool instrument_function_call (
132134 goto_programt &goto_program,
133135 const goto_programt::targett &,
134136 const stack_catcht &,
@@ -369,7 +371,7 @@ void remove_exceptionst::add_exception_dispatch_sequence(
369371
370372// / instruments each throw with conditional GOTOS to the corresponding
371373// / exception handlers
372- void remove_exceptionst::instrument_throw (
374+ bool remove_exceptionst::instrument_throw (
373375 goto_programt &goto_program,
374376 const goto_programt::targett &instr_it,
375377 const remove_exceptionst::stack_catcht &stack_catch,
@@ -387,7 +389,7 @@ void remove_exceptionst::instrument_throw(
387389 // and this may reduce the instrumentation considerably if the programmer
388390 // used assertions)
389391 if (assertion_error)
390- return ;
392+ return false ;
391393
392394 add_exception_dispatch_sequence (
393395 goto_program, instr_it, stack_catch, locals);
@@ -403,11 +405,13 @@ void remove_exceptionst::instrument_throw(
403405 // now turn the `throw' into `assignment'
404406 instr_it->type =ASSIGN;
405407 instr_it->code =assignment;
408+
409+ return true ;
406410}
407411
408412// / instruments each function call that may escape exceptions with conditional
409413// / GOTOS to the corresponding exception handlers
410- void remove_exceptionst::instrument_function_call (
414+ bool remove_exceptionst::instrument_function_call (
411415 goto_programt &goto_program,
412416 const goto_programt::targett &instr_it,
413417 const stack_catcht &stack_catch,
@@ -441,7 +445,11 @@ void remove_exceptionst::instrument_function_call(
441445 t_null->source_location =instr_it->source_location ;
442446 t_null->function =instr_it->function ;
443447 t_null->guard =eq_null;
448+
449+ return true ;
444450 }
451+
452+ return false ;
445453}
446454
447455// / instruments throws, function calls that may escape exceptions and exception
@@ -460,6 +468,8 @@ void remove_exceptionst::instrument_exceptions(
460468 bool program_or_callees_may_throw =
461469 function_or_callees_may_throw (goto_program);
462470
471+ bool did_something = false ;
472+
463473 Forall_goto_program_instructions (instr_it, goto_program)
464474 {
465475 if (instr_it->is_decl ())
@@ -537,18 +547,22 @@ void remove_exceptionst::instrument_exceptions(
537547 " CATCH opcode should be one of push-catch, pop-catch, landingpad" );
538548 }
539549 instr_it->make_skip ();
550+ did_something = true ;
540551 }
541552 else if (instr_it->type ==THROW)
542553 {
543- instrument_throw (
544- goto_program, instr_it, stack_catch, locals);
554+ did_something |=
555+ instrument_throw ( goto_program, instr_it, stack_catch, locals);
545556 }
546557 else if (instr_it->type ==FUNCTION_CALL)
547558 {
548- instrument_function_call (
549- goto_program, instr_it, stack_catch, locals);
559+ did_something |=
560+ instrument_function_call ( goto_program, instr_it, stack_catch, locals);
550561 }
551562 }
563+
564+ if (did_something)
565+ remove_skip (goto_program);
552566}
553567
554568void remove_exceptionst::operator ()(goto_functionst &goto_functions)
0 commit comments