Skip to content

Commit 98e5365

Browse files
committed
Revert "Revert "goto_symex: rename type symbols only when needed""
This reverts commit 60ce997.
1 parent d5740b3 commit 98e5365

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/goto-symex/goto_symex_state.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,12 +611,63 @@ void goto_symex_statet::rename_address(
611611
}
612612
}
613613

614+
static bool requires_renaming(const typet &type, const namespacet &ns)
615+
{
616+
if(type.id() == ID_array)
617+
{
618+
const auto &array_type = to_array_type(type);
619+
return requires_renaming(array_type.subtype(), ns) ||
620+
!array_type.size().is_constant();
621+
}
622+
else if(
623+
type.id() == ID_struct || type.id() == ID_union || type.id() == ID_class)
624+
{
625+
const struct_union_typet &s_u_type = to_struct_union_type(type);
626+
const struct_union_typet::componentst &components = s_u_type.components();
627+
628+
for(auto &component : components)
629+
{
630+
// be careful, or it might get cyclic
631+
if(component.type().id() != ID_pointer)
632+
return requires_renaming(component.type(), ns);
633+
}
634+
635+
return false;
636+
}
637+
else if(type.id() == ID_pointer)
638+
{
639+
return requires_renaming(to_pointer_type(type).subtype(), ns);
640+
}
641+
else if(type.id() == ID_symbol_type)
642+
{
643+
const symbolt &symbol = ns.lookup(to_symbol_type(type));
644+
return requires_renaming(symbol.type, ns);
645+
}
646+
else if(type.id() == ID_union_tag)
647+
{
648+
const symbolt &symbol = ns.lookup(to_union_tag_type(type));
649+
return requires_renaming(symbol.type, ns);
650+
}
651+
else if(type.id() == ID_struct_tag)
652+
{
653+
const symbolt &symbol = ns.lookup(to_struct_tag_type(type));
654+
return requires_renaming(symbol.type, ns);
655+
}
656+
657+
return false;
658+
}
659+
614660
void goto_symex_statet::rename(
615661
typet &type,
616662
const irep_idt &l1_identifier,
617663
const namespacet &ns,
618664
levelt level)
619665
{
666+
// check whether there are symbol expressions in the type; if not, there
667+
// is no need to expand the struct/union tags in the type
668+
if(!requires_renaming(type, ns))
669+
return; // no action
670+
620671
// rename all the symbols with their last known value
621672
// to the given level
622673

0 commit comments

Comments
 (0)