File tree 4 files changed +28
-2
lines changed
regression/cbmc-java/instanceof8
4 files changed +28
-2
lines changed Original file line number Diff line number Diff line change
1
+ public class InstanceOf8 {
2
+ public static boolean test (Integer i ) {
3
+ if (i instanceof Integer ) {
4
+ return true ;
5
+ } else {
6
+ return false ;
7
+ }
8
+ }
9
+ public static void main (String [] args )
10
+ {
11
+ assert (!test (null ));
12
+ assert (test (new Integer (1 )));
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ InstanceOf8.class
3
+
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION SUCCESSFUL$
7
+ --
Original file line number Diff line number Diff line change @@ -113,15 +113,20 @@ std::size_t remove_instanceoft::lower_instanceof(
113
113
newinst->source_location =this_inst->source_location ;
114
114
newinst->function =this_inst->function ;
115
115
116
- // Replace the instanceof construct with a big-or.
116
+ // Replace the instanceof construct with a conjunction of non-null and the
117
+ // disjunction of all possible object types. According to the Java
118
+ // specification, null instanceof T is false for all possible values of T.
119
+ // (http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.20.2)
120
+ notequal_exprt non_null_expr (
121
+ check_ptr, null_pointer_exprt (to_pointer_type (check_ptr.type ())));
117
122
exprt::operandst or_ops;
118
123
for (const auto &clsname : children)
119
124
{
120
125
constant_exprt clsexpr (clsname, string_typet ());
121
126
equal_exprt test (newsym.symbol_expr (), clsexpr);
122
127
or_ops.push_back (test);
123
128
}
124
- expr= disjunction (or_ops);
129
+ expr = and_exprt (non_null_expr, disjunction (or_ops) );
125
130
126
131
return 1 ;
127
132
}
You can’t perform that action at this time.
0 commit comments