From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 555B7385042B; Wed, 16 Jun 2021 14:24:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 555B7385042B 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 r10-9921] middle-end/100509 - avoid folding constant to aggregate type X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: cedce283c319103e039ae2659d0d7473dd8efeca X-Git-Newrev: cd712310edc2ffeec8982ba5f9aeaa0b14e93cf1 Message-Id: <20210616142414.555B7385042B@sourceware.org> Date: Wed, 16 Jun 2021 14:24:14 +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: Wed, 16 Jun 2021 14:24:14 -0000 https://gcc.gnu.org/g:cd712310edc2ffeec8982ba5f9aeaa0b14e93cf1 commit r10-9921-gcd712310edc2ffeec8982ba5f9aeaa0b14e93cf1 Author: Richard Biener Date: Tue May 11 10:58:35 2021 +0200 middle-end/100509 - avoid folding constant to aggregate type When folding a constant initializer looking through aliases to incompatible types can lead to us trying to fold a constant to an aggregate type which can't work. Simply avoid trying to constant fold non-register typed symbols. 2021-05-11 Richard Biener PR middle-end/100509 * gimple-fold.c (fold_gimple_assign): Only call get_symbol_constant_value on register type symbols. * gcc.dg/pr100509.c: New testcase. (cherry picked from commit ca8e8301180fa71de1a76769fc038df2ab85dfeb) Diff: --- gcc/gimple-fold.c | 3 ++- gcc/testsuite/gcc.dg/pr100509.c | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index b8754dcc105..912540dc8a7 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -445,7 +445,8 @@ fold_gimple_assign (gimple_stmt_iterator *si) CONSTRUCTOR_ELTS (rhs)); } - else if (DECL_P (rhs)) + else if (DECL_P (rhs) + && is_gimple_reg_type (TREE_TYPE (rhs))) return get_symbol_constant_value (rhs); } break; diff --git a/gcc/testsuite/gcc.dg/pr100509.c b/gcc/testsuite/gcc.dg/pr100509.c new file mode 100644 index 00000000000..9405e2a27df --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr100509.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O" } */ + +struct X { + int a; +}; +const int a = 0; +static struct X A __attribute__((alias("a"))); +void foo() { struct X b = A; }