]> gcc.gnu.org Git - gcc.git/commitdiff
middle-end/100509 - avoid folding constant to aggregate type
authorRichard Biener <rguenther@suse.de>
Tue, 11 May 2021 08:58:35 +0000 (10:58 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 25 May 2021 06:54:24 +0000 (08:54 +0200)
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)

gcc/gimple-fold.c
gcc/testsuite/gcc.dg/pr100509.c [new file with mode: 0644]

index 9e6683dbac919eaf3d4fb7f3a77e7336cc71cb15..39356eaf66f2064e0992e20c3c71449911a8e768 100644 (file)
@@ -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 (file)
index 0000000..9405e2a
--- /dev/null
@@ -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; }
This page took 0.080035 seconds and 5 git commands to generate.