This fixes PR46796 by making sure the types in the type variant chain
can be looked up again using get_qualified_type.

LTO bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2011-12-09  Richard Guenther  <rguent...@suse.de>

        PR lto/46796
        * lto.c (uniquify_nodes): Merge TYPE_DECLs in the
        type variant chain.

Index: gcc/lto/lto.c
===================================================================
--- gcc/lto/lto.c       (revision 182154)
+++ gcc/lto/lto.c       (working copy)
@@ -860,6 +860,34 @@ uniquify_nodes (struct data_in *data_in,
       if (t == NULL_TREE)
        continue;
 
+      /* Perform very simple TYPE_DECL merging on the type variant
+        chain here.  That catches the cases in PR46796, where
+        get_qualified_type fails to lookup an existing qualified
+        type because TYPE_NAME are not pointer-equal.  */
+      if (TYPE_P (t)
+         && TYPE_NAME (t)
+         && TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)
+       {
+         tree tn = TYPE_NAME (t);
+         tree t2;
+         for (t2 = TYPE_MAIN_VARIANT (t); t2; t2 = TYPE_NEXT_VARIANT (t2))
+           {
+             tree t2n = TYPE_NAME (t2);
+             if (t2 == t
+                 || t2n == tn)
+               continue;
+             if (t2n
+                 && TREE_CODE (t2n) == TYPE_DECL
+                 && TREE_TYPE (t2n) == TREE_TYPE (tn)
+                 && DECL_NAME (t2n) == DECL_NAME (tn)
+                 && DECL_SOURCE_LOCATION (t2n) == DECL_SOURCE_LOCATION (tn))
+               {
+                 TYPE_NAME (t) = t2n;
+                 break;
+               }
+           }
+       }
+
       if (TREE_CODE (t) == VAR_DECL)
        lto_register_var_decl_in_symtab (data_in, t);
       else if (TREE_CODE (t) == FUNCTION_DECL && !DECL_BUILT_IN (t))

Reply via email to