Skip to content

Commit 9a1289d

Browse files
committed
Add overview documentation for remove-exceptions.
1 parent c11bba0 commit 9a1289d

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

src/cbmc/cbmc_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ bool cbmc_parse_optionst::process_goto_program(
815815
cmdline.isset("pointer-check"));
816816
// Java virtual functions -> explicit dispatch tables:
817817
remove_virtual_functions(symbol_table, goto_functions);
818-
// remove catch and throw
818+
// remove catch and throw (introduces instanceof)
819819
remove_exceptions(symbol_table, goto_functions);
820820
// Similar removal of RTTI inspection:
821821
remove_instanceof(symbol_table, goto_functions);

src/goto-analyzer/goto_analyzer_parse_options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ bool goto_analyzer_parse_optionst::process_goto_program(
356356
// Java virtual functions -> explicit dispatch tables:
357357
remove_virtual_functions(goto_model);
358358
// remove Java throw and catch
359+
// This introduces instanceof, so order is important:
359360
remove_exceptions(goto_model);
360361
// remove rtti
361362
remove_instanceof(goto_model);

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ void goto_instrument_parse_optionst::do_indirect_call_and_rtti_removal(
806806
status() << "Virtual function removal" << eom;
807807
remove_virtual_functions(symbol_table, goto_functions);
808808
status() << "Catch and throw removal" << eom;
809+
// This introduces instanceof, so order is important:
809810
remove_exceptions(symbol_table, goto_functions);
810811
status() << "Java instanceof removal" << eom;
811812
remove_instanceof(symbol_table, goto_functions);

src/goto-programs/remove_exceptions.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,54 @@ Date: December 2016
2727

2828
#include <analyses/uncaught_exceptions_analysis.h>
2929

30+
/// Lowers high-level exception descriptions into low-level operations suitable
31+
/// for symex and other analyses that don't understand the THROW or CATCH GOTO
32+
/// instructions.
33+
///
34+
/// The instructions affected by the lowering are:
35+
///
36+
/// THROW, whose operand must be a code_expressiont wrapping a
37+
/// side_effect_expr_throwt. This starts propagating an exception, aborting
38+
/// functions until a suitable catch point is found.
39+
///
40+
/// CATCH with a code_push_catcht operand, which commences a region in which
41+
/// exceptions should be caught, commonly a try block.
42+
/// It specifies one or more exception tags to handle
43+
/// (in instruction->code.exception_list()) and a corresponding GOTO program
44+
/// target for each (in instruction->targets).
45+
/// Thrown instructions are currently always matched to tags using
46+
/// java_instanceof, so a language frontend wanting to use this class
47+
/// must use exceptions with a Java-compatible structure.
48+
///
49+
/// CATCH with a code_pop_catcht operand terminates a try-block begun by
50+
/// a code_push_catcht. At present the try block consists of the instructions
51+
/// between the push and the pop *in program order*, not according to dynamic
52+
/// control flow, so goto_convert_exceptions must ensure that control-flow
53+
/// within the try block does not leave this range.
54+
///
55+
/// CATCH with a code_landingpadt operand marks a point where exceptional
56+
/// control flow terminates and normal control flow resumes, typically the top
57+
/// of a catch or finally block, and the target of a code_push_catcht
58+
/// describing the correponding try block. It gives an lvalue expression that
59+
/// should be assigned the caught exception, typically a local variable.
60+
///
61+
/// FUNCTION_CALL instructions are also affected: if the callee may abort
62+
/// due to an escaping instruction, a dispatch sequence is inserted to check
63+
/// whether the callee aborted and propagate the exception further if so.
64+
///
65+
/// Exception propagation is implemented using a global variable per function
66+
/// (named function_name#exception_value) that carries a reference to an
67+
/// in-flight exception, or is null during normal control flow.
68+
/// THROW assigns it a reference to the thrown instance; CALL instructions
69+
/// copy between the exception_value for the callee and caller, catch_push
70+
/// and catch_pop instructions indicate how they should be checked to dispatch
71+
/// the right exception type to the right catch block, and landingpad
72+
/// instructions copy back to an ordinary local variable (or other expression)
73+
/// and set #exception_value back to null, indicating the exception has been
74+
/// caught and normal control flow resumed.
75+
///
76+
/// Note that remove_exceptions introduces java_instanceof comparisons at
77+
/// present, so a remove_instanceof may be necessary after it completes.
3078
class remove_exceptionst
3179
{
3280
typedef std::vector<std::pair<

src/symex/symex_parse_options.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ bool symex_parse_optionst::process_goto_program(const optionst &options)
304304
// Java virtual functions -> explicit dispatch tables:
305305
remove_virtual_functions(goto_model);
306306
// Java throw and catch -> explicit exceptional return variables:
307+
// This introduces instanceof, so order is important:
307308
remove_exceptions(goto_model);
308309
// Java instanceof -> clsid comparison:
309310
remove_instanceof(goto_model);

0 commit comments

Comments
 (0)