Skip to content

Commit 58ded62

Browse files
author
Owen
committed
Ensure no exception handling in __CPROVER_initialize
__CPROVER_initialize should not contain any exception handling branches for two reasons: (1) with symex-driven lazy loading it means that code that references @inflight_exception might be generated before @inflight_exception is initialized; (2) symex can analyze INITIALIZE_FUNCTION much faster if it doesn't contain any branching.
1 parent fbe5196 commit 58ded62

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

jbmc/src/java_bytecode/remove_exceptions.cpp

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Date: December 2016
3030

3131
#include <analyses/uncaught_exceptions_analysis.h>
3232

33+
#include <linking/static_lifetime_init.h>
34+
3335
#include "java_types.h"
3436

3537
/// Lowers high-level exception descriptions into low-level operations suitable
@@ -119,6 +121,13 @@ class remove_exceptionst
119121
bool remove_added_instanceof;
120122
message_handlert &message_handler;
121123

124+
enum class instrumentation_resultt
125+
{
126+
DID_NOTHING,
127+
ADDED_CODE_WITHOUT_MAY_THROW,
128+
ADDED_CODE_WITH_MAY_THROW,
129+
};
130+
122131
symbol_exprt get_inflight_exception_global();
123132

124133
bool function_or_callees_may_throw(const goto_programt &) const;
@@ -148,7 +157,7 @@ class remove_exceptionst
148157
const stack_catcht &,
149158
const std::vector<symbol_exprt> &);
150159

151-
bool instrument_function_call(
160+
instrumentation_resultt instrument_function_call(
152161
const irep_idt &function_identifier,
153162
goto_programt &goto_program,
154163
const goto_programt::targett &,
@@ -421,7 +430,8 @@ bool remove_exceptionst::instrument_throw(
421430

422431
/// instruments each function call that may escape exceptions with conditional
423432
/// GOTOS to the corresponding exception handlers
424-
bool remove_exceptionst::instrument_function_call(
433+
remove_exceptionst::instrumentation_resultt
434+
remove_exceptionst::instrument_function_call(
425435
const irep_idt &function_identifier,
426436
goto_programt &goto_program,
427437
const goto_programt::targett &instr_it,
@@ -455,6 +465,8 @@ bool remove_exceptionst::instrument_function_call(
455465
goto_program.insert_after(
456466
instr_it,
457467
goto_programt::make_assumption(no_exception_currently_in_flight));
468+
469+
return instrumentation_resultt::ADDED_CODE_WITHOUT_MAY_THROW;
458470
}
459471
else
460472
{
@@ -468,12 +480,12 @@ bool remove_exceptionst::instrument_function_call(
468480
next_it,
469481
no_exception_currently_in_flight,
470482
instr_it->source_location));
471-
}
472483

473-
return true;
484+
return instrumentation_resultt::ADDED_CODE_WITH_MAY_THROW;
485+
}
474486
}
475487

476-
return false;
488+
return instrumentation_resultt::DID_NOTHING;
477489
}
478490

479491
/// instruments throws, function calls that may escape exceptions and exception
@@ -494,6 +506,7 @@ void remove_exceptionst::instrument_exceptions(
494506
function_or_callees_may_throw(goto_program);
495507

496508
bool did_something = false;
509+
bool added_goto_instruction = false;
497510

498511
Forall_goto_program_instructions(instr_it, goto_program)
499512
{
@@ -577,16 +590,29 @@ void remove_exceptionst::instrument_exceptions(
577590
}
578591
else if(instr_it->type==THROW)
579592
{
580-
did_something |= instrument_throw(
593+
did_something = instrument_throw(
581594
function_identifier, goto_program, instr_it, stack_catch, locals);
582595
}
583596
else if(instr_it->type==FUNCTION_CALL)
584597
{
585-
did_something |= instrument_function_call(
586-
function_identifier, goto_program, instr_it, stack_catch, locals);
598+
instrumentation_resultt result =
599+
instrument_function_call(
600+
function_identifier, goto_program, instr_it, stack_catch, locals);
601+
did_something = result != instrumentation_resultt::DID_NOTHING;
602+
added_goto_instruction =
603+
result == instrumentation_resultt::ADDED_CODE_WITH_MAY_THROW;
587604
}
588605
}
589606

607+
// INITIALIZE_FUNCTION should not contain any exception handling branches for
608+
// two reasons: (1) with symex-driven lazy loading it means that code that
609+
// references @inflight_exception might be generated before
610+
// @inflight_exception is initialized; (2) symex can analyze
611+
// INITIALIZE_FUNCTION much faster if it doesn't contain any branching.
612+
INVARIANT(
613+
function_identifier != INITIALIZE_FUNCTION || !added_goto_instruction,
614+
INITIALIZE_FUNCTION " should not contain any exception handling branches");
615+
590616
if(did_something)
591617
remove_skip(goto_program);
592618
}

0 commit comments

Comments
 (0)