Bug 19099 - No warning for uninitialized local variable use
Summary: No warning for uninitialized local variable use
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.4.1
: P2 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-21 07:39 UTC by Gopal V
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: powerpc-unknown-linux-gnu
Target: powerpc-unknown-linux-gnu
Build: powerpc-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Simple test case (198 bytes, text/plain)
2004-12-21 07:40 UTC, Gopal V
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gopal V 2004-12-21 07:39:14 UTC
Code similar to the one below does not give a warning (though one is expected).

int foo()
{
  int x = x;
  return x;
}

Though this code in itself seems stupid - this is how it hid into my codebase 
(in a simplified example).

#include <stdio.h>

#define macro2(imm) \
	do {\
		int __value = (imm);\
		printf("macro2 got %d\n", __value);\
	}while(0)

#define macro3(imm) \
	do { \
		int __value = (imm);\
		printf("macro3 got %d\n", __value);\
	} while(0);
#define macro1(imm)\
	do {\
		int __value = (imm);\
		printf("macro1 got %d\n", __value);\
		macro2(__value);\
		macro3(__value);\
	}while(0)

int foobar()
{
	printf("foobar was called\n");
	return 42;
}
int main()
{
	macro1(foobar());
	return 0;
}

The expected output was 
"""
foobar was called 
macro1 got 42
macro2 got 42
macro3 got 42
"""

But I get
"""
gopal@sweden samples $ gcc -Wall -pedantic -ansi -O3 test.c
gopal@sweden samples $ ./a.out 
foobar was called
macro1 got 42
macro2 got 805441120
macro3 got 805441120
"""

The original code was spread accross 4 files. I think the code 
should generate a valid warning because the variable is as good
as being stack/register junk . 

Tested with "gcc (GCC) 3.4.1 20040803 (Gentoo Linux 3.4.1-r3, ssp-3.4-2,
pie-8.7.6.5)".
Comment 1 Gopal V 2004-12-21 07:40:21 UTC
Created attachment 7788 [details]
Simple test case

Generates different output with different optimisation levels - but no warnings
at all.
Comment 2 Andrew Pinski 2004-12-21 15:20:08 UTC
Use -Winit-self and -Wuninitialized (and -O1).

See <http://gcc.gnu.org/onlinedocs/gcc-3.4.3/gcc/Warning-Options.html#Warning-Options> where 
this is documented.
Comment 3 GCC Commits 2005-01-14 00:34:02 UTC
Subject: Bug 19099

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rth@gcc.gnu.org	2005-01-14 00:33:51

Modified files:
	gcc            : ChangeLog 
	gcc/config/i386: i386-protos.h i386.c i386.md 

Log message:
	PR target/19099
	PR target/19250
	PR target/19252
	* config/i386/i386.md (cmpdf, cmpsf, bunordered, bordered, buneq,
	bunge, bungt, bunle, bunlt, bltgt): Enable for TARGET_SSE_MATH,
	not just TARGET_SSE.
	(cmpfp_i_387): Rename from cmpfp_i.  Move after sse patterns.
	(cmpfp_i_mixed): Rename from cmpfp_i_sse; use for TARGET_MIX_SSE_I387.
	(cmpfp_i_sse): Rename from cmpfp_i_sse_only; use for TARGET_SSE_MATH.
	(cmpfp_iu_mixed, cmpfp_iu_sse, cmpfp_iu_387): Similarly.
	(fp_jcc_1_mixed, fp_jcc_1_sse, fp_jcc_1_387): Similarly.
	(fp_jcc_2_mixed, fp_jcc_2_sse, fp_jcc_2_387): Similarly.
	(fp_jcc_3_387, fp_jcc_4_387, fp_jcc_5_387, fp_jcc_6_387,
	fp_jcc_7_387, fp_jcc_8_387): Rename from fp_jcc_N.
	(movdicc_c_rex64): Rename with '*'.
	(movsfcc, movdfcc): Add checks for 387 and sse math to condition.
	(movsfcc_1_sse_min, movsfcc_1_sse_max, movsfcc_1_sse): New.
	(movsfcc_1_387): Rename from movsfcc_1.
	(movdfcc_1_sse_min, movdfcc_1_sse_max, movdfcc_1_sse): New.
	(movdfcc_1, movdfcc_1_rex64): Add check for 387.
	(sminsf3, smaxsf3, smindf3, smaxdf3): New.
	(minsf3, minsf, minsf_nonieee, minsf_sse, mindf3, mindf,
	mindf_nonieee, mindf_sse, maxsf3, maxsf, maxsf_nonieee, maxsf_sse,
	maxdf3, maxdf, maxdf_nonieee, maxdf_sse, sse_movsfcc, sse_movsfcc_eq,
	sse_movdfcc, sse_movdfcc_eq, sse_movsfcc_const0_1,
	sse_movsfcc_const0_2, sse_movsfcc_const0_3, sse_movsfcc_const0_4,
	sse_movdfcc_const0_1, sse_movdfcc_const0_2, sse_movdfcc_const0_3,
	sse_movdfcc_const0_4): Remove.
	* config/i386/i386.c (ix86_expand_fp_movcc): For TARGET_SSE_MATH,
	recognize min/max early.  Update for changed sse cmove patterns.
	(ix86_split_sse_movcc): New.
	* config/i386/i386-protos.h: Update.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.7114&r2=2.7115
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386-protos.h.diff?cvsroot=gcc&r1=1.125&r2=1.126
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.c.diff?cvsroot=gcc&r1=1.776&r2=1.777
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.md.diff?cvsroot=gcc&r1=1.605&r2=1.606