Skip to content

Commit 2c29180

Browse files
authored
Merge pull request #1096 from cristina-david/feature/consider-implicit-exceptions-when-building-cfg
Consider Java implicit exceptions when building the CFG
2 parents db0b1f2 + 85b2a6d commit 2c29180

20 files changed

+50
-15
lines changed

regression/cbmc-java/ArrayIndexOutOfBoundsException1/ArrayIndexOutOfBoundsExceptionTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ public static void main(String args[]) {
33
try {
44
int[] a=new int[4];
55
a[4]=0;
6-
throw new RuntimeException();
76
}
87
catch (ArrayIndexOutOfBoundsException exc) {
98
assert false;

regression/cbmc-java/ArrayIndexOutOfBoundsException1/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ArrayIndexOutOfBoundsExceptionTest.class
33
--java-throw-runtime-exceptions
44
^EXIT=10$
55
^SIGNAL=0$
6-
^.*assertion at file ArrayIndexOutOfBoundsExceptionTest.java line 9 function.*: FAILURE$
6+
^.*assertion at file ArrayIndexOutOfBoundsExceptionTest.java line 8 function.*: FAILURE$
77
^VERIFICATION FAILED$
88
--
99
^warning: ignoring
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class ArrayIndexOutOfBoundsExceptionTest {
2+
public static void main(String args[]) {
3+
try {
4+
int[] a=new int[4];
5+
int i=a[5];
6+
}
7+
catch (ArrayIndexOutOfBoundsException exc) {
8+
assert false;
9+
}
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
ArrayIndexOutOfBoundsExceptionTest.class
3+
--java-throw-runtime-exceptions
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^.*assertion at file ArrayIndexOutOfBoundsExceptionTest.java line 8 function.*: FAILURE$
7+
^VERIFICATION FAILED$
8+
--
9+
^warning: ignoring
Binary file not shown.

regression/cbmc-java/ClassCastException1/ClassCastExceptionTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ public static void main(String args[]) {
33
try {
44
Object x = new Integer(0);
55
String y = (String)x;
6-
throw new RuntimeException();
76
}
87
catch (ClassCastException exc) {
98
assert false;

regression/cbmc-java/ClassCastException1/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ClassCastExceptionTest.class
33
--java-throw-runtime-exceptions
44
^EXIT=10$
55
^SIGNAL=0$
6-
^.*assertion at file ClassCastExceptionTest.java line 9 function.*: FAILURE$
6+
^.*assertion at file ClassCastExceptionTest.java line 8 function.*: FAILURE$
77
^VERIFICATION FAILED$
88
--
99
^warning: ignoring

regression/cbmc-java/ClassCastException2/ClassCastExceptionTest.java

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ public static void main(String args[]) {
99
try {
1010
A c = new C();
1111
B b = (B)c;
12-
// TODO: an explicit throw is currently needed in order
13-
// for CBMC to convert the exception handler
14-
throw new RuntimeException();
1512
}
1613
catch (ClassCastException exc) {
1714
assert false;
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public class NegativeArraySizeExceptionTest {
2+
public static void main(String args[]) {
3+
try {
4+
int a[]=new int[-1];
5+
}
6+
catch (NegativeArraySizeException exc) {
7+
assert false;
8+
}
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
NegativeArraySizeExceptionTest.class
3+
--java-throw-runtime-exceptions
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^.*assertion at file NegativeArraySizeExceptionTest.java line 7 function.*: FAILURE$
7+
^VERIFICATION FAILED$
8+
--
9+
^warning: ignoring
Binary file not shown.

regression/cbmc-java/NullPointerException2/Test.java

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ public static void main(String args[]) {
99
A a=null;
1010
try {
1111
a.i=0;
12-
// TODO: an explicit throw is currently needed in order
13-
// for CBMC to convert the exception handler
14-
throw new B();
1512
}
1613
catch (NullPointerException exc) {
1714
assert false;

regression/cbmc-java/NullPointerException2/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Test.class
33
--java-throw-runtime-exceptions
44
^EXIT=10$
55
^SIGNAL=0$
6-
^.*assertion at file Test.java line 17 function.*: FAILURE$
6+
^.*assertion at file Test.java line 14 function.*: FAILURE$
77
^VERIFICATION FAILED$
88
--
99
^warning: ignoring
Binary file not shown.

regression/cbmc-java/NullPointerException3/Test.java

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ public static void main(String args[]) {
99
A a=null;
1010
try {
1111
int i=a.i;
12-
// TODO: an explicit throw is currently needed in order
13-
// for CBMC to convert the exception handler
14-
throw new B();
1512
}
1613
catch (NullPointerException exc) {
1714
assert false;

regression/cbmc-java/NullPointerException3/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Test.class
33
--java-throw-runtime-exceptions
44
^EXIT=10$
55
^SIGNAL=0$
6-
^.*assertion at file Test.java line 17 function.*: FAILURE$
6+
^.*assertion at file Test.java line 14 function.*: FAILURE$
77
^VERIFICATION FAILED$
88
--
99
^warning: ignoring

src/java_bytecode/java_bytecode_convert_method.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,13 @@ codet java_bytecode_convert_methodt::convert_instructions(
10461046
}
10471047

10481048
if(i_it->statement=="athrow" ||
1049+
i_it->statement=="putfield" ||
1050+
i_it->statement=="getfield" ||
1051+
i_it->statement=="checkcast" ||
1052+
i_it->statement=="newarray" ||
1053+
i_it->statement=="anewarray" ||
1054+
i_it->statement==patternt("?astore") ||
1055+
i_it->statement==patternt("?aload") ||
10491056
i_it->statement=="invokestatic" ||
10501057
i_it->statement=="invokevirtual" ||
10511058
i_it->statement=="invokespecial" ||

0 commit comments

Comments
 (0)