public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Matthew Malcomson <matmal01@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/vendors/ARM/heads/morello)] c: Add missing fold in build_binary_op
Date: Fri,  1 Oct 2021 09:16:43 +0000 (GMT)	[thread overview]
Message-ID: <20211001091643.AB1D83857C63@sourceware.org> (raw)

https://gcc.gnu.org/g:56b253703f286253cadc701e01984090766e3c15

commit 56b253703f286253cadc701e01984090766e3c15
Author: Alex Coplan <alex.coplan@arm.com>
Date:   Wed Sep 22 11:20:47 2021 +0100

    c: Add missing fold in build_binary_op
    
    In build_binary_op we call c_fully_fold on the address value operand
    before building a replace_address_value node, since c_fully_fold (which
    would otherwise be called later) can't fold inside replace_address_value
    nodes. However, this didn't account for possible c_maybe_const_expr
    nodes in the intcap expression itself. This adds a call to c_fully_fold
    for the intcap operand.
    
    gcc/c/ChangeLog:
    
            * c-typeck.c (build_binary_op): Also call c_fully_fold on the
            intcap operand before building a replace_address_value node.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/aarch64/morello/intcap-fold-ice.c: New test.

Diff:
---
 gcc/c/c-typeck.c                                           | 3 ++-
 gcc/testsuite/gcc.target/aarch64/morello/intcap-fold-ice.c | 9 +++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 5b6c6e186af..30a082b3144 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -12962,8 +12962,9 @@ build_binary_op (location_t location, enum tree_code code,
 	  intcap = convert (ic_type, intcap);
 
 	  /* We can't fold inside REPLACE_ADDRESS_VALUE calls, so ensure
-	     we've folded the address value expression.  */
+	     we've folded the operands.  */
 	  ret = c_fully_fold (ret, false, NULL);
+	  intcap = c_fully_fold (intcap, false, NULL);
 	  ret = fold_build_replace_address_value_loc (location, intcap, ret);
 	}
 
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/intcap-fold-ice.c b/gcc/testsuite/gcc.target/aarch64/morello/intcap-fold-ice.c
new file mode 100644
index 00000000000..95b73f8f7bb
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/intcap-fold-ice.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+
+/* This was ICEing due to a missing fold when building
+   replace_address_value nodes in the C frontend.  */
+
+struct {
+  __uintcap_t a;
+} * b;
+void c() { long a = (b ? b->a : 0) + a; }


                 reply	other threads:[~2021-10-01  9:16 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=20211001091643.AB1D83857C63@sourceware.org \
    --to=matmal01@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).