From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] middle-end/100786 - constant folding from incompatible alias
Date: Thu, 20 Jan 2022 14:58:21 +0100 (CET) [thread overview]
Message-ID: <3158023-8523-n61r-460-r7n98r84q57@fhfr.qr> (raw)
The following avoids us ICEing doing constant folding from variables
with aliases of different types. The formerly used fold_convert
wasn't entirely correct even for the cases it handled and using
a VIEW_CONVERT_EXPR avoids the ICE. Reading from a larger alias
will cause unfolded constants to appear but appearantly we handle
that just "fine".
b.0_1 = VIEW_CONVERT_EXPR<double>(1);
There is no obvious spot and way to just disable the constant folding
so I've not attempted to do that.
Boostrapped on x86_64-unknown-linux-gnu, testing in progress.
2022-01-20 Richard Biener <rguenther@suse.de>
PR middle-end/100786
* gimple-fold.cc (fold_stmt_1): Use a VIEW_CONVERT_EXPR on type
mismatches.
* gcc.dg/torture/pr100786.c: New testcase.
---
gcc/gimple-fold.cc | 2 +-
gcc/testsuite/gcc.dg/torture/pr100786.c | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/torture/pr100786.c
diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 08d3cc214ff..a4f1fdabc18 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -6264,7 +6264,7 @@ fold_stmt_1 (gimple_stmt_iterator *gsi, bool inplace, tree (*valueize) (tree))
if (new_rhs
&& !useless_type_conversion_p (TREE_TYPE (lhs),
TREE_TYPE (new_rhs)))
- new_rhs = fold_convert (TREE_TYPE (lhs), new_rhs);
+ new_rhs = fold_build1 (VIEW_CONVERT_EXPR, TREE_TYPE (lhs), new_rhs);
if (new_rhs
&& (!inplace
|| get_gimple_rhs_num_ops (TREE_CODE (new_rhs)) < old_num_ops))
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; }
--
2.31.1
next reply other threads:[~2022-01-20 13:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-20 13:58 Richard Biener [this message]
2022-01-20 14:02 ` Jakub Jelinek
2022-01-20 14:21 ` Richard Biener
2022-01-20 15:10 ` Richard Biener
2022-03-26 16:54 FX
2022-03-28 6:34 ` Richard Biener
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=3158023-8523-n61r-460-r7n98r84q57@fhfr.qr \
--to=rguenther@suse.de \
--cc=gcc-patches@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).