Skip to content

Commit ec9f6b0

Browse files
Allocate array with right size when possible
When the array is not marked as nondet and is not a reference it can directly be allocated with the right size, which will allow constant propagation through arrays.
1 parent f156307 commit ec9f6b0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

jbmc/src/java_bytecode/assignments_from_json.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -839,18 +839,23 @@ void assign_from_json_rec(
839839
}
840840
else if(is_java_array_type(expr.type()))
841841
{
842-
const exprt length =
843-
nondet_length(info.allocate_objects, info.block, info.loc);
844-
allocate_array(expr, length, info);
845842
if(has_nondet_length(json))
846843
{
844+
const exprt length =
845+
nondet_length(info.allocate_objects, info.block, info.loc);
846+
allocate_array(expr, length, info);
847847
assign_nondet_length_array_from_json(
848848
expr, json, length, type_from_array, info);
849849
}
850850
else
851851
{
852-
assign_det_length_array_from_json(
853-
expr, json, length, type_from_array, info);
852+
PRECONDITION(is_java_array_type(expr.type()));
853+
const auto &element_type =
854+
java_array_element_type(to_struct_tag_type(expr.type().subtype()));
855+
const std::size_t length = get_untyped_array(json, element_type).size();
856+
allocate_array(expr, from_integer(length, java_int_type()), info);
857+
assign_array_data_component_from_json(
858+
expr, json, type_from_array, info);
854859
}
855860
}
856861
else if(

0 commit comments

Comments
 (0)