@@ -47,16 +47,46 @@ static bool link_functions(
4747 goto_functionst &dest_functions,
4848 const symbol_tablet &src_symbol_table,
4949 goto_functionst &src_functions,
50- const rename_symbolt &rename_symbol,
50+ rename_symbolt &rename_symbol,
5151 const std::unordered_set<irep_idt> &weak_symbols,
5252 const replace_symbolt &object_type_updates)
5353{
5454 namespacet ns (dest_symbol_table);
5555 namespacet src_ns (src_symbol_table);
5656
57+ // remove any unnecessary duplicates
58+ std::unordered_set<irep_idt> duplicates;
59+ for (const auto &f_pair : src_functions.function_map )
60+ {
61+ rename_symbolt::expr_mapt::iterator rename_it =
62+ rename_symbol.expr_map .find (f_pair.first );
63+ if (rename_it == rename_symbol.expr_map .end ())
64+ continue ;
65+
66+ std::string new_name = id2string (rename_it->second );
67+ std::string::size_type suffix_pos = new_name.find (" $link" );
68+ if (suffix_pos == std::string::npos)
69+ continue ;
70+
71+ irep_idt original_name = new_name.substr (0 , suffix_pos);
72+ goto_functionst::function_mapt::iterator existing_func =
73+ dest_functions.function_map .find (original_name);
74+ if (existing_func == dest_functions.function_map .end ())
75+ continue ;
76+
77+ if (f_pair.second .body .equals (existing_func->second .body ))
78+ {
79+ duplicates.insert (f_pair.first );
80+ rename_symbol.expr_map .erase (rename_it);
81+ }
82+ }
83+
5784 // merge functions
5885 Forall_goto_functions (src_it, src_functions)
5986 {
87+ if (duplicates.find (src_it->first ) != duplicates.end ())
88+ continue ;
89+
6090 // the function might have been renamed
6191 rename_symbolt::expr_mapt::const_iterator e_it=
6292 rename_symbol.expr_map .find (src_it->first );
0 commit comments