diff options
author | Richard Biener <rguenther@suse.de> | 2021-05-11 10:58:35 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2021-05-11 12:48:05 +0200 |
commit | ca8e8301180fa71de1a76769fc038df2ab85dfeb (patch) | |
tree | f6badc25ee1b91ebc8d74ef1ade19a8c53c4f6cc /gcc | |
parent | 9b905ba9ebba8d2cc805c26351225e7f74c02333 (diff) | |
download | gcc-ca8e8301180fa71de1a76769fc038df2ab85dfeb.zip gcc-ca8e8301180fa71de1a76769fc038df2ab85dfeb.tar.gz gcc-ca8e8301180fa71de1a76769fc038df2ab85dfeb.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/gimple-fold.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr100509.c | 9 |
2 files changed, 11 insertions, 1 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 768ef89..6beb4f3 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 0000000..9405e2a --- /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; } |