Skip to content

Commit c049004

Browse files
committed
Base-type-eq: check pointer types really match
Generally base-type-eq's task is to ensure that types match up to substitution of a type's body for a symbol referring to that type. However now that derivatives of pointers exist with named subexpressions (e.g. java_generic_parametert), it is now possible for types not involving symbols to be `base_type_eq` but not `==`. This resolves that particular case by checking that the names subexpressions match exactly.
1 parent c74d257 commit c049004

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/util/base_type.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,34 @@ bool base_type_eqt::base_type_eq_rec(
253253
}
254254
else if(type1.id()==ID_pointer)
255255
{
256+
// Types dervied from pointer, such as java_generic_parametert, may have
257+
// qualifiers given as named subexpressions:
258+
const auto &named_subs1 = type1.get_named_sub();
259+
const auto &named_subs2 = type2.get_named_sub();
260+
261+
for(const auto &name_and_sub : named_subs1)
262+
{
263+
if(irept::is_comment(name_and_sub.first))
264+
continue;
265+
auto other_sub = named_subs2.find(name_and_sub.first);
266+
if(
267+
other_sub == named_subs2.end() ||
268+
name_and_sub.second != other_sub->second)
269+
{
270+
return false;
271+
}
272+
}
273+
274+
for(const auto &name_and_sub : named_subs2)
275+
{
276+
if(irept::is_comment(name_and_sub.first))
277+
continue;
278+
auto other_sub = named_subs1.find(name_and_sub.first);
279+
// Equality already checked above
280+
if(other_sub == named_subs1.end())
281+
return false;
282+
}
283+
256284
return base_type_eq_rec(
257285
to_pointer_type(type1).subtype(), to_pointer_type(type2).subtype());
258286
}

0 commit comments

Comments
 (0)