Created attachment 31316 [details] Testcase (compile with "-g -O2 -flto") GCC 4.9.0 20131124 (experimental). 1.c: In function 'main': 1.c:33:1: internal compiler error: in add_AT_specification, at dwarf2out.c:4026 } ^ 0x8267571 add_AT_specification ../../gcc-4.9/gcc/dwarf2out.c:4026 0x8267571 gen_subprogram_die ../../gcc-4.9/gcc/dwarf2out.c:17995 0x826d89c gen_decl_die ../../gcc-4.9/gcc/dwarf2out.c:20338 0x82856ad process_scope_var ../../gcc-4.9/gcc/dwarf2out.c:19946 0x8285726 decls_for_scope ../../gcc-4.9/gcc/dwarf2out.c:19971 0x8285cae gen_lexical_block_die ../../gcc-4.9/gcc/dwarf2out.c:18970 0x828694d gen_block_die ../../gcc-4.9/gcc/dwarf2out.c:19918 0x82858a8 decls_for_scope ../../gcc-4.9/gcc/dwarf2out.c:19985 0x8285cae gen_lexical_block_die ../../gcc-4.9/gcc/dwarf2out.c:18970 0x828694d gen_block_die ../../gcc-4.9/gcc/dwarf2out.c:19918 0x82858a8 decls_for_scope ../../gcc-4.9/gcc/dwarf2out.c:19985 0x826983d gen_subprogram_die ../../gcc-4.9/gcc/dwarf2out.c:18355 0x826d89c gen_decl_die ../../gcc-4.9/gcc/dwarf2out.c:20338 0x826ea4b dwarf2out_decl(tree_node*) ../../gcc-4.9/gcc/dwarf2out.c:20721 0x826eb21 dwarf2out_function_decl ../../gcc-4.9/gcc/dwarf2out.c:20729 0x82e36a8 rest_of_handle_final ../../gcc-4.9/gcc/final.c:4469 0x82e3897 execute ../../gcc-4.9/gcc/final.c:4513 GCC 20130526 /rev. 199345/ - works, GCC 20130630 /rev. 200571/ - fails.
Confirmed. Nested functions. There seems to be a declaration coming in from BLOCK_VARS #5 0x000000000074b91a in decls_for_scope (stmt=<block 0x7ffff6e4f190>, context_die=0x7ffff6e4f050, depth=2) at /space/rguenther/src/svn/trunk/gcc/dwarf2out.c:19971 but the decl itself has non-BLOCK scope (its DECL_CONTEXT is the main fn). There are two BLOCKs which contain the exact same BLOCK_VARs ... So it seems we duplicate BLOCKs either bogously during streaming (maybe only in the context of nested functions) or they are duplicate also in the compile phase. It seems that one BLOCK is BLOCK_SUPERCONTEXT of the other which cannot really be a streaming artifact. It's a tree merging artifact - we merge the TYPE_DECLs for enum { X }; which end up being written to the global section despite their DECL_CONTEXT being a FUNCTION_DECL (bah). Such merging happens without considering DECL_CHAIN as we assume they are not in BLOCK context. They end up there because the nested function decl 'foo' is in that same block (I think) and thus they form a tree SCC via BLOCK_VARS. Ah no - it's ultimately the CONST_DECL for X that pulls the enum type and its type decl global. Ick... I have a fix.
Author: rguenth Date: Thu Nov 28 12:09:10 2013 New Revision: 205481 URL: http://gcc.gnu.org/viewcvs?rev=205481&root=gcc&view=rev Log: 2013-11-28 Richard Biener <rguenther@suse.de> PR lto/59323 * lto-streamer-out.c (tree_is_indexable): TYPE_DECLs and CONST_DECLs in function context are not indexable. * gcc.dg/lto/pr59323_0.c: New testcase. Added: trunk/gcc/testsuite/gcc.dg/lto/pr59323_0.c Modified: trunk/gcc/ChangeLog trunk/gcc/lto-streamer-out.c trunk/gcc/testsuite/ChangeLog
Fixed.
Author: rguenth Date: Thu Nov 28 15:22:55 2013 New Revision: 205487 URL: http://gcc.gnu.org/viewcvs?rev=205487&root=gcc&view=rev Log: 2013-11-28 Richard Biener <rguenther@suse.de> PR lto/59323 * gcc.dg/lto/pr59323-2_0.c: New testcase. Added: trunk/gcc/testsuite/gcc.dg/lto/pr59323-2_0.c Modified: trunk/gcc/testsuite/ChangeLog