@@ -26,6 +26,8 @@ Date: December 2016
26
26
#include < util/std_code.h>
27
27
#include < util/symbol_table.h>
28
28
29
+ #include < goto-programs/remove_skip.h>
30
+
29
31
#include < analyses/uncaught_exceptions_analysis.h>
30
32
31
33
// / Lowers high-level exception descriptions into low-level operations suitable
@@ -122,13 +124,13 @@ class remove_exceptionst
122
124
const stack_catcht &stack_catch,
123
125
const std::vector<exprt> &locals);
124
126
125
- void instrument_throw (
127
+ bool instrument_throw (
126
128
goto_programt &goto_program,
127
129
const goto_programt::targett &,
128
130
const stack_catcht &,
129
131
const std::vector<exprt> &);
130
132
131
- void instrument_function_call (
133
+ bool instrument_function_call (
132
134
goto_programt &goto_program,
133
135
const goto_programt::targett &,
134
136
const stack_catcht &,
@@ -369,7 +371,7 @@ void remove_exceptionst::add_exception_dispatch_sequence(
369
371
370
372
// / instruments each throw with conditional GOTOS to the corresponding
371
373
// / exception handlers
372
- void remove_exceptionst::instrument_throw (
374
+ bool remove_exceptionst::instrument_throw (
373
375
goto_programt &goto_program,
374
376
const goto_programt::targett &instr_it,
375
377
const remove_exceptionst::stack_catcht &stack_catch,
@@ -387,7 +389,7 @@ void remove_exceptionst::instrument_throw(
387
389
// and this may reduce the instrumentation considerably if the programmer
388
390
// used assertions)
389
391
if (assertion_error)
390
- return ;
392
+ return false ;
391
393
392
394
add_exception_dispatch_sequence (
393
395
goto_program, instr_it, stack_catch, locals);
@@ -403,11 +405,13 @@ void remove_exceptionst::instrument_throw(
403
405
// now turn the `throw' into `assignment'
404
406
instr_it->type =ASSIGN;
405
407
instr_it->code =assignment;
408
+
409
+ return true ;
406
410
}
407
411
408
412
// / instruments each function call that may escape exceptions with conditional
409
413
// / GOTOS to the corresponding exception handlers
410
- void remove_exceptionst::instrument_function_call (
414
+ bool remove_exceptionst::instrument_function_call (
411
415
goto_programt &goto_program,
412
416
const goto_programt::targett &instr_it,
413
417
const stack_catcht &stack_catch,
@@ -441,7 +445,11 @@ void remove_exceptionst::instrument_function_call(
441
445
t_null->source_location =instr_it->source_location ;
442
446
t_null->function =instr_it->function ;
443
447
t_null->guard =eq_null;
448
+
449
+ return true ;
444
450
}
451
+
452
+ return false ;
445
453
}
446
454
447
455
// / instruments throws, function calls that may escape exceptions and exception
@@ -460,6 +468,8 @@ void remove_exceptionst::instrument_exceptions(
460
468
bool program_or_callees_may_throw =
461
469
function_or_callees_may_throw (goto_program);
462
470
471
+ bool did_something = false ;
472
+
463
473
Forall_goto_program_instructions (instr_it, goto_program)
464
474
{
465
475
if (instr_it->is_decl ())
@@ -537,18 +547,22 @@ void remove_exceptionst::instrument_exceptions(
537
547
" CATCH opcode should be one of push-catch, pop-catch, landingpad" );
538
548
}
539
549
instr_it->make_skip ();
550
+ did_something = true ;
540
551
}
541
552
else if (instr_it->type ==THROW)
542
553
{
543
- instrument_throw (
544
- goto_program, instr_it, stack_catch, locals);
554
+ did_something |=
555
+ instrument_throw ( goto_program, instr_it, stack_catch, locals);
545
556
}
546
557
else if (instr_it->type ==FUNCTION_CALL)
547
558
{
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);
550
561
}
551
562
}
563
+
564
+ if (did_something)
565
+ remove_skip (goto_program);
552
566
}
553
567
554
568
void remove_exceptionst::operator ()(goto_functionst &goto_functions)
0 commit comments