@@ -509,39 +509,14 @@ static member_exprt to_member(const exprt &pointer, const exprt &fieldref)
509
509
510
510
const dereference_exprt obj_deref (pointer2, class_type);
511
511
512
- return member_exprt (
512
+ member_exprt member_expr (
513
513
obj_deref,
514
514
fieldref.get (ID_component_name),
515
515
fieldref.type ());
516
- }
517
516
518
- codet java_bytecode_convert_methodt::get_array_bounds_check (
519
- const exprt &arraystruct,
520
- const exprt &idx,
521
- const source_locationt &original_sloc)
522
- {
523
- constant_exprt intzero=from_integer (0 , java_int_type ());
524
- binary_relation_exprt gezero (idx, ID_ge, intzero);
525
- const member_exprt length_field (arraystruct, " length" , java_int_type ());
526
- binary_relation_exprt ltlength (idx, ID_lt, length_field);
527
- code_blockt bounds_checks;
528
-
529
- bounds_checks.add (code_assertt (gezero));
530
- bounds_checks.operands ().back ().add_source_location ()=original_sloc;
531
- bounds_checks.operands ().back ().add_source_location ()
532
- .set_comment (" Array index < 0" );
533
- bounds_checks.operands ().back ().add_source_location ()
534
- .set_property_class (" array-index-out-of-bounds-low" );
535
- bounds_checks.add (code_assertt (ltlength));
536
-
537
- bounds_checks.operands ().back ().add_source_location ()=original_sloc;
538
- bounds_checks.operands ().back ().add_source_location ()
539
- .set_comment (" Array index >= length" );
540
- bounds_checks.operands ().back ().add_source_location ()
541
- .set_property_class (" array-index-out-of-bounds-high" );
542
-
543
- // TODO make this throw ArrayIndexOutOfBoundsException instead of asserting.
544
- return bounds_checks;
517
+ // tag it so it's easy to identify during instrumentation
518
+ member_expr.set (ID_java_member_access, true );
519
+ return member_expr;
545
520
}
546
521
547
522
// / Find all goto statements in 'repl' that target 'old_label' and redirect them
@@ -1256,50 +1231,26 @@ codet java_bytecode_convert_methodt::convert_instructions(
1256
1231
else if (statement==" athrow" )
1257
1232
{
1258
1233
assert (op.size ()==1 && results.size ()==1 );
1259
- code_blockt block;
1260
- // TODO throw NullPointerException instead
1261
- const typecast_exprt lhs (op[0 ], pointer_typet (empty_typet ()));
1262
- const exprt rhs (null_pointer_exprt (to_pointer_type (lhs.type ())));
1263
- const exprt not_equal_null (
1264
- binary_relation_exprt (lhs, ID_notequal, rhs));
1265
- code_assertt check (not_equal_null);
1266
- check.add_source_location ()
1267
- .set_comment (" Throw null" );
1268
- check.add_source_location ()
1269
- .set_property_class (" null-pointer-exception" );
1270
- block.move_to_operands (check);
1271
1234
1272
1235
side_effect_expr_throwt throw_expr;
1273
1236
throw_expr.add_source_location ()=i_it->source_location ;
1274
1237
throw_expr.copy_to_operands (op[0 ]);
1275
1238
c=code_expressiont (throw_expr);
1276
1239
results[0 ]=op[0 ];
1277
-
1278
- block.move_to_operands (c);
1279
- c=block;
1280
1240
}
1281
1241
else if (statement==" checkcast" )
1282
1242
{
1283
1243
// checkcast throws an exception in case a cast of object
1284
1244
// on stack to given type fails.
1285
1245
// The stack isn't modified.
1286
- // TODO: convert assertions to exceptions.
1287
1246
assert (op.size ()==1 && results.size ()==1 );
1288
1247
binary_predicate_exprt check (op[0 ], ID_java_instanceof, arg0);
1289
1248
code_assertt assert_class (check);
1290
1249
assert_class.add_source_location ().set_comment (" Dynamic cast check" );
1291
1250
assert_class.add_source_location ().set_property_class (" bad-dynamic-cast" );
1292
- // checkcast passes when the operand is null.
1293
- empty_typet voidt;
1294
- pointer_typet voidptr (voidt);
1295
- exprt null_check_op=op[0 ];
1296
- if (null_check_op.type ()!=voidptr)
1297
- null_check_op.make_typecast (voidptr);
1298
- code_ifthenelset conditional_check;
1299
- notequal_exprt op_not_null (null_check_op, null_pointer_exprt (voidptr));
1300
- conditional_check.cond ()=std::move (op_not_null);
1301
- conditional_check.then_case ()=std::move (assert_class);
1302
- c=std::move (conditional_check);
1251
+ // we add this assert such that we can recognise it
1252
+ // during the instrumentation phase
1253
+ c=std::move (assert_class);
1303
1254
results[0 ]=op[0 ];
1304
1255
}
1305
1256
else if (statement==" invokedynamic" )
@@ -1525,17 +1476,12 @@ codet java_bytecode_convert_methodt::convert_instructions(
1525
1476
pointer_typet (java_type_from_char (type_char)));
1526
1477
1527
1478
plus_exprt data_plus_offset (data_ptr, op[1 ], data_ptr.type ());
1479
+ // tag it so it's easy to identify during instrumentation
1480
+ data_plus_offset.set (ID_java_array_access, true );
1528
1481
typet element_type=data_ptr.type ().subtype ();
1529
1482
const dereference_exprt element (data_plus_offset, element_type);
1530
1483
1531
- c=code_blockt ();
1532
- codet bounds_check=
1533
- get_array_bounds_check (deref, op[1 ], i_it->source_location );
1534
- bounds_check.add_source_location ()=i_it->source_location ;
1535
- c.move_to_operands (bounds_check);
1536
- code_assignt array_put (element, op[2 ]);
1537
- array_put.add_source_location ()=i_it->source_location ;
1538
- c.move_to_operands (array_put);
1484
+ c=code_assignt (element, op[2 ]);
1539
1485
c.add_source_location ()=i_it->source_location ;
1540
1486
}
1541
1487
else if (statement==patternt (" ?store" ))
@@ -1569,11 +1515,10 @@ codet java_bytecode_convert_methodt::convert_instructions(
1569
1515
pointer_typet (java_type_from_char (type_char)));
1570
1516
1571
1517
plus_exprt data_plus_offset (data_ptr, op[1 ], data_ptr.type ());
1518
+ // tag it so it's easy to identify during instrumentation
1519
+ data_plus_offset.set (ID_java_array_access, true );
1572
1520
typet element_type=data_ptr.type ().subtype ();
1573
1521
dereference_exprt element (data_plus_offset, element_type);
1574
-
1575
- c=get_array_bounds_check (deref, op[1 ], i_it->source_location );
1576
- c.add_source_location ()=i_it->source_location ;
1577
1522
results[0 ]=java_bytecode_promotion (element);
1578
1523
}
1579
1524
else if (statement==patternt (" ?load" ))
@@ -2136,14 +2081,6 @@ codet java_bytecode_convert_methodt::convert_instructions(
2136
2081
java_new_array.add_source_location ()=i_it->source_location ;
2137
2082
2138
2083
c=code_blockt ();
2139
- // TODO make this throw NegativeArrayIndexException instead.
2140
- constant_exprt intzero=from_integer (0 , java_int_type ());
2141
- binary_relation_exprt gezero (op[0 ], ID_ge, intzero);
2142
- code_assertt check (gezero);
2143
- check.add_source_location ().set_comment (" Array size < 0" );
2144
- check.add_source_location ()
2145
- .set_property_class (" array-create-negative-size" );
2146
- c.move_to_operands (check);
2147
2084
2148
2085
if (max_array_length!=0 )
2149
2086
{
@@ -2175,27 +2112,20 @@ codet java_bytecode_convert_methodt::convert_instructions(
2175
2112
if (!i_it->source_location .get_line ().empty ())
2176
2113
java_new_array.add_source_location ()=i_it->source_location ;
2177
2114
2178
- code_blockt checkandcreate;
2179
- // TODO make this throw NegativeArrayIndexException instead.
2180
- constant_exprt intzero=from_integer (0 , java_int_type ());
2181
- binary_relation_exprt gezero (op[0 ], ID_ge, intzero);
2182
- code_assertt check (gezero);
2183
- check.add_source_location ().set_comment (" Array size < 0" );
2184
- check.add_source_location ()
2185
- .set_property_class (" array-create-negative-size" );
2186
- checkandcreate.move_to_operands (check);
2115
+ code_blockt create;
2187
2116
2188
2117
if (max_array_length!=0 )
2189
2118
{
2190
2119
constant_exprt size_limit=
2191
2120
from_integer (max_array_length, java_int_type ());
2192
2121
binary_relation_exprt le_max_size (op[0 ], ID_le, size_limit);
2193
2122
code_assumet assume_le_max_size (le_max_size);
2194
- checkandcreate .move_to_operands (assume_le_max_size);
2123
+ create .move_to_operands (assume_le_max_size);
2195
2124
}
2196
2125
2197
2126
const exprt tmp=tmp_variable (" newarray" , ref_type);
2198
- c=code_assignt (tmp, java_new_array);
2127
+ create.copy_to_operands (code_assignt (tmp, java_new_array));
2128
+ c=std::move (create);
2199
2129
results[0 ]=tmp;
2200
2130
}
2201
2131
else if (statement==" arraylength" )
0 commit comments