https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103720
Bug ID: 103720
Summary: bogus warning from -Wuninitialized +
-ftrivial-auto-var-init + O2
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: qinzhao at gcc dot gnu.org
Target Milestone: ---
There are multiple bogus warnings from -Wuninitialized +
-ftrivial-auto-var-init when building linux kernel the the latest upstream gcc.
One of them is from building fs/proc/array.c.
and I used Creduce to reduce into the following small testing case:
[opc@qinzhao-ol8u3-x86 tem]$ cat t.c
typedef struct {
unsigned long a[4];
} b;
int e, g;
long f;
int *h();
int *i(j) {
int *a = h(j);
return a;
}
void k(b *j) {
for (e = 1; e <= 4; ++e) {
b *b = j;
b->a[0] = f;
}
}
int l() {
b c;
unsigned long d;
i(&d);
k(&c);
g = c.a[0];
return 0;
}
[opc@qinzhao-ol8u3-x86 tem]$ sh t
/home/opc/Install/latest-d/bin/gcc -O2 -Wall -std=gnu89 -Werror
-Wno-pointer-sign -ftrivial-auto-var-init=zero t.c -S
t.c: In function ‘l’:
t.c:19:17: error: ‘c.a[0]’ is used uninitialized [-Werror=uninitialized]
19 | unsigned long d;
| ^
t.c:18:5: note: ‘c.a[0]’ was declared here
18 | b c;
| ^
cc1: all warnings being treated as errors