https://gcc.gnu.org/bugzilla/show_bug.cgi?id=73550
Bug ID: 73550
Summary: Another wrong -Wmaybe-uninitialized warning in switch
statement
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: amker at gcc dot gnu.org
Target Milestone: ---
Hi,
GCC trunk gives wrong -Wmaybe-uninitialized warning message on below switch
statement:
int fun1 (int, int);
int fun2 (int, int);
int fun3 (int, int);
void swap (int *, int *);
void abort (void);
void bar (void);
void foo (int code, int x, int a, int b)
{
int (*fp) (int, int);
switch (code)
{
case 1:
if (x == 1)
{
fp = fun3;
break;
}
case 2:
swap (&a, &b);
case 3:
case 4:
fp = fun1;
break;
case 11:
if (x == 1)
{
fp = fun3;
break;
}
case 12:
swap (&a, &b);
case 13:
case 14:
fp = fun2;
break;
case 5:
case 6:
case 7:
case 8:
break;
default:
abort ();
}
switch (code)
{
case 1:
case 3:
case 11:
case 13:
fp (a, b);
bar ();
break;
case 2:
case 4:
case 12:
case 14:
fp (a, b);
break;
case 5:
case 6:
case 7:
case 8:
bar ();
break;
default:
abort ();
}
return;
}
Compiled with:
$ ./gcc -O2 -S x.c -o x.S -Wmaybe-uninitialized
produces:
x.c: In function ‘foo’:
x.c:53:7: warning: ‘fp’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
fp (a, b);
^~~~~~~~~
GCC is configured as:
../gcc/configure --prefix=... --disable-bootstrap --disable-libssp
--disable-libgomp --disable-libsanitizer --disable-libitm --disable-atomic
CXXFLAGS='-g -O0' --enable-languages=c,c++