@@ -200,26 +200,30 @@ codet java_bytecode_instrumentt::check_class_cast(
200
200
exprt null_check_op=class1;
201
201
if (null_check_op.type ()!=voidptr)
202
202
null_check_op.make_typecast (voidptr);
203
- notequal_exprt op_not_null (null_check_op, null_pointer_exprt (voidptr));
204
-
205
- // checkcast passes when the operand is null
206
- and_exprt and_expr (op_not_null, not_exprt (class_cast_check));
207
203
204
+ codet check_code;
208
205
if (throw_runtime_exceptions)
209
- return throw_exception (
210
- and_expr,
211
- original_loc,
212
- " ClassCastException" );
213
-
214
- code_assertt assert_class (class_cast_check);
215
- assert_class.add_source_location ().
216
- set_comment (" Dynamic cast check" );
217
- assert_class.add_source_location ().
218
- set_property_class (" bad-dynamic-cast" );
206
+ {
207
+ check_code=
208
+ throw_exception (
209
+ not_exprt (class_cast_check),
210
+ original_loc,
211
+ " ClassCastException" );
212
+ }
213
+ else
214
+ {
215
+ code_assertt assert_class (class_cast_check);
216
+ assert_class.add_source_location ().
217
+ set_comment (" Dynamic cast check" );
218
+ assert_class.add_source_location ().
219
+ set_property_class (" bad-dynamic-cast" );
220
+ check_code=std::move (assert_class);
221
+ }
219
222
220
223
code_ifthenelset conditional_check;
224
+ notequal_exprt op_not_null (null_check_op, null_pointer_exprt (voidptr));
221
225
conditional_check.cond ()=std::move (op_not_null);
222
- conditional_check.then_case ()=std::move (assert_class );
226
+ conditional_check.then_case ()=std::move (check_code );
223
227
return conditional_check;
224
228
}
225
229
@@ -328,7 +332,7 @@ void java_bytecode_instrumentt::instrument_code(exprt &expr)
328
332
}
329
333
else if (statement==ID_assert)
330
334
{
331
- code_assertt code_assert=to_code_assert (code);
335
+ const code_assertt & code_assert=to_code_assert (code);
332
336
333
337
// does this correspond to checkcast?
334
338
if (code_assert.assertion ().id ()==ID_java_instanceof)
@@ -339,13 +343,11 @@ void java_bytecode_instrumentt::instrument_code(exprt &expr)
339
343
code_assert.assertion ().operands ().size ()==2 ,
340
344
" Instanceof should have 2 operands" );
341
345
342
- block. copy_to_operands (
346
+ code=
343
347
check_class_cast (
344
348
code_assert.assertion ().op0 (),
345
349
code_assert.assertion ().op1 (),
346
- code_assert.source_location ()));
347
- block.copy_to_operands (code_assert);
348
- code=block;
350
+ code_assert.source_location ());
349
351
}
350
352
}
351
353
else if (statement==ID_block)
0 commit comments