Skip to content

Commit 53d89b1

Browse files
author
Daniel Kroening
authored
Merge pull request #490 from smowton/use_remove_instanceof
Use remove instanceof
2 parents 61d69a6 + 5195a0c commit 53d89b1

31 files changed

+159
-41
lines changed
-240 Bytes
Binary file not shown.

regression/cbmc-java/instanceof1/instanceof1.java

-12
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@ class instanceof1
22
{
33
public static void main(String[] args)
44
{
5-
// absolutely everything is an Object
65
assert args instanceof Object;
7-
assert int.class instanceof Object;
8-
9-
// args is an array
10-
assert args instanceof Object[];
11-
12-
// string literals are strings
13-
assert "" instanceof String;
14-
15-
// need a negative example, too
16-
Object o=new Object();
17-
assert ! (o instanceof String);
186
}
197
};
597 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class instanceof2
2+
{
3+
public static void main(String[] args)
4+
{
5+
assert int.class instanceof Object;
6+
}
7+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
KNOWNBUG
2+
instanceof2.class
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
560 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class instanceof3
2+
{
3+
public static void main(String[] args)
4+
{
5+
assert args instanceof Object[];
6+
}
7+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
KNOWNBUG
2+
instanceof3.class
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
564 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class instanceof4
2+
{
3+
public static void main(String[] args)
4+
{
5+
assert "" instanceof String;
6+
}
7+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
instanceof4.class
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
577 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class instanceof5
2+
{
3+
public static void main(String[] args)
4+
{
5+
Object o=new Object();
6+
assert ! (o instanceof String);
7+
}
8+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
instanceof5.class
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
186 Bytes
Binary file not shown.
171 Bytes
Binary file not shown.
633 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class instanceof6
2+
{
3+
public static void main(String[] args)
4+
{
5+
A[] as = { new A(), new B() };
6+
assert(as[0] instanceof A);
7+
assert(as[1] instanceof A);
8+
}
9+
};
10+
11+
class A {
12+
}
13+
14+
class B extends A {
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
instanceof6.class
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
186 Bytes
Binary file not shown.
171 Bytes
Binary file not shown.
633 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class instanceof7
2+
{
3+
public static void main(String[] args)
4+
{
5+
A[] as = { new A(), new B() };
6+
assert(!(as[0] instanceof B));
7+
assert(as[1] instanceof B);
8+
}
9+
};
10+
11+
class A {
12+
}
13+
14+
class B extends A {
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
instanceof7.class
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/cbmc/cbmc_parse_options.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Author: Daniel Kroening, [email protected]
2222
#include <goto-programs/goto_convert_functions.h>
2323
#include <goto-programs/remove_function_pointers.h>
2424
#include <goto-programs/remove_virtual_functions.h>
25+
#include <goto-programs/remove_instanceof.h>
2526
#include <goto-programs/remove_returns.h>
2627
#include <goto-programs/remove_vector.h>
2728
#include <goto-programs/remove_complex.h>
@@ -884,7 +885,10 @@ bool cbmc_parse_optionst::process_goto_program(
884885
symbol_table,
885886
goto_functions,
886887
cmdline.isset("pointer-check"));
888+
// Java virtual functions -> explicit dispatch tables:
887889
remove_virtual_functions(symbol_table, goto_functions);
890+
// Java instanceof -> clsid comparison:
891+
remove_instanceof(symbol_table, goto_functions);
888892

889893
// full slice?
890894
if(cmdline.isset("full-slice"))

src/goto-analyzer/goto_analyzer_parse_options.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Author: Daniel Kroening, [email protected]
1919
#include <goto-programs/set_properties.h>
2020
#include <goto-programs/remove_function_pointers.h>
2121
#include <goto-programs/remove_virtual_functions.h>
22+
#include <goto-programs/remove_instanceof.h>
2223
#include <goto-programs/remove_returns.h>
2324
#include <goto-programs/remove_vector.h>
2425
#include <goto-programs/remove_complex.h>
@@ -380,7 +381,10 @@ bool goto_analyzer_parse_optionst::process_goto_program(
380381
// remove function pointers
381382
status() << "Removing function pointers and virtual functions" << eom;
382383
remove_function_pointers(goto_model, cmdline.isset("pointer-check"));
384+
// Java virtual functions -> explicit dispatch tables:
383385
remove_virtual_functions(goto_model);
386+
// Java instanceof -> clsid comparison:
387+
remove_instanceof(goto_model);
384388

385389
// do partial inlining
386390
status() << "Partial Inlining" << eom;

0 commit comments

Comments
 (0)