@@ -57,16 +57,46 @@ static bool link_functions(
5757 goto_functionst &dest_functions,
5858 const symbol_tablet &src_symbol_table,
5959 goto_functionst &src_functions,
60- const rename_symbolt &rename_symbol,
60+ rename_symbolt &rename_symbol,
6161 const std::unordered_set<irep_idt> &weak_symbols,
6262 const replace_symbolt &object_type_updates)
6363{
6464 namespacet ns (dest_symbol_table);
6565 namespacet src_ns (src_symbol_table);
6666
67+ // remove any unnecessary duplicates
68+ std::unordered_set<irep_idt> duplicates;
69+ for (const auto &f_pair : src_functions.function_map )
70+ {
71+ rename_symbolt::expr_mapt::iterator rename_it =
72+ rename_symbol.expr_map .find (f_pair.first );
73+ if (rename_it == rename_symbol.expr_map .end ())
74+ continue ;
75+
76+ std::string new_name = id2string (rename_it->second );
77+ std::string::size_type suffix_pos = new_name.find (" $link" );
78+ if (suffix_pos == std::string::npos)
79+ continue ;
80+
81+ irep_idt original_name = new_name.substr (0 , suffix_pos);
82+ goto_functionst::function_mapt::iterator existing_func =
83+ dest_functions.function_map .find (original_name);
84+ if (existing_func == dest_functions.function_map .end ())
85+ continue ;
86+
87+ if (f_pair.second .body .equals (existing_func->second .body ))
88+ {
89+ duplicates.insert (f_pair.first );
90+ rename_symbol.expr_map .erase (rename_it);
91+ }
92+ }
93+
6794 // merge functions
6895 Forall_goto_functions (src_it, src_functions)
6996 {
97+ if (duplicates.find (src_it->first ) != duplicates.end ())
98+ continue ;
99+
70100 // the function might have been renamed
71101 rename_symbolt::expr_mapt::const_iterator e_it=
72102 rename_symbol.expr_map .find (src_it->first );
0 commit comments