Bug 59323 - [4.9 Regression] Int. comp. error: in add_AT_specification, at dwarf2out.c:4026
Summary: [4.9 Regression] Int. comp. error: in add_AT_specification, at dwarf2out.c:4026
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code, lto
Depends on:
Blocks:
 
Reported: 2013-11-28 07:23 UTC by Dmitry Gorbachev
Modified: 2013-11-28 15:22 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-11-28 00:00:00


Attachments
Testcase (compile with "-g -O2 -flto") (172 bytes, text/plain)
2013-11-28 07:23 UTC, Dmitry Gorbachev
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Gorbachev 2013-11-28 07:23:51 UTC
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.
Comment 1 Richard Biener 2013-11-28 10:00:28 UTC
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.
Comment 2 Richard Biener 2013-11-28 12:09:13 UTC
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
Comment 3 Richard Biener 2013-11-28 12:12:00 UTC
Fixed.
Comment 4 Richard Biener 2013-11-28 15:22:57 UTC
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