@@ -53,16 +53,46 @@ static bool link_functions(
5353 goto_functionst &dest_functions,
5454 const symbol_tablet &src_symbol_table,
5555 goto_functionst &src_functions,
56- const rename_symbolt &rename_symbol,
56+ rename_symbolt &rename_symbol,
5757 const std::unordered_set<irep_idt> &weak_symbols,
5858 const replace_symbolt &object_type_updates)
5959{
6060 namespacet ns (dest_symbol_table);
6161 namespacet src_ns (src_symbol_table);
6262
63+ // remove any unnecessary duplicates
64+ std::unordered_set<irep_idt> duplicates;
65+ for (const auto &f_pair : src_functions.function_map )
66+ {
67+ rename_symbolt::expr_mapt::iterator rename_it =
68+ rename_symbol.expr_map .find (f_pair.first );
69+ if (rename_it == rename_symbol.expr_map .end ())
70+ continue ;
71+
72+ std::string new_name = id2string (rename_it->second );
73+ std::string::size_type suffix_pos = new_name.find (" $link" );
74+ if (suffix_pos == std::string::npos)
75+ continue ;
76+
77+ irep_idt original_name = new_name.substr (0 , suffix_pos);
78+ goto_functionst::function_mapt::iterator existing_func =
79+ dest_functions.function_map .find (original_name);
80+ if (existing_func == dest_functions.function_map .end ())
81+ continue ;
82+
83+ if (f_pair.second .body .equals (existing_func->second .body ))
84+ {
85+ duplicates.insert (f_pair.first );
86+ rename_symbol.expr_map .erase (rename_it);
87+ }
88+ }
89+
6390 // merge functions
6491 for (auto &gf_entry : src_functions.function_map )
6592 {
93+ if (duplicates.find (gf_entry.first ) != duplicates.end ())
94+ continue ;
95+
6696 // the function might have been renamed
6797 rename_symbolt::expr_mapt::const_iterator e_it =
6898 rename_symbol.expr_map .find (gf_entry.first );
0 commit comments