Skip to content

Commit a9b08e3

Browse files
authored
Merge pull request #3742 from diffblue/gather_field_types
strengthen type of parameter of gather_field_types
2 parents e7787ad + 86640b4 commit a9b08e3

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

jbmc/src/java_bytecode/ci_lazy_methods_needed.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void ci_lazy_methods_neededt::initialize_instantiated_classes_from_pointer(
124124
// explore again even if we've seen this classid before in the array case.
125125
if(add_needed_class(param_classid) || is_java_array_tag(param_classid))
126126
{
127-
gather_field_types(pointer_type.base_type(), ns);
127+
gather_field_types(class_type, ns);
128128
}
129129

130130
if(is_java_generic_type(pointer_type))
@@ -145,33 +145,30 @@ void ci_lazy_methods_neededt::initialize_instantiated_classes_from_pointer(
145145
/// \param class_type: root of class tree to search
146146
/// \param ns: global namespaces.
147147
void ci_lazy_methods_neededt::gather_field_types(
148-
const typet &class_type,
148+
const struct_tag_typet &class_type,
149149
const namespacet &ns)
150150
{
151-
const auto &underlying_type = to_struct_type(ns.follow(class_type));
151+
const auto &underlying_type = ns.follow_tag(class_type);
152+
152153
if(is_java_array_tag(underlying_type.get_tag()))
153154
{
154-
// If class_type is not a symbol this may be a reference array,
155-
// but we can't tell what type.
156-
if(class_type.id() == ID_struct_tag)
155+
const typet &element_type = java_array_element_type(class_type);
156+
if(
157+
element_type.id() == ID_pointer &&
158+
to_pointer_type(element_type).base_type().id() != ID_empty)
157159
{
158-
const typet &element_type =
159-
java_array_element_type(to_struct_tag_type(class_type));
160-
if(
161-
element_type.id() == ID_pointer &&
162-
to_pointer_type(element_type).base_type().id() != ID_empty)
163-
{
164-
// This is a reference array -- mark its element type available.
165-
add_all_needed_classes(to_pointer_type(element_type));
166-
}
160+
// This is a reference array -- mark its element type available.
161+
add_all_needed_classes(to_pointer_type(element_type));
167162
}
168163
}
169164
else
170165
{
171166
for(const auto &field : underlying_type.components())
172167
{
173-
if(field.type().id() == ID_struct || field.type().id() == ID_struct_tag)
174-
gather_field_types(field.type(), ns);
168+
if(field.type().id() == ID_struct_tag)
169+
gather_field_types(to_struct_tag_type(field.type()), ns);
170+
else if(field.type().id() == ID_struct)
171+
UNREACHABLE;
175172
else if(field.type().id() == ID_pointer)
176173
{
177174
if(to_pointer_type(field.type()).base_type().id() == ID_struct_tag)

jbmc/src/java_bytecode/ci_lazy_methods_needed.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class namespacet;
2020
class pointer_typet;
2121
class select_pointer_typet;
2222
class symbol_table_baset;
23-
class typet;
23+
class struct_tag_typet;
2424

2525
class ci_lazy_methods_neededt
2626
{
@@ -64,7 +64,8 @@ class ci_lazy_methods_neededt
6464
const pointer_typet &pointer_type,
6565
const namespacet &ns);
6666

67-
void gather_field_types(const typet &class_type, const namespacet &ns);
67+
void
68+
gather_field_types(const struct_tag_typet &class_type, const namespacet &ns);
6869
};
6970

7071
#endif

0 commit comments

Comments
 (0)