From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 64BE739490A1; Fri, 6 May 2022 11:08:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 64BE739490A1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-10041] middle-end/100786 - constant folding from incompatible alias X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/releases/gcc-9 X-Git-Oldrev: 4aae279dc74afe6cc9c1799824d44b64bc824d2f X-Git-Newrev: fba3068ec155e4d9a3074d55d3c3b1111c0bcb84 Message-Id: <20220506110855.64BE739490A1@sourceware.org> Date: Fri, 6 May 2022 11:08:55 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 May 2022 11:08:55 -0000 https://gcc.gnu.org/g:fba3068ec155e4d9a3074d55d3c3b1111c0bcb84 commit r9-10041-gfba3068ec155e4d9a3074d55d3c3b1111c0bcb84 Author: Richard Biener 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 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 aea4ea0c6e8..0166fdae0c0 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -274,7 +274,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; }