public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-712] middle-end/100509 - avoid folding constant to aggregate type
@ 2021-05-11 10:48 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-05-11 10:48 UTC (permalink / raw)
To: gcc-cvs
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; }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-05-11 10:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-11 10:48 [gcc r12-712] middle-end/100509 - avoid folding constant to aggregate type Richard Biener
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).