https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65182
Bug ID: 65182
Summary: -Wuninitialized fails when pointer to variable later
passed to function
Product: gcc
Version: 4.9.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: tisaac at ices dot utexas.edu
Created attachment 34848
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34848&action=edit
Test program that demonstrates -Wuninitialized failure
If a pointer to a variable is passed *after* it is used uninitialized, then
-Wuninitialized fails to report.
Test code:
>cat test.c
#include <stdio.h>
#include <stdlib.h>
void
bar(int *a)
{
*a = 2;
}
int
baz (void)
{
return 3;
}
void
foo(int *b)
{
int a;
if (a) {
*b = 0;
return;
}
#if defined(USE_AS_POINTER)
bar(&a);
#endif
a = baz();
*b = a + 2;
}
int
main (int argc, char **argv)
{
int c;
c = atoi(argv[1]);
foo(&c);
return c;
}
>gcc-4.9 -O0 -Wuninitialized -c -o test.o test.c
test.c: In function ‘foo’:
test.c:21:6: warning: ‘a’ is used uninitialized in this function
[-Wuninitialized]
if (a) {
^
>gcc-4.9 -DUSE_AS_POINTER -O0 -Wuninitialized -c -o test.o test.c
[no output]
>uname --all
Linux alembic 3.2.0-76-generic #111-Ubuntu SMP Tue Jan 13 22:16:09 UTC 2015
x86_64 x86_64 x86_64 GNU/Linux
>gcc-4.9 --version
gcc-4.9 (Ubuntu 4.9.2-0ubuntu1~12.04) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.