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