https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88719
Bug ID: 88719
Summary: [9 Regression] wrong code at -O2, -O3, and -Os on
x86_64-linux-gnu
Product: gcc
Version: 9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: chenjunjie9208 at 163 dot com
Target Milestone: ---
$ gcc -v
Using built-in specs.
COLLECT_GCC=./gcc
COLLECT_LTO_WRAPPER=/home/wgc/installs/gcc_trunks/trunk_r267367/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ./configure LDFLAGS=-Wl,--no-as-needed
--prefix=/home/wgc/installs/gcc_trunks/trunk_r267367
--with-gmp=/home/wgc/installs/gmp-6.1.2
--with-mpfr=/home/wgc/installs/mpfr-4.0.1
--with-mpc=/home/wgc/installs/mpc-1.1.0 --with-isl= --with-cloog=
--enable-languages=c,c++ --disable-multilib --disable-bootstrap
Thread model: posix
gcc version 9.0.0 20181223 (experimental) (GCC)
$ gcc -O0 program.c
$ ./a.out
0
$ gcc -O1 program.c
$ ./a.out
0
$ gcc -O2 program.c
$ ./a.out
-60
$ gcc -O3 program.c
$ ./a.out
-60
$ gcc -Os program.c
$ ./a.out
-60
$ cat program.c
struct a {
unsigned char b;
};
union {
short int c;
long int b;
} d = {2};
short int *e = &d.c;
long int *f[][1] = {&d.b, &d.b, &d.b, &d.b};
long int **g = &f[0][3];
unsigned int h;
int main() {
struct a i = {};
for (; i.b != 60; ++i.b)
if (**g = 0)
;
else if (*e)
--h;
printf("%d\n", h);
return 0;
}
The used operating system and CPU are as below:
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
Intel(R) Xeon(R) CPU E5-2640 v4 @ 2.40GHz