public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Avoid changing type in the type_hash_canon hash
@ 2024-05-03 10:58 Richard Biener
  2024-05-03 11:00 ` Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Biener @ 2024-05-03 10:58 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

When building a type and type_hash_canon returns an existing type
avoid changing it, in particular its TYPE_CANONICAL.

Bootstrapped and tested on x86_64-unknown-linux-gnu for all languages.

OK for trunk?

Thanks,
Richard.

	PR middle-end/114931
	* tree.cc (build_array_type_1): Return early when type_hash_canon
	returned an older existing type.
	(build_function_type): Likewise.
	(build_method_type_directly): Likewise.
	(build_offset_type): Likewise.
---
 gcc/tree.cc | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/gcc/tree.cc b/gcc/tree.cc
index 83f3bf306af..780662549fe 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -7352,7 +7352,10 @@ build_array_type_1 (tree elt_type, tree index_type, bool typeless_storage,
   if (shared)
     {
       hashval_t hash = type_hash_canon_hash (t);
+      tree probe_type = t;
       t = type_hash_canon (hash, t);
+      if (t != probe_type)
+	return t;
     }
 
   if (TYPE_CANONICAL (t) == t && set_canonical)
@@ -7509,7 +7512,10 @@ build_function_type (tree value_type, tree arg_types,
 
   /* If we already have such a type, use the old one.  */
   hashval_t hash = type_hash_canon_hash (t);
+  tree probe_type = t;
   t = type_hash_canon (hash, t);
+  if (t != probe_type)
+    return t;
 
   /* Set up the canonical type. */
   any_structural_p   = TYPE_STRUCTURAL_EQUALITY_P (value_type);
@@ -7663,7 +7669,10 @@ build_method_type_directly (tree basetype,
 
   /* If we already have such a type, use the old one.  */
   hashval_t hash = type_hash_canon_hash (t);
+  tree probe_type = t;
   t = type_hash_canon (hash, t);
+  if (t != probe_type)
+    return t;
 
   /* Set up the canonical type. */
   any_structural_p
@@ -7720,7 +7729,10 @@ build_offset_type (tree basetype, tree type)
 
   /* If we already have such a type, use the old one.  */
   hashval_t hash = type_hash_canon_hash (t);
+  tree probe_type = t;
   t = type_hash_canon (hash, t);
+  if (t != probe_type)
+    return t;
 
   if (!COMPLETE_TYPE_P (t))
     layout_type (t);
-- 
2.35.3

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Avoid changing type in the type_hash_canon hash
  2024-05-03 10:58 [PATCH] Avoid changing type in the type_hash_canon hash Richard Biener
@ 2024-05-03 11:00 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2024-05-03 11:00 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Fri, May 03, 2024 at 12:58:55PM +0200, Richard Biener wrote:
> When building a type and type_hash_canon returns an existing type
> avoid changing it, in particular its TYPE_CANONICAL.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu for all languages.
> 
> OK for trunk?
> 
> Thanks,
> Richard.
> 
> 	PR middle-end/114931
> 	* tree.cc (build_array_type_1): Return early when type_hash_canon
> 	returned an older existing type.
> 	(build_function_type): Likewise.
> 	(build_method_type_directly): Likewise.
> 	(build_offset_type): Likewise.

LGTM, thanks.

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-03 11:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-03 10:58 [PATCH] Avoid changing type in the type_hash_canon hash Richard Biener
2024-05-03 11:00 ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).