-
Notifications
You must be signed in to change notification settings - Fork 273
Refactor runtime exception instrumentation #1019
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
72677f2
961c0a3
a6d1084
236e442
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,12 @@ | ||
public class ArrayIndexOutOfBoundsExceptionTest { | ||
public static void main(String args[]) { | ||
try { | ||
int[] a=new int[4]; | ||
a[4]=0; | ||
throw new RuntimeException(); | ||
} | ||
catch (ArrayIndexOutOfBoundsException exc) { | ||
assert false; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CORE | ||
ArrayIndexOutOfBoundsExceptionTest.class | ||
--java-throw-runtime-exceptions | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^.*assertion at file ArrayIndexOutOfBoundsExceptionTest.java line 9 function.*: FAILURE$ | ||
^VERIFICATION FAILED$ | ||
-- | ||
^warning: ignoring |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class ClassCastExceptionTest { | ||
public static void main(String args[]) { | ||
try { | ||
Object x = new Integer(0); | ||
String y = (String)x; | ||
throw new RuntimeException(); | ||
} | ||
catch (ClassCastException exc) { | ||
assert false; | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CORE | ||
ClassCastExceptionTest.class | ||
--java-throw-runtime-exceptions | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^.*assertion at file ClassCastExceptionTest.java line 9 function.*: FAILURE$ | ||
^VERIFICATION FAILED$ | ||
-- | ||
^warning: ignoring |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class A {} | ||
|
||
class B extends A {} | ||
|
||
class C extends B {} | ||
|
||
public class ClassCastExceptionTest { | ||
public static void main(String args[]) { | ||
try { | ||
A c = new C(); | ||
B b = (B)c; | ||
// TODO: an explicit throw is currently needed in order | ||
// for CBMC to convert the exception handler | ||
throw new RuntimeException(); | ||
} | ||
catch (ClassCastException exc) { | ||
assert false; | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
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. Aren't tests CCE1 and CCE2 identical? 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. Yes, they somehow were, thanks for noticing that. I've now replaced CCE2 by the one you suggest below (with C<:B<:A), if I understood it correctly. |
||
ClassCastExceptionTest.class | ||
--java-throw-runtime-exceptions | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class B extends RuntimeException {} | ||
|
||
class A { | ||
int i; | ||
} | ||
|
||
public class Test { | ||
public static void main(String args[]) { | ||
A a=null; | ||
try { | ||
a.i=0; | ||
// TODO: an explicit throw is currently needed in order | ||
// for CBMC to convert the exception handler | ||
throw new B(); | ||
} | ||
catch (NullPointerException exc) { | ||
assert false; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CORE | ||
Test.class | ||
--java-throw-runtime-exceptions | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^.*assertion at file Test.java line 17 function.*: FAILURE$ | ||
^VERIFICATION FAILED$ | ||
-- | ||
^warning: ignoring |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class B extends RuntimeException {} | ||
|
||
class A { | ||
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. How does this test differ from NPE2? 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. NPE2 uses putfield, whereas NPE3 uses getfield. They ultimately rely on the same code but I still wanted to check they are both good. |
||
int i; | ||
} | ||
|
||
public class Test { | ||
public static void main(String args[]) { | ||
A a=null; | ||
try { | ||
int i=a.i; | ||
// TODO: an explicit throw is currently needed in order | ||
// for CBMC to convert the exception handler | ||
throw new B(); | ||
} | ||
catch (NullPointerException exc) { | ||
assert false; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CORE | ||
Test.class | ||
--java-throw-runtime-exceptions | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^.*assertion at file Test.java line 17 function.*: FAILURE$ | ||
^VERIFICATION FAILED$ | ||
-- | ||
^warning: ignoring |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ Author: Daniel Kroening, [email protected] | |
#include "java_types.h" | ||
#include "java_bytecode_convert_method.h" | ||
#include "java_bytecode_language.h" | ||
#include "java_utils.h" | ||
|
||
#include <util/arith_tools.h> | ||
#include <util/namespace.h> | ||
|
@@ -56,7 +57,10 @@ class java_bytecode_convert_classt:public messaget | |
string_preprocess.add_string_type( | ||
parse_tree.parsed_class.name, symbol_table); | ||
else if(!loading_success) | ||
generate_class_stub(parse_tree.parsed_class.name); | ||
generate_class_stub( | ||
parse_tree.parsed_class.name, | ||
symbol_table, | ||
get_message_handler()); | ||
} | ||
|
||
typedef java_bytecode_parse_treet::classt classt; | ||
|
@@ -73,7 +77,6 @@ class java_bytecode_convert_classt:public messaget | |
void convert(const classt &c); | ||
void convert(symbolt &class_symbol, const fieldt &f); | ||
|
||
void generate_class_stub(const irep_idt &class_name); | ||
void add_array_types(); | ||
}; | ||
|
||
|
@@ -171,40 +174,6 @@ void java_bytecode_convert_classt::convert(const classt &c) | |
java_root_class(*class_symbol); | ||
} | ||
|
||
void java_bytecode_convert_classt::generate_class_stub( | ||
const irep_idt &class_name) | ||
{ | ||
class_typet class_type; | ||
|
||
class_type.set_tag(class_name); | ||
class_type.set(ID_base_name, class_name); | ||
|
||
class_type.set(ID_incomplete_class, true); | ||
|
||
// produce class symbol | ||
symbolt new_symbol; | ||
new_symbol.base_name=class_name; | ||
new_symbol.pretty_name=class_name; | ||
new_symbol.name="java::"+id2string(class_name); | ||
class_type.set(ID_name, new_symbol.name); | ||
new_symbol.type=class_type; | ||
new_symbol.mode=ID_java; | ||
new_symbol.is_type=true; | ||
|
||
symbolt *class_symbol; | ||
|
||
if(symbol_table.move(new_symbol, class_symbol)) | ||
{ | ||
warning() << "stub class symbol " << new_symbol.name | ||
<< " already exists" << eom; | ||
} | ||
else | ||
{ | ||
// create the class identifier etc | ||
java_root_class(*class_symbol); | ||
} | ||
} | ||
|
||
void java_bytecode_convert_classt::convert( | ||
symbolt &class_symbol, | ||
const fieldt &f) | ||
|
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.
Dodgy indentation, use spaces everywhere