-
Notifications
You must be signed in to change notification settings - Fork 273
JBMC report FAILURE on uncaught exception #2043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
55bdbc7
04c0205
07acde4
653d887
cd2ef4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
assert3.class | ||
--throw-assertion-error --disable-uncaught-exception-check | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Test | ||
{ | ||
public static void main(String[] args) | ||
{ | ||
AssertionError a = new AssertionError(); | ||
if(false) | ||
throw a; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
Test.class | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
CORE | ||
catch1.class | ||
|
||
^EXIT=0$ | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
^VERIFICATION FAILED$ | ||
^\[.*\] no uncaught exception: FAILURE$ | ||
-- | ||
^warning: ignoring |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
catch1.class | ||
--disable-uncaught-exception-check | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
CORE | ||
Test.class | ||
--function Test.goo | ||
^EXIT=0$ | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
^VERIFICATION FAILED$ | ||
no uncaught exception: FAILURE | ||
-- | ||
^warning: ignoring |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,11 +32,14 @@ Author: Daniel Kroening, [email protected] | |
#include <util/simplify_expr.h> | ||
#include <util/std_expr.h> | ||
#include <util/string2int.h> | ||
#include <util/string_constant.h> | ||
|
||
#include <goto-programs/cfg.h> | ||
#include <goto-programs/class_hierarchy.h> | ||
#include <goto-programs/resolve_inherited_component.h> | ||
|
||
#include <analyses/cfg_dominators.h> | ||
#include <analyses/uncaught_exceptions_analysis.h> | ||
|
||
#include <limits> | ||
#include <algorithm> | ||
|
@@ -2248,10 +2251,40 @@ void java_bytecode_convert_methodt::convert_athrow( | |
codet &c, | ||
exprt::operandst &results) const | ||
{ | ||
side_effect_expr_throwt throw_expr; | ||
throw_expr.add_source_location() = location; | ||
throw_expr.copy_to_operands(op[0]); | ||
c = code_expressiont(throw_expr); | ||
if( | ||
!throw_assertion_error && | ||
uncaught_exceptions_domaint::get_exception_type(op[0].type()) == | ||
"java::java.lang.AssertionError") | ||
{ | ||
// we translate athrow into | ||
// ASSERT false; | ||
// ASSUME false: | ||
code_assertt assert_code; | ||
assert_code.assertion() = false_exprt(); | ||
source_locationt assert_location = location; // copy | ||
assert_location.set_comment("assertion at " + location.as_string()); | ||
assert_location.set("user-provided", true); | ||
assert_location.set_property_class(ID_assertion); | ||
assert_code.add_source_location() = assert_location; | ||
|
||
code_assumet assume_code; | ||
assume_code.assumption() = false_exprt(); | ||
source_locationt assume_location = location; // copy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above: why copy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
assume_location.set("user-provided", true); | ||
assume_code.add_source_location() = assume_location; | ||
|
||
code_blockt ret_block; | ||
ret_block.move_to_operands(assert_code); | ||
ret_block.move_to_operands(assume_code); | ||
c = ret_block; | ||
} | ||
else | ||
{ | ||
side_effect_expr_throwt throw_expr; | ||
throw_expr.add_source_location() = location; | ||
throw_expr.copy_to_operands(op[0]); | ||
c = code_expressiont(throw_expr); | ||
} | ||
results[0] = op[0]; | ||
} | ||
|
||
|
@@ -3055,6 +3088,7 @@ void java_bytecode_convert_method( | |
symbol_table_baset &symbol_table, | ||
message_handlert &message_handler, | ||
size_t max_array_length, | ||
bool throw_assertion_error, | ||
optionalt<ci_lazy_methods_neededt> needed_lazy_methods, | ||
java_string_library_preprocesst &string_preprocess, | ||
const class_hierarchyt &class_hierarchy) | ||
|
@@ -3073,6 +3107,7 @@ void java_bytecode_convert_method( | |
symbol_table, | ||
message_handler, | ||
max_array_length, | ||
throw_assertion_error, | ||
needed_lazy_methods, | ||
string_preprocess, | ||
class_hierarchy); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ Date: June 2017 | |
#include <goto-programs/goto_functions.h> | ||
|
||
#include "java_bytecode_convert_class.h" | ||
#include "java_entry_point.h" | ||
#include "java_utils.h" | ||
|
||
class java_bytecode_instrumentt:public messaget | ||
|
@@ -592,6 +593,27 @@ void java_bytecode_instrument_symbol( | |
instrument(to_code(symbol.value)); | ||
} | ||
|
||
/// Instruments the start function with an assertion that checks whether | ||
/// an exception has escaped the entry point | ||
/// \param init_code: the code block to which the assertion is appended | ||
/// \param exc_symbol: the top-level exception symbol | ||
/// \param source_location: the source location to attach to the assertion | ||
void java_bytecode_instrument_uncaught_exceptions( | ||
codet &init_code, | ||
const symbolt &exc_symbol, | ||
const source_locationt &source_location) | ||
{ | ||
// check that there is no uncaught exception | ||
code_assertt assert_no_exception; | ||
assert_no_exception.assertion() = equal_exprt( | ||
exc_symbol.symbol_expr(), | ||
null_pointer_exprt(to_pointer_type(exc_symbol.type))); | ||
source_locationt assert_location = source_location; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there actual value in this temporary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's shorter than |
||
assert_location.set_comment("no uncaught exception"); | ||
assert_no_exception.add_source_location() = assert_location; | ||
init_code.move_to_operands(assert_no_exception); | ||
} | ||
|
||
/// Instruments all the code in the symbol_table with | ||
/// runtime exceptions or corresponding assertions. | ||
/// Exceptions are thrown when the `throw_runtime_exceptions` flag is set. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this copy good for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we use
location
as the basis for a modified source location.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: either explain that in the comment, or delete the comment (saying copy afterwards just invites the question)