Bug 39113

Summary: no warning that a variable may be used uninitialized
Product: gcc Reporter: David Hill <dhill>
Component: cAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: dberlin, dhill, fredrik, gcc-bugs, jellegeerts, manu, mark, mueller, P.Schaffnit, pinskia, satyam, thutt
Priority: P3 Keywords: diagnostic
Version: 4.3.2   
Target Milestone: ---   
Host: --host=x86_64-linux-gnu Target: --target=x86_64-linux-gnu
Build: --build=x86_64-linux-gnu Known to work:
Known to fail: Last reconfirmed:
Attachments: .i file

Description David Hill 2009-02-05 20:49:46 UTC
$gcc -O -Wextra -save-temps um3.c
$

um3.c

#include <stdio.h>

main()
{
char *J;

if (rand())
  J = NULL;

printf("\ntest %s\n",J);
}


In this example, J could be used uninitialized but the compiler is not giving that warning.
Comment 1 David Hill 2009-02-05 20:51:24 UTC
Created attachment 17252 [details]
.i file
Comment 2 David Hill 2009-02-05 21:04:03 UTC
Here is the gcc -v output if that is helpful

$ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.2-1ubuntu12' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu12) 
Comment 3 David Hill 2009-02-05 21:48:20 UTC
Note that the warning is correctly reported in older versions of the compiler.

The following example is from gcc 3.2.3


$ gcc -O -W um3.c
um3.c: In function `main':
um3.c:5: warning: `J' might be used uninitialized in this function


$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-59)

$ cat um3.c
#include <stdio.h>

main()
{
char *J;

if (rand())
  J = NULL;

printf("\ntest %s\n",J);
}

Comment 4 Andrew Pinski 2009-02-05 21:57:12 UTC

*** This bug has been marked as a duplicate of 18501 ***

*** This bug has been marked as a duplicate of 18501 ***