public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-10549] middle-end/100786 - constant folding from incompatible alias
Date: Thu, 21 Apr 2022 12:52:04 +0000 (GMT)	[thread overview]
Message-ID: <20220421125204.14E7E380DBE9@sourceware.org> (raw)

https://gcc.gnu.org/g:1e1b247774e0239f73b59e07f30db4e400f9b4eb

commit r10-10549-g1e1b247774e0239f73b59e07f30db4e400f9b4eb
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Jan 20 14:25:51 2022 +0100

    middle-end/100786 - constant folding from incompatible alias
    
    The following avoids us ICEing doing constant folding from variables
    with aliases of different types.  The issue appears both in
    folding and CCP and FRE can do more fancy stuff to still constant
    fold cases where the load is smaller than the initializer so
    defer it to there.
    
    2022-01-20  Richard Biener  <rguenther@suse.de>
    
            PR middle-end/100786
            * gimple-fold.c (get_symbol_constant_value): Only return
            values of compatible type to the symbol.
    
            * gcc.dg/torture/pr100786.c: New testcase.
    
    (cherry picked from commit 5c12507f5d0bc080e4f346af99824e039236e61c)

Diff:
---
 gcc/gimple-fold.c                       | 4 +++-
 gcc/testsuite/gcc.dg/torture/pr100786.c | 9 +++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 912540dc8a7..969c3998421 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -285,7 +285,9 @@ get_symbol_constant_value (tree sym)
       if (val)
 	{
 	  val = canonicalize_constructor_val (unshare_expr (val), sym);
-	  if (val && is_gimple_min_invariant (val))
+	  if (val
+	      && is_gimple_min_invariant (val)
+	      && useless_type_conversion_p (TREE_TYPE (sym), TREE_TYPE (val)))
 	    return val;
 	  else
 	    return NULL_TREE;
diff --git a/gcc/testsuite/gcc.dg/torture/pr100786.c b/gcc/testsuite/gcc.dg/torture/pr100786.c
new file mode 100644
index 00000000000..42f4e485593
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr100786.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+
+const double a = 0;
+extern int b __attribute__((alias("a")));
+void inc() { b++; }
+
+const int a2 = 0;
+extern double b2 __attribute__((alias("a2")));
+void inc2() { b2+=1; }


                 reply	other threads:[~2022-04-21 12:52 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=20220421125204.14E7E380DBE9@sourceware.org \
    --to=rguenth@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).