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 r11-8463] middle-end/100509 - avoid folding constant to aggregate type
Date: Tue, 25 May 2021 08:07:17 +0000 (GMT)	[thread overview]
Message-ID: <20210525080717.AE3E63896C1B@sourceware.org> (raw)

https://gcc.gnu.org/g:3870fe246f442d795ef2270c74f56dda9d0be26c

commit r11-8463-g3870fe246f442d795ef2270c74f56dda9d0be26c
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.
    
    (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 9e6683dbac9..39356eaf66f 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; }


                 reply	other threads:[~2021-05-25  8:07 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=20210525080717.AE3E63896C1B@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).