@@ -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,18 @@ 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 because we propgate the AssertionError
476
+ if (
477
+ instr_it->guard .is_false () &&
478
+ instr_it->source_location .get_bool (" user-provided" ))
479
+ instr_it->make_skip ();
480
+ }
481
+ }
482
+ else if (instr_it->is_decl ())
466
483
{
467
484
code_declt decl=to_code_decl (instr_it->code );
468
485
locals.push_back (decl.symbol ());
@@ -566,6 +583,7 @@ void remove_exceptionst::operator()(goto_programt &goto_program)
566
583
void remove_exceptions (
567
584
symbol_table_baset &symbol_table,
568
585
goto_functionst &goto_functions,
586
+ bool propagate_assertion_error,
569
587
remove_exceptions_typest type)
570
588
{
571
589
const namespacet ns (symbol_table);
@@ -578,6 +596,7 @@ void remove_exceptions(
578
596
remove_exceptionst remove_exceptions (
579
597
symbol_table,
580
598
function_may_throw,
599
+ propagate_assertion_error,
581
600
type == remove_exceptions_typest::REMOVE_ADDED_INSTANCEOF);
582
601
remove_exceptions (goto_functions);
583
602
}
@@ -598,6 +617,7 @@ void remove_exceptions(
598
617
void remove_exceptions (
599
618
goto_programt &goto_program,
600
619
symbol_table_baset &symbol_table,
620
+ bool propagate_assertion_error,
601
621
remove_exceptions_typest type)
602
622
{
603
623
remove_exceptionst::function_may_throwt any_function_may_throw =
@@ -606,12 +626,20 @@ void remove_exceptions(
606
626
remove_exceptionst remove_exceptions (
607
627
symbol_table,
608
628
any_function_may_throw,
629
+ propagate_assertion_error,
609
630
type == remove_exceptions_typest::REMOVE_ADDED_INSTANCEOF);
610
631
remove_exceptions (goto_program);
611
632
}
612
633
613
634
// / removes throws/CATCH-POP/CATCH-PUSH
614
- void remove_exceptions (goto_modelt &goto_model, remove_exceptions_typest type)
635
+ void remove_exceptions (
636
+ goto_modelt &goto_model,
637
+ bool propagate_assertion_error,
638
+ remove_exceptions_typest type)
615
639
{
616
- remove_exceptions (goto_model.symbol_table , goto_model.goto_functions , type);
640
+ remove_exceptions (
641
+ goto_model.symbol_table ,
642
+ goto_model.goto_functions ,
643
+ propagate_assertion_error,
644
+ type);
617
645
}
0 commit comments