@@ -1084,20 +1084,17 @@ codet java_bytecode_convert_methodt::convert_instructions(
1084
1084
{
1085
1085
assert (op.size ()==1 && results.size ()==1 );
1086
1086
code_blockt block;
1087
- if (!disable_runtime_checks)
1088
- {
1089
- // TODO throw NullPointerException instead
1090
- const typecast_exprt lhs (op[0 ], pointer_typet (empty_typet ()));
1091
- const exprt rhs (null_pointer_exprt (to_pointer_type (lhs.type ())));
1092
- const exprt not_equal_null (
1093
- binary_relation_exprt (lhs, ID_notequal, rhs));
1094
- code_assertt check (not_equal_null);
1095
- check.add_source_location ()
1096
- .set_comment (" Throw null" );
1097
- check.add_source_location ()
1098
- .set_property_class (" null-pointer-exception" );
1099
- block.move_to_operands (check);
1100
- }
1087
+ // TODO throw NullPointerException instead
1088
+ const typecast_exprt lhs (op[0 ], pointer_typet (empty_typet ()));
1089
+ const exprt rhs (null_pointer_exprt (to_pointer_type (lhs.type ())));
1090
+ const exprt not_equal_null (
1091
+ binary_relation_exprt (lhs, ID_notequal, rhs));
1092
+ code_assertt check (not_equal_null);
1093
+ check.add_source_location ()
1094
+ .set_comment (" Throw null" );
1095
+ check.add_source_location ()
1096
+ .set_property_class (" null-pointer-exception" );
1097
+ block.move_to_operands (check);
1101
1098
1102
1099
side_effect_expr_throwt throw_expr;
1103
1100
throw_expr.add_source_location ()=i_it->source_location ;
@@ -1110,20 +1107,15 @@ codet java_bytecode_convert_methodt::convert_instructions(
1110
1107
}
1111
1108
else if (statement==" checkcast" )
1112
1109
{
1113
- if (!disable_runtime_checks)
1114
- {
1115
- // checkcast throws an exception in case a cast of object
1116
- // on stack to given type fails.
1117
- // The stack isn't modified.
1118
- // TODO: convert assertions to exceptions.
1119
- assert (op.size ()==1 && results.size ()==1 );
1120
- binary_predicate_exprt check (op[0 ], ID_java_instanceof, arg0);
1121
- c=code_assertt (check);
1122
- c.add_source_location ().set_comment (" Dynamic cast check" );
1123
- c.add_source_location ().set_property_class (" bad-dynamic-cast" );
1124
- }
1125
- else
1126
- c=code_skipt ();
1110
+ // checkcast throws an exception in case a cast of object
1111
+ // on stack to given type fails.
1112
+ // The stack isn't modified.
1113
+ // TODO: convert assertions to exceptions.
1114
+ assert (op.size ()==1 && results.size ()==1 );
1115
+ binary_predicate_exprt check (op[0 ], ID_java_instanceof, arg0);
1116
+ c=code_assertt (check);
1117
+ c.add_source_location ().set_comment (" Dynamic cast check" );
1118
+ c.add_source_location ().set_property_class (" bad-dynamic-cast" );
1127
1119
1128
1120
results[0 ]=op[0 ];
1129
1121
}
@@ -1308,13 +1300,10 @@ codet java_bytecode_convert_methodt::convert_instructions(
1308
1300
const dereference_exprt element (data_plus_offset, element_type);
1309
1301
1310
1302
c=code_blockt ();
1311
- if (!disable_runtime_checks)
1312
- {
1313
- codet bounds_check=
1314
- get_array_bounds_check (deref, op[1 ], i_it->source_location );
1315
- bounds_check.add_source_location ()=i_it->source_location ;
1316
- c.move_to_operands (bounds_check);
1317
- }
1303
+ codet bounds_check=
1304
+ get_array_bounds_check (deref, op[1 ], i_it->source_location );
1305
+ bounds_check.add_source_location ()=i_it->source_location ;
1306
+ c.move_to_operands (bounds_check);
1318
1307
code_assignt array_put (element, op[2 ]);
1319
1308
array_put.add_source_location ()=i_it->source_location ;
1320
1309
c.move_to_operands (array_put);
@@ -1354,11 +1343,8 @@ codet java_bytecode_convert_methodt::convert_instructions(
1354
1343
typet element_type=data_ptr.type ().subtype ();
1355
1344
dereference_exprt element (data_plus_offset, element_type);
1356
1345
1357
- if (!disable_runtime_checks)
1358
- {
1359
- c=get_array_bounds_check (deref, op[1 ], i_it->source_location );
1360
- c.add_source_location ()=i_it->source_location ;
1361
- }
1346
+ c=get_array_bounds_check (deref, op[1 ], i_it->source_location );
1347
+ c.add_source_location ()=i_it->source_location ;
1362
1348
results[0 ]=java_bytecode_promotion (element);
1363
1349
}
1364
1350
else if (statement==patternt (" ?load" ))
@@ -1899,17 +1885,15 @@ codet java_bytecode_convert_methodt::convert_instructions(
1899
1885
java_new_array.add_source_location ()=i_it->source_location ;
1900
1886
1901
1887
c=code_blockt ();
1902
- if (!disable_runtime_checks)
1903
- {
1904
- // TODO make this throw NegativeArrayIndexException instead.
1905
- constant_exprt intzero=from_integer (0 , java_int_type ());
1906
- binary_relation_exprt gezero (op[0 ], ID_ge, intzero);
1907
- code_assertt check (gezero);
1908
- check.add_source_location ().set_comment (" Array size < 0" );
1909
- check.add_source_location ()
1910
- .set_property_class (" array-create-negative-size" );
1911
- c.move_to_operands (check);
1912
- }
1888
+ // TODO make this throw NegativeArrayIndexException instead.
1889
+ constant_exprt intzero=from_integer (0 , java_int_type ());
1890
+ binary_relation_exprt gezero (op[0 ], ID_ge, intzero);
1891
+ code_assertt check (gezero);
1892
+ check.add_source_location ().set_comment (" Array size < 0" );
1893
+ check.add_source_location ()
1894
+ .set_property_class (" array-create-negative-size" );
1895
+ c.move_to_operands (check);
1896
+
1913
1897
if (max_array_length!=0 )
1914
1898
{
1915
1899
constant_exprt size_limit=
@@ -1941,26 +1925,24 @@ codet java_bytecode_convert_methodt::convert_instructions(
1941
1925
java_new_array.add_source_location ()=i_it->source_location ;
1942
1926
1943
1927
code_blockt checkandcreate;
1944
- if (!disable_runtime_checks)
1928
+ // TODO make this throw NegativeArrayIndexException instead.
1929
+ constant_exprt intzero=from_integer (0 , java_int_type ());
1930
+ binary_relation_exprt gezero (op[0 ], ID_ge, intzero);
1931
+ code_assertt check (gezero);
1932
+ check.add_source_location ().set_comment (" Array size < 0" );
1933
+ check.add_source_location ()
1934
+ .set_property_class (" array-create-negative-size" );
1935
+ checkandcreate.move_to_operands (check);
1936
+
1937
+ if (max_array_length!=0 )
1945
1938
{
1946
- // TODO make this throw NegativeArrayIndexException instead.
1947
- constant_exprt intzero=from_integer (0 , java_int_type ());
1948
- binary_relation_exprt gezero (op[0 ], ID_ge, intzero);
1949
- code_assertt check (gezero);
1950
- check.add_source_location ().set_comment (" Array size < 0" );
1951
- check.add_source_location ()
1952
- .set_property_class (" array-create-negative-size" );
1953
- checkandcreate.move_to_operands (check);
1954
-
1955
- if (max_array_length!=0 )
1956
- {
1957
- constant_exprt size_limit=
1958
- from_integer (max_array_length, java_int_type ());
1959
- binary_relation_exprt le_max_size (op[0 ], ID_le, size_limit);
1960
- code_assumet assume_le_max_size (le_max_size);
1961
- checkandcreate.move_to_operands (assume_le_max_size);
1962
- }
1939
+ constant_exprt size_limit=
1940
+ from_integer (max_array_length, java_int_type ());
1941
+ binary_relation_exprt le_max_size (op[0 ], ID_le, size_limit);
1942
+ code_assumet assume_le_max_size (le_max_size);
1943
+ checkandcreate.move_to_operands (assume_le_max_size);
1963
1944
}
1945
+
1964
1946
const exprt tmp=tmp_variable (" newarray" , ref_type);
1965
1947
c=code_assignt (tmp, java_new_array);
1966
1948
results[0 ]=tmp;
@@ -2430,15 +2412,13 @@ void java_bytecode_convert_method(
2430
2412
const java_bytecode_parse_treet::methodt &method,
2431
2413
symbol_tablet &symbol_table,
2432
2414
message_handlert &message_handler,
2433
- bool disable_runtime_checks,
2434
2415
size_t max_array_length,
2435
2416
safe_pointer<std::vector<irep_idt> > needed_methods,
2436
2417
safe_pointer<std::set<irep_idt> > needed_classes)
2437
2418
{
2438
2419
java_bytecode_convert_methodt java_bytecode_convert_method (
2439
2420
symbol_table,
2440
2421
message_handler,
2441
- disable_runtime_checks,
2442
2422
max_array_length,
2443
2423
needed_methods,
2444
2424
needed_classes);
0 commit comments