File tree 1 file changed +14
-4
lines changed
1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -1368,10 +1368,20 @@ codet java_bytecode_convert_methodt::convert_instructions(
1368
1368
// TODO: convert assertions to exceptions.
1369
1369
assert (op.size ()==1 && results.size ()==1 );
1370
1370
binary_predicate_exprt check (op[0 ], ID_java_instanceof, arg0);
1371
- c=code_assertt (check);
1372
- c.add_source_location ().set_comment (" Dynamic cast check" );
1373
- c.add_source_location ().set_property_class (" bad-dynamic-cast" );
1374
-
1371
+ code_assertt assert_class (check);
1372
+ assert_class.add_source_location ().set_comment (" Dynamic cast check" );
1373
+ assert_class.add_source_location ().set_property_class (" bad-dynamic-cast" );
1374
+ // checkcast passes when the operand is null.
1375
+ empty_typet voidt;
1376
+ pointer_typet voidptr (voidt);
1377
+ exprt null_check_op=op[0 ];
1378
+ if (null_check_op.type ()!=voidptr)
1379
+ null_check_op.make_typecast (voidptr);
1380
+ code_ifthenelset conditional_check;
1381
+ notequal_exprt op_not_null (null_check_op, null_pointer_exprt (voidptr));
1382
+ conditional_check.cond ()=std::move (op_not_null);
1383
+ conditional_check.then_case ()=std::move (assert_class);
1384
+ c=std::move (conditional_check);
1375
1385
results[0 ]=op[0 ];
1376
1386
}
1377
1387
else if (statement==" invokedynamic" )
You can’t perform that action at this time.
0 commit comments