Bug 13127 - [4.0 Regression] Inlining causes spurious "might be used uninitialized" warnings
Summary: [4.0 Regression] Inlining causes spurious "might be used uninitialized" warnings
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: tree-ssa
: P2 normal
Target Milestone: 4.0.0
Assignee: Richard Henderson
URL:
Keywords: diagnostic, patch
Depends on: 13000 13863
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2003-11-19 15:05 UTC by Steven Bosscher
Modified: 2005-11-02 19:17 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.4.0
Known to fail:
Last reconfirmed: 2005-01-09 00:48:14


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steven Bosscher 2003-11-19 15:05:42 UTC
While looking at Bug 13000 I noticed this bug.  Consider: 
 
static int foo (int a) { } 
int main (void) { return foo (0); } 
 
Compile this with "-O2 -Wall" and you can see that when finalizing 
`main' (after inlining foo of course), we produce this strange warning: 
 
t.i:2: warning: '({anonymous})' might be used uninitialized in this function 
 
Wtf  :-) 
 
Of course this is a regression from mainline and older GCCs. 
 
 
-------------- 
$ cat t.i 
static int foo (int a) { } 
int main (void) { return foo (0); } 
$ cc1 --version 
GNU C version 3.5-tree-ssa 20031119 (merged 20031111) (i686-pc-linux-gnu) 
        compiled by GNU C version 3.5-tree-ssa 20031119 (merged 20031111). 
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 
$ cc1 -O -Wall t.i 
 foo 
t.i: In function `foo': 
t.i:1: warning: control reaches end of non-void function 
 main 
 
$ cc1 -O2 -Wall t.i 
 main 
t.i: In function `main': 
t.i:2: warning: '({anonymous})' might be used uninitialized in this function
Comment 1 Volker Reichelt 2003-11-20 16:26:35 UTC
With little variations you can get all sorts of funny behavior:

==================================
int foo () {} 
int main () { return foo(); }
==================================
leads to

x.cc: In function `int foo()':
x.cc:1: warning: control reaches end of non-void function

which looks OK to me. However, with

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

I get

x.cc: In function `int foo()':
x.cc:1: warning: no return statement in function returning non-void
x.cc: In function `int main()':
x.cc:2: warning: '<anonymous>' might be used uninitialized in this function
Comment 2 Wolfgang Bangerth 2003-11-20 16:31:46 UTC
Volker: How do the two code snippets differ? I think one should be
different from the other, right?

W.
Comment 3 Volker Reichelt 2003-11-21 23:28:33 UTC
Sorry. Cut-and-pasto. :-(
The second example should read

==================================
inline int foo () {} 
int main () { return foo(); }
==================================
Comment 4 Andrew Pinski 2004-02-06 06:17:23 UTC
Using my patch for 13863 (which I am about to post) and setting TREE_NO_WARNING 
for the decl which was created, this will be fixed.

Mine as I can fix this.
Comment 5 Andrew Pinski 2004-02-06 07:12:18 UTC
the fix would be set TREE_NO_WARNING in declare_return_variable on var, will test 
after the patch for 13863 is done testing.
Comment 6 Andrew Pinski 2004-02-06 15:42:29 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-02/msg00561.html>.
Comment 7 GCC Commits 2004-02-06 21:30:11 UTC
Subject: Bug 13127

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	tree-ssa-20020619-branch
Changes by:	pinskia@gcc.gnu.org	2004-02-06 21:30:06

Modified files:
	gcc            : ChangeLog.tree-ssa tree-inline.c 
	gcc/testsuite  : ChangeLog.tree-ssa 
Added files:
	gcc/testsuite/gcc.dg: 20040206-1.c 

Log message:
	2004-02-06  Andrew Pinski  <pinskia@physics.uc.edu>
	
	PR middle-end/13127
	* tree-inline.c (declare_return_variable): Set the no warning bit
	on the variable created for the return value.
	
	2004-02-06  Andrew Pinski  <pinskia@physics.uc.edu>
	
	PR middle-end/13127
	* gcc.dg/20040206-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.tree-ssa.diff?cvsroot=gcc&only_with_tag=tree-ssa-20020619-branch&r1=1.1.2.1162&r2=1.1.2.1163
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-inline.c.diff?cvsroot=gcc&only_with_tag=tree-ssa-20020619-branch&r1=1.26.2.80&r2=1.26.2.81
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.tree-ssa.diff?cvsroot=gcc&only_with_tag=tree-ssa-20020619-branch&r1=1.1.2.162&r2=1.1.2.163
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20040206-1.c.diff?cvsroot=gcc&only_with_tag=tree-ssa-20020619-branch&r1=NONE&r2=1.1.2.1

Comment 8 Andrew Pinski 2004-02-06 21:31:16 UTC
The uninitialized warning is fixed, the only warning left is the one referenced in 13000, the testcase has 
been xfailed for it.
Comment 9 Richard Henderson 2004-08-18 07:34:44 UTC
Broken again.
Comment 10 Richard Henderson 2004-08-18 07:35:09 UTC
Mine.
Comment 11 Andrew Pinski 2004-09-24 04:11:05 UTC
Since this broke again, my patch will not help anymore.
Comment 12 Steven Bosscher 2004-12-20 01:02:48 UTC
Still there... 
Comment 13 Andrew Pinski 2005-01-17 03:01:22 UTC
Ian posted a patch here: <http://gcc.gnu.org/ml/gcc-patches/2005-01/msg00957.html>.
Comment 14 GCC Commits 2005-01-17 17:13:18 UTC
Subject: Bug 13127

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ian@gcc.gnu.org	2005-01-17 17:12:31

Modified files:
	gcc            : ChangeLog tree-inline.c 

Log message:
	PR middle-end/13127:
	* tree-inline.c (expand_call_inline): Set TREE_NO_WARNING on
	a variable set to the return value of the inlined function.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.7152&r2=2.7153
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-inline.c.diff?cvsroot=gcc&r1=1.162&r2=1.163

Comment 15 Ian Lance Taylor 2005-01-17 17:13:52 UTC
Fixed.
Comment 16 GCC Commits 2005-01-17 17:17:15 UTC
Subject: Bug 13127

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ian@gcc.gnu.org	2005-01-17 17:17:02

Modified files:
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/gcc.dg: 20040206-1.c 

Log message:
	PR middle-end/13127
	* gcc.dg/20040206-1.c: Remove xfail on bogus warning which is no
	longer emitted.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4896&r2=1.4897
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/20040206-1.c.diff?cvsroot=gcc&r1=1.3&r2=1.4