This fixes the ICE seen in PR60060 which stems from us asking to output debug-info for a function-scope global twice - once via emitting the function and its BLOCK-associated vars and once via the debug-hook through lto_write_globals -> emit_debug_global_declarations.
The list of "global" variables does not agree with those from the frontends (that function-scope global is not in GFortrans list). Thus the following simply avoids the mess by only ever emitting debug-info for non-function scope globals here. As wrapup_global_declarations looks like a complete no-op for LTO (DECL_DEFER_OUTPUT is never 1, it's not even streamed ...) I chose to inline emit_debug_global_declarations. That whole area asks for a FE-middle-end interface sanitization ... LTO bootstrapped / tested on x86_64-unknown-linux-gnu. Does that look ok? Thanks, Richard. 2014-02-11 Richard Biener <rguent...@suse.de> PR lto/60060 * lto-lang.c (lto_write_globals): Do not call wrapup_global_declarations or emit_debug_global_declarations but emit debug info for non-function scope variables directly. Index: gcc/lto/lto-lang.c =================================================================== *** gcc/lto/lto-lang.c (revision 207655) --- gcc/lto/lto-lang.c (working copy) *************** lto_write_globals (void) *** 1082,1098 **** if (flag_wpa) return; ! /* Record the global variables. */ ! vec<tree> lto_global_var_decls = vNULL; varpool_node *vnode; FOR_EACH_DEFINED_VARIABLE (vnode) ! lto_global_var_decls.safe_push (vnode->decl); ! ! tree *vec = lto_global_var_decls.address (); ! int len = lto_global_var_decls.length (); ! wrapup_global_declarations (vec, len); ! emit_debug_global_declarations (vec, len); ! lto_global_var_decls.release (); } static tree --- 1082,1092 ---- if (flag_wpa) return; ! /* Output debug info for global variables. */ varpool_node *vnode; FOR_EACH_DEFINED_VARIABLE (vnode) ! if (!decl_function_context (vnode->decl)) ! debug_hooks->global_decl (vnode->decl); } static tree