https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110286
Bug ID: 110286
Summary: Wrong code at -O2 on x86_64-linux-gnu
(nondeterministic output)
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: shaohua.li at inf dot ethz.ch
Target Milestone: ---
For the following code, gcc trunk at -O2 emits wrong code. If you run the
compiled code multiple times, you will observe different outputs.
$ cat a.c
int printf(const char *, ...);
char a;
int b;
short c;
short(d)(short e) { return e + c; }
int f;
char g;
char g_0;
int h;
void i() {
for (; h; f++)
switch (g_0)
case '"':
case '\\':
++g;
}
short j;
static int aa;
int k;
const int *l;
const int **m = &l;
short n;
signed o;
int p = 84134051;
unsigned r = 1;
int ag;
static char ah() {
int ai = 0;
if (r)
aj : {
i();
short *ak = &n;
ag = 78003764;
*m = &ag;
*ak = 1;
for (; *l + p - 162153904 + k; k++)
for (; p - 168260671 > 3; ai++) {
*ak = o && 5;
if (a) {
int *al = &aa;
short *am = &j;
*al &= b;
*am = 0;
}
}
if (d((*ak)--))
;
else if (*l)
goto aj;
}
return 0;
}
int main() {
ah();
printf("%d\n", n);
}
$
$ gcc-tk -O0 a.c && ./a.out
0
$ gcc-tk -O2 a.c
$ ./a.out
518
$ ./a.out
514
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-27612ce352921d74086102d9ad4d3e011923f837/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-27612ce352921d74086102d9ad4d3e011923f837
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230616 (experimental) (GCC)
$