12
12
#include < util/nondet_bool.h>
13
13
#include < util/pointer_offset_size.h>
14
14
15
+ #include < goto-programs/class_identifier.h>
15
16
#include < goto-programs/goto_functions.h>
16
17
18
+ #include < linking/zero_initializer.h>
19
+
17
20
#include " generic_parameter_specialization_map_keys.h"
18
21
#include " java_root_class.h"
19
22
@@ -1027,8 +1030,35 @@ void java_object_factoryt::gen_nondet_struct_init(
1027
1030
1028
1031
const componentst &components=struct_type.components ();
1029
1032
1030
- if (!is_sub)
1031
- class_identifier=struct_tag;
1033
+ // Should we write the whole object?
1034
+ // * Not if this is a sub-structure (a superclass object), as our caller will
1035
+ // have done this already
1036
+ // * Not if the object has already been initialised by our caller, in whic
1037
+ // case they will set `skip_classid`
1038
+ // * Not if we're re-initializing an existing object (i.e. update_in_place)
1039
+
1040
+ if (!is_sub &&
1041
+ !skip_classid &&
1042
+ update_in_place != update_in_placet::MUST_UPDATE_IN_PLACE)
1043
+ {
1044
+ class_identifier = struct_tag;
1045
+
1046
+ // Add an initial all-zero write. Most of the fields of this will be
1047
+ // overwritten, but it helps to have a whole-structure write that analysis
1048
+ // passes can easily recognise leaves no uninitialised state behind.
1049
+
1050
+ // This code mirrors the `remove_java_new` pass:
1051
+ null_message_handlert nullout;
1052
+ exprt zero_object=
1053
+ zero_initializer (
1054
+ struct_type, source_locationt (), ns, nullout);
1055
+ irep_idt qualified_clsid = " java::" + id2string (class_identifier);
1056
+ set_class_identifier (
1057
+ to_struct_expr (zero_object), ns, symbol_typet (qualified_clsid));
1058
+
1059
+ assignments.copy_to_operands (
1060
+ code_assignt (expr, zero_object));
1061
+ }
1032
1062
1033
1063
for (const auto &component : components)
1034
1064
{
@@ -1039,25 +1069,11 @@ void java_object_factoryt::gen_nondet_struct_init(
1039
1069
1040
1070
if (name==" @class_identifier" )
1041
1071
{
1042
- if (update_in_place==update_in_placet::MUST_UPDATE_IN_PLACE)
1043
- continue ;
1044
-
1045
- if (skip_classid)
1046
- continue ;
1047
-
1048
- irep_idt qualified_clsid = " java::" + id2string (class_identifier);
1049
- constant_exprt ci (qualified_clsid, string_typet ());
1050
- code_assignt code (me, ci);
1051
- code.add_source_location ()=loc;
1052
- assignments.copy_to_operands (code);
1072
+ continue ;
1053
1073
}
1054
1074
else if (name==" @lock" )
1055
1075
{
1056
- if (update_in_place==update_in_placet::MUST_UPDATE_IN_PLACE)
1057
- continue ;
1058
- code_assignt code (me, from_integer (0 , me.type ()));
1059
- code.add_source_location ()=loc;
1060
- assignments.copy_to_operands (code);
1076
+ continue ;
1061
1077
}
1062
1078
else
1063
1079
{
0 commit comments