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.
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;
--- /dev/null
+/* { 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; }