Bug 100509 - [9 Regression] ICE at -O3: in fold_convert_loc with variable (attribute) alias of different types
Summary: [9 Regression] ICE at -O3: in fold_convert_loc with variable (attribute) alia...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 12.0
: P2 normal
Target Milestone: 9.5
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2021-05-10 19:34 UTC by Chengnian Sun
Modified: 2021-10-13 10:10 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 10.3.1, 11.1.1, 12.0
Known to fail: 10.3.0, 11.1.0, 9.4.0
Last reconfirmed: 2021-05-11 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chengnian Sun 2021-05-10 19:34:17 UTC
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.
Comment 1 Andrew Pinski 2021-05-10 21:15:33 UTC
(In reply to Chengnian Sun from comment #0)
> Not sure whether this is a dup of PR96131.

It is unrelated.
Comment 2 Richard Biener 2021-05-11 07:07:57 UTC
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.
Comment 3 Martin Liška 2021-05-11 08:09:36 UTC
Started with r5-4443-g016adb0549c554d7.
Comment 4 GCC Commits 2021-05-11 10:48:45 UTC
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.
Comment 5 Richard Biener 2021-05-11 10:49:18 UTC
Fixed on trunk sofar.
Comment 6 GCC Commits 2021-05-25 08:07:18 UTC
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)
Comment 7 Richard Biener 2021-06-01 08:20:51 UTC
GCC 9.4 is being released, retargeting bugs to GCC 9.5.
Comment 8 GCC Commits 2021-06-16 14:24:15 UTC
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)
Comment 9 GCC Commits 2021-10-13 10:09:10 UTC
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)
Comment 10 Richard Biener 2021-10-13 10:10:35 UTC
Fixed.