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 r12-712] middle-end/100509 - avoid folding constant to aggregate type Date: Tue, 11 May 2021 10:48:44 +0000 (GMT) [thread overview] Message-ID: <20210511104844.215D73846416@sourceware.org> (raw) https://gcc.gnu.org/g:ca8e8301180fa71de1a76769fc038df2ab85dfeb commit r12-712-gca8e8301180fa71de1a76769fc038df2ab85dfeb Author: Richard Biener <rguenther@suse.de> 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 <rguenther@suse.de> 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. 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 768ef89d876..6beb4f3d305 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -547,7 +547,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; }
reply other threads:[~2021-05-11 10:48 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=20210511104844.215D73846416@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: linkBe 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).