https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61886

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Btw, it seems that at the point we merge in lto-symtab.c the cgraph nodes are
not yet populated.  Neither of the two candidates are marked as alias.

So maybe the wrong thing already happens earlier, during compile-time
and we shouldn't do any symtab merging?  at least from symbols originating
from the same TU?  That is, tree merging already should catch most
true equivalencies and cgraph merging shouldn't be symtab-driven?

That said, I wonder how to fix things up properly.

The following fixes the testcase, not merging the actual symtab intra-TU
and retaining decls that have a symtab entry recorded.

Index: gcc/lto/lto-symtab.c
===================================================================
--- gcc/lto/lto-symtab.c        (revision 212927)
+++ gcc/lto/lto-symtab.c        (working copy)
@@ -575,6 +575,9 @@ lto_symtab_merge_symbols_1 (symtab_node

       if (!lto_symtab_symbol_p (e))
        continue;
+      /* Do not merge symtab nodes originating from the same TU.  */
+      if (e->lto_file_data == prevailing->lto_file_data)
+       continue;
       cgraph_node *ce = dyn_cast <cgraph_node *> (e);
       if (ce && !DECL_BUILT_IN (e->decl))
        lto_cgraph_replace_node (ce, cgraph (prevailing));
@@ -680,6 +683,12 @@ lto_symtab_prevailing_decl (tree decl)
   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
     return decl;

+  /* If the decl retained its symtab node then it prevails.  This
+     preserves semantically different decls for the same underlying
+     symbol, like aliases that have been resolved at compile-time.  */
+  if (symtab_get_node (decl))
+    return decl;
+
   /* Ensure DECL_ASSEMBLER_NAME will not set assembler name.  */
   gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));

Reply via email to