I'm testing the following patch for PR48437 - the C frontend generates decl copies for placing them in BLOCK_VARS for
int test (void) { extern int f (void); return 0; } we currently end up putting those into the decl merging machinery, causing DECL_CHAIN re-use and subsequent crashes. By not indexing them we make sure to keep them separate. LTO bootstrap & regtest pending on x86_64-unknown-linux-gnu, ok? [Similar fix has to be employed for VLA types] Thanks, Richard. 2011-12-07 Richard Guenther <rguent...@suse.de> PR lto/48437 * lto-streamer-out.c (tree_is_indexable): Exclude block-local extern declarations. * gcc.dg/lto/20111207-2_0.c: New testcase. * gcc.dg/guality/pr48437.c: Likewise. Index: gcc/lto-streamer-out.c =================================================================== *** gcc/lto-streamer-out.c (revision 182081) --- gcc/lto-streamer-out.c (working copy) *************** tree_is_indexable (tree t) *** 129,134 **** --- 129,144 ---- else if (TREE_CODE (t) == VAR_DECL && decl_function_context (t) && !TREE_STATIC (t)) return false; + /* If this is a decl generated for block local externs for + debug info generation, stream it unshared alongside BLOCK_VARS. */ + else if (VAR_OR_FUNCTION_DECL_P (t) + /* ??? The following tests are a literal match on what + c-decl.c:pop_scope does. */ + && TREE_PUBLIC (t) + && DECL_EXTERNAL (t) + && DECL_CONTEXT (t) + && TREE_CODE (DECL_CONTEXT (t)) == FUNCTION_DECL) + return false; else return (TYPE_P (t) || DECL_P (t) || TREE_CODE (t) == SSA_NAME); } Index: gcc/testsuite/gcc.dg/lto/20111207-2_0.c =================================================================== *** gcc/testsuite/gcc.dg/lto/20111207-2_0.c (revision 0) --- gcc/testsuite/gcc.dg/lto/20111207-2_0.c (revision 0) *************** *** 0 **** --- 1,17 ---- + /* { dg-lto-do run } */ + + int + test (void) + { + int f (void); + return 0; + } + + int + main (void) + { + int f (void); + int test (void); + + return test (); + } Index: gcc/testsuite/gcc.dg/guality/pr48437.c =================================================================== *** gcc/testsuite/gcc.dg/guality/pr48437.c (revision 0) --- gcc/testsuite/gcc.dg/guality/pr48437.c (revision 0) *************** *** 0 **** --- 1,15 ---- + /* PR lto/48437 */ + /* { dg-do run } */ + /* { dg-options "-g" } */ + + int i __attribute__((used)); + int main() + { + volatile int i; + for (i = 3; i < 7; ++i) + { + extern int i; /* { dg-final { gdb-test 7 "i" "0" } } */ + asm volatile ("" : : : "memory"); + } + return 0; + }