Skip to content

Commit a9433c6

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 8450fec commit a9433c6

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
@@ -831,18 +831,23 @@ void assign_from_json_rec(
831831
}
832832
else if(is_java_array_type(expr.type()))
833833
{
834-
const exprt length =
835-
nondet_length(info.allocate_objects, info.block, info.loc);
836-
allocate_array(expr, length, info);
837834
if(has_nondet_length(json))
838835
{
836+
const exprt length =
837+
nondet_length(info.allocate_objects, info.block, info.loc);
838+
allocate_array(expr, length, info);
839839
assign_nondet_length_array_from_json(
840840
expr, json, length, type_from_array, info);
841841
}
842842
else
843843
{
844-
assign_det_length_array_from_json(
845-
expr, json, length, type_from_array, info);
844+
PRECONDITION(is_java_array_type(expr.type()));
845+
const auto &element_type =
846+
java_array_element_type(to_struct_tag_type(expr.type().subtype()));
847+
const std::size_t length = get_untyped_array(json, element_type).size();
848+
allocate_array(expr, from_integer(length, java_int_type()), info);
849+
assign_array_data_component_from_json(
850+
expr, json, type_from_array, info);
846851
}
847852
}
848853
else if(

0 commit comments

Comments
 (0)