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

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
So a real fix might look like the following (requiring changes in all other
type builders to first set/compute the canonical type of course).

diff --git a/gcc/tree.cc b/gcc/tree.cc
index 83f3bf306af..5dfe12f0e96 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -6012,6 +6012,9 @@ type_hash_canon_hash (tree type)

   hstate.add_int (TREE_CODE (type));

+  if (TYPE_CANONICAL (type))
+    hstate.add_object (TYPE_HASH (TYPE_CANONICAL (type)));
+
   if (TREE_TYPE (type))
     hstate.add_object (TYPE_HASH (TREE_TYPE (type)));

@@ -6109,6 +6112,9 @@ type_cache_hasher::equal (type_hash *a, type_hash *b)
          || TYPE_MODE (a->type) != TYPE_MODE (b->type)))
     return false;

+  if (TYPE_CANONICAL (a->type) != TYPE_CANONICAL (b->type))
+    return false;
+
   switch (TREE_CODE (a->type))
     {
     case VOID_TYPE:
@@ -7507,10 +7513,6 @@ build_function_type (tree value_type, tree arg_types,
       TYPE_NO_NAMED_ARGS_STDARG_P (t) = 1;
     }

-  /* If we already have such a type, use the old one.  */
-  hashval_t hash = type_hash_canon_hash (t);
-  t = type_hash_canon (hash, t);
-
   /* Set up the canonical type. */
   any_structural_p   = TYPE_STRUCTURAL_EQUALITY_P (value_type);
   any_noncanonical_p = TYPE_CANONICAL (value_type) != value_type;
@@ -7523,6 +7525,16 @@ build_function_type (tree value_type, tree arg_types,
     TYPE_CANONICAL (t) = build_function_type (TYPE_CANONICAL (value_type),
                                              canon_argtypes);

+  /* If we already have such a type, use the old one.  */
+  hashval_t hash = type_hash_canon_hash (t);
+  t = type_hash_canon (hash, t);
+
   if (!COMPLETE_TYPE_P (t))
     layout_type (t);
   return t;

Reply via email to