Bug 49971

Summary: Missing "uninitialized" warning; may involve "return" statements
Product: gcc Reporter: Kevin Cernekee <cernekee>
Component: middle-endAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: manu
Priority: P3    
Version: 4.5.3   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Kevin Cernekee 2011-08-04 00:29:06 UTC
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.
Comment 1 Andrew Pinski 2011-08-04 00:55:52 UTC
This is the standard CCP optimization getting in the way of uninitialized variable warnings.
Comment 2 Manuel López-Ibáñez 2011-08-04 08:41:02 UTC
(In reply to comment #1)
> This is the standard CCP optimization getting in the way of uninitialized
> variable warnings.

Correct.

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