https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64614
Bug ID: 64614
Summary: bogus used initialized warning (in gcc 4.9.2 not in
4.8.3); switch statement versus &
Product: gcc
Version: 4.9.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: dgilbert at redhat dot com
gcc t.c -O1 -Wall -Wextra
(Any -O value 1 or above)
t.c: In function ‘foo’:
t.c:15:15: warning: ‘tmp’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
tmp[11] = 15;
^
(This code is similar to qemu's arch_init.c/ram_load loop where I hit this)
Gcc doesn't seem to be spotting that the tmp = baz initialiser will always
happen for the switch cases that use tmp.
this is using the Fedora 21 gcc: gcc version 4.9.2 20141101 (Red Hat 4.9.2-1)
(GCC)
package: gcc-4.9.2-1.fc21.x86_64
It doesn't trigger for me on gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC)
char *foo(int bar, char *baz)
{
char *tmp;
if (bar & 3) {
tmp = baz;
}
switch (bar) {
case 1:
tmp[5] = 7;
break;
case 2:
tmp[11] = 15;
break;
default:
tmp = 0;
break;
}
return tmp;
}