This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/49971] New: Missing "uninitialized" warning; may involve "return" statements
- From: "cernekee at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 4 Aug 2011 00:29:09 +0000
- Subject: [Bug c/49971] New: Missing "uninitialized" warning; may involve "return" statements
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49971
Summary: Missing "uninitialized" warning; may involve "return"
statements
Product: gcc
Version: 4.5.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: cernekee@gmail.com
This code does not produce any warnings ("uninitialized" or otherwise) on gcc
4.4.3, 4.4.5, or 4.5.3:
int testcase(unsigned int in)
{
int a = 0, b;
a++;
if (in == 1)
return -1;
b++;
return a + b;
}
Command line: gcc -O2 -c test.c -o test.o -Wall
Disassembly:
0000000000000000 <testcase>:
0: b8 ff ff ff ff mov $0xffffffff,%eax
5: c3 retq
(IOW, it silently changed the entire function into "return -1")
Compiler:
$ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5'
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--enable-multiarch --enable-linker-build-id --with-system-zlib
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls
--enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc
--disable-werror --with-arch-32=i486 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)
gcc 4.2.0 and 4.3.5 do produce a warning, using the same command lines.
-O0 on gcc 4.4.3 / 4.4.5 / 4.5.3 does produce a warning. -O[123s] do not.
If I leave "a" uninitialized, gcc will produce a warning. "a" does not seem to
be strictly necessary to reproduce the problem involving "b".
If I assign the value of "b" to a global variable before returning, gcc will
produce a warning.