This fixes PR48437, we shouldn't unify function-local externs as that
confuses the DECL_CHAIN lists.  It seems they can be identified by
looking at TREE_STATIC and decl_function_context, if not we'll find out
(maybe the hard way, with wrong-code because of unmerged decls).

Eventually we should simply mark those decls that are introduced for
debug info only in an unambiguous way - or is there any already?

Bootstrapped and tested on x86_64-unknown-linux-gnu, SPEC 2k6 built
with LTO and -g.

Any comments?

Thanks,
Richard.

2011-04-06  Richard Guenther  <rguent...@suse.de>

        PR lto/48437
        * lto-symtab.c (lto_symtab_prevailing_decl): Do not unify
        function local externs.

        * gcc.dg/lto/pr48437_0.c: New testcase.

Index: gcc/lto-symtab.c
===================================================================
*** gcc/lto-symtab.c    (revision 171978)
--- gcc/lto-symtab.c    (working copy)
*************** lto_symtab_prevailing_decl (tree decl)
*** 854,859 ****
--- 854,865 ----
    if (TREE_CODE (decl) == FUNCTION_DECL && DECL_ABSTRACT (decl))
      return decl;
  
+   /* Non-static function local decls appear in block trees for
+      debug information purposes.  Those are their own prevailing decl.  */
+   if (!TREE_STATIC (decl)
+       && decl_function_context (decl) != NULL_TREE)
+     return decl;
+ 
    /* Ensure DECL_ASSEMBLER_NAME will not set assembler name.  */
    gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
  
Index: gcc/testsuite/gcc.dg/lto/pr48437_0.c
===================================================================
*** gcc/testsuite/gcc.dg/lto/pr48437_0.c        (revision 0)
--- gcc/testsuite/gcc.dg/lto/pr48437_0.c        (revision 0)
***************
*** 0 ****
--- 1,18 ----
+ /* { dg-lto-do run } */
+ /* { dg-lto-options { { -O -g -fwhole-program -flto } } } */
+ 
+ int
+ test (void)
+ {
+   int f (void);
+   return 0;
+ }
+ 
+ int
+ main (void)
+ {
+   int f (void);
+   int test (void);
+ 
+   return test ();
+ }

Reply via email to