@@ -86,9 +86,11 @@ class remove_exceptionst
86
86
explicit remove_exceptionst (
87
87
symbol_table_baset &_symbol_table,
88
88
function_may_throwt _function_may_throw,
89
+ bool propagate_assertion_error,
89
90
bool remove_added_instanceof)
90
91
: symbol_table(_symbol_table),
91
92
function_may_throw(_function_may_throw),
93
+ propagate_assertion_error(propagate_assertion_error),
92
94
remove_added_instanceof(remove_added_instanceof)
93
95
{
94
96
}
@@ -99,6 +101,7 @@ class remove_exceptionst
99
101
protected:
100
102
symbol_table_baset &symbol_table;
101
103
function_may_throwt function_may_throw;
104
+ bool propagate_assertion_error;
102
105
bool remove_added_instanceof;
103
106
104
107
symbol_exprt get_inflight_exception_global ();
@@ -162,6 +165,9 @@ bool remove_exceptionst::function_or_callees_may_throw(
162
165
{
163
166
if (instr_it->is_throw ())
164
167
{
168
+ if (propagate_assertion_error)
169
+ return true ;
170
+
165
171
const exprt &exc =
166
172
uncaught_exceptions_domaint::get_exception_symbol (instr_it->code );
167
173
bool is_assertion_error =
@@ -383,10 +389,10 @@ void remove_exceptionst::instrument_throw(
383
389
uncaught_exceptions_domaint::get_exception_type (exc_expr.type ())).
384
390
find (" java.lang.AssertionError" )!=std::string::npos;
385
391
386
- // we don't count AssertionError (we couldn't catch it anyway
387
- // and this may reduce the instrumentation considerably if the programmer
388
- // used assertions)
389
- if (assertion_error)
392
+ // we allow AssertionError not to be propgated since
393
+ // this may reduce the instrumentation considerably if the programmer
394
+ // used assertions
395
+ if (assertion_error && !propagate_assertion_error )
390
396
return ;
391
397
392
398
add_exception_dispatch_sequence (
@@ -462,7 +468,21 @@ void remove_exceptionst::instrument_exceptions(
462
468
463
469
Forall_goto_program_instructions (instr_it, goto_program)
464
470
{
465
- if (instr_it->is_decl ())
471
+ if (instr_it->is_assert ())
472
+ {
473
+ if (propagate_assertion_error)
474
+ {
475
+ // suppress user-provided assertion
476
+ // because we propgate the AssertionError
477
+ if (
478
+ instr_it->guard .is_false () &&
479
+ instr_it->source_location .get_bool (" user-provided" ))
480
+ {
481
+ instr_it->make_skip ();
482
+ }
483
+ }
484
+ }
485
+ else if (instr_it->is_decl ())
466
486
{
467
487
code_declt decl=to_code_decl (instr_it->code );
468
488
locals.push_back (decl.symbol ());
@@ -566,6 +586,7 @@ void remove_exceptionst::operator()(goto_programt &goto_program)
566
586
void remove_exceptions (
567
587
symbol_table_baset &symbol_table,
568
588
goto_functionst &goto_functions,
589
+ bool propagate_assertion_error,
569
590
remove_exceptions_typest type)
570
591
{
571
592
const namespacet ns (symbol_table);
@@ -578,6 +599,7 @@ void remove_exceptions(
578
599
remove_exceptionst remove_exceptions (
579
600
symbol_table,
580
601
function_may_throw,
602
+ propagate_assertion_error,
581
603
type == remove_exceptions_typest::REMOVE_ADDED_INSTANCEOF);
582
604
remove_exceptions (goto_functions);
583
605
}
@@ -598,6 +620,7 @@ void remove_exceptions(
598
620
void remove_exceptions (
599
621
goto_programt &goto_program,
600
622
symbol_table_baset &symbol_table,
623
+ bool propagate_assertion_error,
601
624
remove_exceptions_typest type)
602
625
{
603
626
remove_exceptionst::function_may_throwt any_function_may_throw =
@@ -606,12 +629,20 @@ void remove_exceptions(
606
629
remove_exceptionst remove_exceptions (
607
630
symbol_table,
608
631
any_function_may_throw,
632
+ propagate_assertion_error,
609
633
type == remove_exceptions_typest::REMOVE_ADDED_INSTANCEOF);
610
634
remove_exceptions (goto_program);
611
635
}
612
636
613
637
// / removes throws/CATCH-POP/CATCH-PUSH
614
- void remove_exceptions (goto_modelt &goto_model, remove_exceptions_typest type)
638
+ void remove_exceptions (
639
+ goto_modelt &goto_model,
640
+ bool propagate_assertion_error,
641
+ remove_exceptions_typest type)
615
642
{
616
- remove_exceptions (goto_model.symbol_table , goto_model.goto_functions , type);
643
+ remove_exceptions (
644
+ goto_model.symbol_table ,
645
+ goto_model.goto_functions ,
646
+ propagate_assertion_error,
647
+ type);
617
648
}
0 commit comments