Not sure whether this is a dup of PR96131. $ gcc-trunk -v Using built-in specs. COLLECT_GCC=gcc-trunk COLLECT_LTO_WRAPPER=/scratch/software/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /tmp/tmp.FRQzt2wMfl-gcc-builder/gcc/configure --enable-languages=c,c++,lto --enable-checking-yes --enable-multiarch --prefix=/scratch/software/gcc-trunk --disable-bootstrap Thread model: posix Supported LTO compression algorithms: zlib gcc version 12.0.0 20210510 (experimental) [master revision :fb3a8fb4a:25f9f35a85ffee808fc1482b14d91176df59751b] (GCC) $ cat mutant.c struct X { int a; }; const a = 0; static struct X A __attribute__((alias("a"))); foo() { struct X b = A; } $ gcc-trunk -O3 mutant.c mutant.c:4:7: warning: type defaults to ‘int’ in declaration of ‘a’ [-Wimplicit-int] 4 | const a = 0; | ^ mutant.c:6:1: warning: return type defaults to ‘int’ [-Wimplicit-int] 6 | foo() { struct X b = A; } | ^~~ during GIMPLE pass: forwprop mutant.c: In function ‘foo’: mutant.c:6:16: internal compiler error: in fold_convert_loc, at fold-const.c:2552 6 | foo() { struct X b = A; } | ^ 0x6bd7c1 fold_convert_loc(unsigned int, tree_node*, tree_node*) /tmp/tmp.FRQzt2wMfl-gcc-builder/gcc/gcc/fold-const.c:2552 0xc02486 fold_stmt_1 /tmp/tmp.FRQzt2wMfl-gcc-builder/gcc/gcc/gimple-fold.c:6269 0x1032191 execute /tmp/tmp.FRQzt2wMfl-gcc-builder/gcc/gcc/tree-ssa-forwprop.c:3108 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions.
(In reply to Chengnian Sun from comment #0) > Not sure whether this is a dup of PR96131. It is unrelated.
I will have a look. The code is border-line valid only, the alias ties objects of incompatible type. It goes wrong during fold_gimple_assign which eventually calls get_symbol_constant_value.
Started with r5-4443-g016adb0549c554d7.
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>: 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.
Fixed on trunk sofar.
The releases/gcc-11 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>: 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)
GCC 9.4 is being released, retargeting bugs to GCC 9.5.
The releases/gcc-10 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>: https://gcc.gnu.org/g:cd712310edc2ffeec8982ba5f9aeaa0b14e93cf1 commit r10-9921-gcd712310edc2ffeec8982ba5f9aeaa0b14e93cf1 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)
The releases/gcc-9 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>: https://gcc.gnu.org/g:379382c438652b594f0e91a61dbfce05eab080bd commit r9-9768-g379382c438652b594f0e91a61dbfce05eab080bd 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)
Fixed.