public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6385] lto: Fix up lto_fixup_prevailing_type [PR108910]
@ 2023-03-01  8:59 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2023-03-01  8:59 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:9b4f7004a77b10bc403875f56c94f73ef86562d8

commit r13-6385-g9b4f7004a77b10bc403875f56c94f73ef86562d8
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Mar 1 09:54:52 2023 +0100

    lto: Fix up lto_fixup_prevailing_type [PR108910]
    
    Without LTO, TYPE_POINTER_TO/TYPE_REFERENCE_TO chains are only maintained
    inside of build_{pointer,reference}_type_for_mode and those routines
    ensure that the pointer/reference type added to the chain is really
    without any user attributes (unless something would modify the types
    in place, but that would be wrong).
    
    Now, LTO adds stuff to these chains in lto_fixup_prevailing_type but
    doesn't guarantee that.  The testcase in the PR (which I'm not including
    for testsuite because when (I hope) the aarch64 backend bug will be fixed,
    the testcase would work either way) shows a case where user has
    TYPE_USER_ALIGN type with very high alignment, as there aren't enough
    pointers to float in the code left that one becomes the prevailing one
    (because types with attributes are created with build_distinct_type_copy
    and thus their own TYPE_MAIN_VARIANTs), lto_fixup_prevailing_type puts
    it into the TYPE_POINTER_TO chain of float and later on during expansion
    of __builtin_cexpif expander uses build_pointer_type (float_type_node)
    to emit a sincosf call and instead of getting a normal pointer type gets
    this non-standard one.
    
    The following patch fixes that by not adding into those chains
    types with TYPE_ATTRIBUTES, and for REFERENCE_TYPEs not even with
    TYPE_REF_IS_RVALUE - while the C++ FE adds those into those chains,
    it always ensures such a type goes immediately after the corresponding
    non-TYPE_REF_IS_RVALUE REFERENCE_TYPE with the same
    mode/TYPE_REF_CAN_ALIAS_ALL, so LTO would need to ensure that too, but
    TYPE_REF_IS_RVALUE types are looked that way only in the C++ FE.
    
    2023-03-01  Jakub Jelinek  <jakub@redhat.com>
    
            PR target/108910
            * lto-common.cc (lto_fixup_prevailing_type): Don't add t to
            TYPE_POINTER_TO or TYPE_REFERENCE_TO chain if it has
            TYPE_ATTRIBUTES or is TYPE_REF_IS_RVALUE.

Diff:
---
 gcc/lto/lto-common.cc | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/gcc/lto/lto-common.cc b/gcc/lto/lto-common.cc
index b166d175478..882dd8971a4 100644
--- a/gcc/lto/lto-common.cc
+++ b/gcc/lto/lto-common.cc
@@ -984,21 +984,25 @@ lto_fixup_prevailing_type (tree t)
       TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
       TYPE_NEXT_VARIANT (mv) = t;
     }
-
-  /* The following reconstructs the pointer chains
-     of the new pointed-to type if we are a main variant.  We do
-     not stream those so they are broken before fixup.  */
-  if (TREE_CODE (t) == POINTER_TYPE
-      && TYPE_MAIN_VARIANT (t) == t)
-    {
-      TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (TREE_TYPE (t));
-      TYPE_POINTER_TO (TREE_TYPE (t)) = t;
-    }
-  else if (TREE_CODE (t) == REFERENCE_TYPE
-	   && TYPE_MAIN_VARIANT (t) == t)
-    {
-      TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (TREE_TYPE (t));
-      TYPE_REFERENCE_TO (TREE_TYPE (t)) = t;
+  else if (!TYPE_ATTRIBUTES (t))
+    {
+      /* The following reconstructs the pointer chains
+	 of the new pointed-to type if we are a main variant.  We do
+	 not stream those so they are broken before fixup.
+	 Don't add it if despite being main variant it has
+	 attributes (then it was created with build_distinct_type_copy).
+	 Similarly don't add TYPE_REF_IS_RVALUE REFERENCE_TYPEs.
+	 Don't add it if there is something in the chain already.  */
+      if (TREE_CODE (t) == POINTER_TYPE)
+	{
+	  TYPE_NEXT_PTR_TO (t) = TYPE_POINTER_TO (TREE_TYPE (t));
+	  TYPE_POINTER_TO (TREE_TYPE (t)) = t;
+	}
+      else if (TREE_CODE (t) == REFERENCE_TYPE && !TYPE_REF_IS_RVALUE (t))
+	{
+	  TYPE_NEXT_REF_TO (t) = TYPE_REFERENCE_TO (TREE_TYPE (t));
+	  TYPE_REFERENCE_TO (TREE_TYPE (t)) = t;
+	}
     }
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-01  8:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-01  8:59 [gcc r13-6385] lto: Fix up lto_fixup_prevailing_type [PR108910] 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).