Hi, this patch fixes leak in decl_in_states. We have quite few cases where we can get rid of a node from symbol table without going through function_in_decl_state. Most important being in lto-symtab merging.
Bootstrapped/regtested x86_64-linux, comitted. Honza * lto.c (read_cgraph_and_symbols): Do not do merging at ltrans stage. * cgraph.c (cgraph_node::release_body): Free function_in_decl_state. (cgraph_node::remove): Likewise. (cgraph_node::get_untransformed_body): Likewise. * varpool.c (varpool_node::remove): Likewise. (varpool_node::get_constructor): Add sanity check. Index: lto/lto.c =================================================================== --- lto/lto.c (revision 221296) +++ lto/lto.c (working copy) @@ -3118,13 +3118,20 @@ read_cgraph_and_symbols (unsigned nfiles fprintf (symtab->dump_file, "Before merging:\n"); symtab_node::dump_table (symtab->dump_file); } - lto_symtab_merge_symbols (); - /* Removal of unreachable symbols is needed to make verify_symtab to pass; - we are still having duplicated comdat groups containing local statics. - We could also just remove them while merging. */ - symtab->remove_unreachable_nodes (dump_file); + if (!flag_ltrans) + { + lto_symtab_merge_symbols (); + /* Removal of unreachable symbols is needed to make verify_symtab to pass; + we are still having duplicated comdat groups containing local statics. + We could also just remove them while merging. */ + symtab->remove_unreachable_nodes (dump_file); + } ggc_collect (); symtab->state = IPA_SSA; + /* FIXME: Technically all node removals happening here are useless, because + WPA should not stream them. */ + if (flag_ltrans) + symtab->remove_unreachable_nodes (dump_file); timevar_pop (TV_IPA_LTO_CGRAPH_MERGE); Index: cgraph.c =================================================================== --- cgraph.c (revision 221296) +++ cgraph.c (working copy) @@ -1711,7 +1711,10 @@ cgraph_node::release_body (bool keep_arg DECL_INITIAL (decl) = error_mark_node; release_function_body (decl); if (lto_file_data) - lto_free_function_in_decl_state_for_node (this); + { + lto_free_function_in_decl_state_for_node (this); + lto_file_data = NULL; + } } /* Remove function from symbol table. */ @@ -1789,13 +1792,18 @@ cgraph_node::remove (void) n = cgraph_node::get (decl); if (!n || (!n->clones && !n->clone_of && !n->global.inlined_to - && (symtab->global_info_ready + && ((symtab->global_info_ready || in_lto_p) && (TREE_ASM_WRITTEN (n->decl) || DECL_EXTERNAL (n->decl) || !n->analyzed || (!flag_wpa && n->in_other_partition))))) release_body (); } + else + { + lto_free_function_in_decl_state_for_node (this); + lto_file_data = NULL; + } decl = NULL; if (call_site_hash) @@ -3208,6 +3216,8 @@ cgraph_node::get_untransformed_body (voi lto_free_section_data (file_data, LTO_section_function_body, name, data, len); lto_free_function_in_decl_state_for_node (this); + /* Keep lto file data so ipa-inline-analysis knows about cross module + inlining. */ timevar_pop (TV_IPA_LTO_GIMPLE_IN); Index: varpool.c =================================================================== --- varpool.c (revision 221296) +++ varpool.c (working copy) @@ -195,6 +195,11 @@ void varpool_node::remove (void) { symtab->call_varpool_removal_hooks (this); + if (lto_file_data) + { + lto_free_function_in_decl_state_for_node (this); + lto_file_data = NULL; + } /* When streaming we can have multiple nodes associated with decl. */ if (symtab->state == LTO_STREAMING) @@ -323,6 +328,7 @@ varpool_node::get_constructor (void) name); lto_input_variable_constructor (file_data, this, data); + gcc_assert (DECL_INITIAL (decl) != error_mark_node); lto_stats.num_function_bodies++; lto_free_section_data (file_data, LTO_section_function_body, name, data, len);