User account creation filtered due to spam.

Bug 49971 - Missing "uninitialized" warning; may involve "return" statements
Summary: Missing "uninitialized" warning; may involve "return" statements
Status: RESOLVED DUPLICATE of bug 18501
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.5.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-04 00:29 UTC by Kevin Cernekee
Modified: 2011-08-04 08:41 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***