https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119913
Bug ID: 119913
Summary: Incorrect code with -ftrivial-auto-var-init=zero
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: fanghs666 at gmail dot com
Target Milestone: ---
static int a[2][2][2] = {};
int printf(const char *, ...);
int main() {
int b, c;
for(;;) {
if (!b) break;
}
for(int i = 0; i < 2; i++) {
for(int j = 0; j < 2; j++) {
for(int k = 0; k < 2; k++) {
printf("%d", a[i][j][k]);
if(c)
printf("%d\n", j);
}
}
}
return 0;
}
The expected output should be "00000000".
$ gcc-trunk -O3 -ftrivial-auto-var-init=zero a.c
$ ./a.out
000000
It seems that the optimizations didn't take zero initialization into account.