public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Alex Coplan <acoplan@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/vendors/ARM/heads/morello)] middle-end: Fix ICE in tree-ssa-forwprop
Date: Tue, 12 Jul 2022 10:36:39 +0000 (GMT)	[thread overview]
Message-ID: <20220712103639.066503857BAB@sourceware.org> (raw)

https://gcc.gnu.org/g:587fdc0303ff883a899e474f20c42cc96997c7b6

commit 587fdc0303ff883a899e474f20c42cc96997c7b6
Author: Alex Coplan <alex.coplan@arm.com>
Date:   Mon Jun 20 17:52:10 2022 +0100

    middle-end: Fix ICE in tree-ssa-forwprop
    
    This fixes an ICE in tree-ssa-forwprop.c:forward_propagate_addr_expr_1
    which was due to a case of TYPE_PRECISION not being updated to one of
    TYPE_[NON]CAP_PRECISION. Here we assert that for capability types, the
    two types must have the same precision. For non-capability types, we
    preserve the behaviour of the existing code (recursing on widening or
    equal-precision conversions), but use TYPE_NONCAP_PRECISION to avoid
    tripping the check when we handle capability types.
    
    gcc/ChangeLog:
    
            * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Update
            TYPE_PRECISION check to handle capability types.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/aarch64/morello/forwprop-ice.c: New test.

Diff:
---
 gcc/testsuite/gcc.target/aarch64/morello/forwprop-ice.c |  7 +++++++
 gcc/tree-ssa-forwprop.c                                 | 11 +++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.target/aarch64/morello/forwprop-ice.c b/gcc/testsuite/gcc.target/aarch64/morello/forwprop-ice.c
new file mode 100644
index 00000000000..901caec9356
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/forwprop-ice.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* This test would ICE in the tree-ssa-forwprop pass due to the
+   conversion between two distinct capability types.  */
+typedef int (*T)();
+void *p;
+void f(T);
+void g() { f((T)(p + 1)); }
diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c
index 6dee66a5322..ff4b81ea237 100644
--- a/gcc/tree-ssa-forwprop.c
+++ b/gcc/tree-ssa-forwprop.c
@@ -701,13 +701,20 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs,
 	  return true;
 	}
 
+      /* If we have a conversion between two capability types, they should have
+	 the same precision.  */
+      gcc_assert (!capability_type_p (TREE_TYPE (lhs))
+		  || !capability_type_p (TREE_TYPE (def_rhs))
+		  || TYPE_CAP_PRECISION (TREE_TYPE (lhs))
+		     == TYPE_CAP_PRECISION (TREE_TYPE (def_rhs)));
+
       /* Else recurse if the conversion preserves the address value.  */
       if ((INTEGRAL_TYPE_P (TREE_TYPE (lhs))
 	   || POINTER_TYPE_P (TREE_TYPE (lhs)))
 	  && (capability_type_p (TREE_TYPE (lhs))
 	      == capability_type_p (TREE_TYPE (def_rhs)))
-	  && (TYPE_PRECISION (TREE_TYPE (lhs))
-	      >= TYPE_PRECISION (TREE_TYPE (def_rhs))))
+	  && (TYPE_NONCAP_PRECISION (TREE_TYPE (lhs))
+	      >= TYPE_NONCAP_PRECISION (TREE_TYPE (def_rhs))))
 	return forward_propagate_addr_expr (lhs, def_rhs, single_use_p);
 
       return false;


                 reply	other threads:[~2022-07-12 10:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220712103639.066503857BAB@sourceware.org \
    --to=acoplan@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).