@@ -88,9 +88,11 @@ class remove_exceptionst
88
88
explicit remove_exceptionst (
89
89
symbol_table_baset &_symbol_table,
90
90
function_may_throwt _function_may_throw,
91
+ bool propagate_assertion_error,
91
92
bool remove_added_instanceof)
92
93
: symbol_table(_symbol_table),
93
94
function_may_throw(_function_may_throw),
95
+ propagate_assertion_error(propagate_assertion_error),
94
96
remove_added_instanceof(remove_added_instanceof)
95
97
{
96
98
}
@@ -101,6 +103,7 @@ class remove_exceptionst
101
103
protected:
102
104
symbol_table_baset &symbol_table;
103
105
function_may_throwt function_may_throw;
106
+ bool propagate_assertion_error;
104
107
bool remove_added_instanceof;
105
108
106
109
symbol_exprt get_inflight_exception_global ();
@@ -164,6 +167,9 @@ bool remove_exceptionst::function_or_callees_may_throw(
164
167
{
165
168
if (instr_it->is_throw ())
166
169
{
170
+ if (propagate_assertion_error)
171
+ return true ;
172
+
167
173
const exprt &exc =
168
174
uncaught_exceptions_domaint::get_exception_symbol (instr_it->code );
169
175
bool is_assertion_error =
@@ -385,10 +391,10 @@ bool remove_exceptionst::instrument_throw(
385
391
uncaught_exceptions_domaint::get_exception_type (exc_expr.type ())).
386
392
find (" java.lang.AssertionError" )!=std::string::npos;
387
393
388
- // we don't count AssertionError (we couldn't catch it anyway
389
- // and this may reduce the instrumentation considerably if the programmer
390
- // used assertions)
391
- if (assertion_error)
394
+ // we allow AssertionError not to be propagated since
395
+ // this may reduce the instrumentation considerably if the programmer
396
+ // used assertions
397
+ if (assertion_error && !propagate_assertion_error )
392
398
return false ;
393
399
394
400
add_exception_dispatch_sequence (
@@ -472,7 +478,21 @@ void remove_exceptionst::instrument_exceptions(
472
478
473
479
Forall_goto_program_instructions (instr_it, goto_program)
474
480
{
475
- if (instr_it->is_decl ())
481
+ if (instr_it->is_assert ())
482
+ {
483
+ if (propagate_assertion_error)
484
+ {
485
+ // suppress user-provided assertion
486
+ // because we propgate the AssertionError
487
+ if (
488
+ instr_it->guard .is_false () &&
489
+ instr_it->source_location .get_bool (" user-provided" ))
490
+ {
491
+ instr_it->make_skip ();
492
+ }
493
+ }
494
+ }
495
+ else if (instr_it->is_decl ())
476
496
{
477
497
code_declt decl=to_code_decl (instr_it->code );
478
498
locals.push_back (decl.symbol ());
@@ -580,18 +600,21 @@ void remove_exceptionst::operator()(goto_programt &goto_program)
580
600
void remove_exceptions (
581
601
symbol_table_baset &symbol_table,
582
602
goto_functionst &goto_functions,
603
+ bool propagate_assertion_error,
583
604
remove_exceptions_typest type)
584
605
{
585
606
const namespacet ns (symbol_table);
586
607
std::map<irep_idt, std::set<irep_idt>> exceptions_map;
587
- uncaught_exceptions (goto_functions, ns, exceptions_map);
608
+ uncaught_exceptions (
609
+ goto_functions, ns, propagate_assertion_error, exceptions_map);
588
610
remove_exceptionst::function_may_throwt function_may_throw =
589
611
[&exceptions_map](const irep_idt &id) {
590
612
return !exceptions_map[id].empty ();
591
613
};
592
614
remove_exceptionst remove_exceptions (
593
615
symbol_table,
594
616
function_may_throw,
617
+ propagate_assertion_error,
595
618
type == remove_exceptions_typest::REMOVE_ADDED_INSTANCEOF);
596
619
remove_exceptions (goto_functions);
597
620
}
@@ -612,6 +635,7 @@ void remove_exceptions(
612
635
void remove_exceptions (
613
636
goto_programt &goto_program,
614
637
symbol_table_baset &symbol_table,
638
+ bool propagate_assertion_error,
615
639
remove_exceptions_typest type)
616
640
{
617
641
remove_exceptionst::function_may_throwt any_function_may_throw =
@@ -620,12 +644,20 @@ void remove_exceptions(
620
644
remove_exceptionst remove_exceptions (
621
645
symbol_table,
622
646
any_function_may_throw,
647
+ propagate_assertion_error,
623
648
type == remove_exceptions_typest::REMOVE_ADDED_INSTANCEOF);
624
649
remove_exceptions (goto_program);
625
650
}
626
651
627
652
// / removes throws/CATCH-POP/CATCH-PUSH
628
- void remove_exceptions (goto_modelt &goto_model, remove_exceptions_typest type)
653
+ void remove_exceptions (
654
+ goto_modelt &goto_model,
655
+ bool propagate_assertion_error,
656
+ remove_exceptions_typest type)
629
657
{
630
- remove_exceptions (goto_model.symbol_table , goto_model.goto_functions , type);
658
+ remove_exceptions (
659
+ goto_model.symbol_table ,
660
+ goto_model.goto_functions ,
661
+ propagate_assertion_error,
662
+ type);
631
663
}
0 commit comments