Bug 5035

Summary: Incorrectly produces '`<var>' might be used uninitialized in this function'
Product: gcc Reporter: thutt
Component: tree-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: enhancement CC: burnus, fang, fnf, gcc-bugs, j.w.r.degoede, manu, midoegal, mkoegler, P.Schaffnit, rolandsun, rth, thutt, trick, william
Priority: P3 Keywords: diagnostic
Version: unknown   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2005-09-07 16:57:24
Bug Depends on:    
Bug Blocks: 24639    
Attachments: defect.c

Description thutt 2001-12-06 09:16:01 UTC
gcc -v -c -O2 -Wall defect.c
Incorrectly produces the following warning:
 defect.c:7: warning: `b' might be used uninitialized in this function

'a' is local and not aliased.
'b' is local and not aliased.

Both uses of 'b' are under the same control conditions; the
compiler should not produce this warning.

Release:
egcs-2.91.66

Environment:
uname -a reports     : Linux thutt-lx 2.2.17 #3 Mon Oct 1 20:43:58 PDT 2001 i686 unknown

How-To-Repeat:
Follow instructions in source file.
Comment 1 Richard Henderson 2002-04-26 01:56:30 UTC
State-Changed-From-To: open->suspended
State-Changed-Why: The well-known
      if (p) set q;
      if (p) use q;
    problem.
Comment 2 thutt 2002-04-29 05:49:45 UTC
From: Taylor Hutt <thutt@vmware.com>
To: rth@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org,
        nobody@gcc.gnu.org, thutt@vmware.com, gcc-gnats@gcc.gnu.org
Cc:  
Subject: Re: c/5035: Incorrectly produces '`<var>' might be used uninitialized in this function'
Date: 29 Apr 2002 05:49:45 -0700

 rth@gcc.gnu.org writes:
 
 > Synopsis: Incorrectly produces '`<var>' might be used uninitialized in this function'
 > 
 > State-Changed-From-To: open->suspended
 > State-Changed-By: rth
 > State-Changed-When: Fri Apr 26 01:56:30 2002
 > State-Changed-Why:
 >     The well-known
 >       if (p) set q;
 >       if (p) use q;
 >     problem.
 > 
 > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5035
 
 This is the most worthless response to a defect report I have ever seen.

Comment 3 Richard Henderson 2002-04-29 10:37:47 UTC
From: Richard Henderson <rth@redhat.com>
To: Taylor Hutt <thutt@vmware.com>
Cc: rth@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org,
   nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Subject: Re: c/5035: Incorrectly produces '`<var>' might be used uninitialized in this function'
Date: Mon, 29 Apr 2002 10:37:47 -0700

 On Mon, Apr 29, 2002 at 05:49:45AM -0700, Taylor Hutt wrote:
 > This is the most worthless response to a defect report I have ever seen.
 
 You're welcome.
 
 It's just that this exact problem has been reported many times,
 and it is distinctly non-trivial to fix.  Thus I suspended it.
 
 
 r~
Comment 4 Andrew Pinski 2004-12-17 23:13:00 UTC
*** Bug 19062 has been marked as a duplicate of this bug. ***
Comment 5 Giovanni Bajo 2004-12-17 23:35:34 UTC
Some discussion about how this warning interacts with the tree-ssa framework 
can be found here:

http://gcc.gnu.org/ml/gcc/2004-12/msg00681.html
http://gcc.gnu.org/ml/gcc-patches/2004-12/msg01309.html
Comment 6 Joseph S. Myers 2005-05-03 20:20:37 UTC
*** Bug 21357 has been marked as a duplicate of this bug. ***
Comment 7 Jeffrey A. Law 2005-11-08 17:03:37 UTC
The SSA optimizers clean this testcase enough to no longer emit a bogus uninitialized warning.  It is (of course) possible to create more complex tests which would still generate bogus uninitialized warnings.
Comment 8 Andrew Pinski 2005-11-26 16:39:03 UTC
Actually this is easy to find a testcase where we do warn (turning off DOM is an easy example)
Comment 9 Andrew Pinski 2005-11-26 16:39:26 UTC
*** Bug 21750 has been marked as a duplicate of this bug. ***
Comment 10 Gerry 2005-12-22 10:38:21 UTC
Maybe you could add a new variable attribute so that these warnings could at least be avoided in cases where the coder knows the code is correct ?  Something like:

int x __attribute__((__notuninited__));
if (y) x = 0;
if (y) use(x);
Comment 11 Andrew Pinski 2005-12-22 14:22:29 UTC
Subject: Re:  Incorrectly produces '`<var>' might be used uninitialized in this function'


On Dec 22, 2005, at 5:38 AM, trick at icculus dot org wrote:

>
>
> ------- Comment #10 from trick at icculus dot org  2005-12-22 10:38 
> -------
> Maybe you could add a new variable attribute so that these warnings 
> could at
> least be avoided in cases where the coder knows the code is correct ?
> Something like:
>
> int x __attribute__((__notuninited__));

int x = x;

Will make the warning go away, plus this is documented in the options 
section
under -Winit-self.

-- Pinski

Comment 12 Andrew Pinski 2006-04-24 17:06:35 UTC
*** Bug 27289 has been marked as a duplicate of this bug. ***
Comment 13 Daniel Berlin 2006-06-13 15:22:43 UTC
Some year we'll have to use the control dependence graph to see if all the conditions are the same :)
Comment 14 Andrew Pinski 2006-10-15 17:30:25 UTC
*** Bug 29479 has been marked as a duplicate of this bug. ***
Comment 15 Andrew Pinski 2006-12-13 07:31:23 UTC
*** Bug 30086 has been marked as a duplicate of this bug. ***
Comment 16 Andrew Pinski 2007-04-24 20:05:45 UTC
*** Bug 31688 has been marked as a duplicate of this bug. ***
Comment 17 Manuel López-Ibáñez 2007-08-22 17:48:48 UTC
The warning is not emitted any more in GCC 4.1.2 and I am fairly sure that this case is covered by gcc.dg/uninit-5.c and gcc.dg/uninit-9.c, so I am tempted to close this as fixed.
Comment 18 Tobias Burnus 2007-08-22 18:07:08 UTC
> so I am tempted to close this as fixed.

At least PR 27289 and PR 29479 (marked as duplicate of this PR) seem still to show the bug.
Comment 19 Manuel López-Ibáñez 2007-08-22 18:47:37 UTC
(In reply to comment #18)
> > so I am tempted to close this as fixed.
> 
> At least PR 27289 and PR 29479 (marked as duplicate of this PR) seem still to
> show the bug.
> 

They shouldn't be duplicates then. Here, the warning does not show up because CCP is assuming that the uninitialized value of b is 10. Thus, the return value is either 10 or 0 but never "uninitialized".

PR29479 seems a duplicate of PR27289 (the latter seems a reduced testcase of the former). The warning shows up because: 1) SRA generates a PHI node that contains the uninitialized value 2) CCP is not working here.
Comment 20 Manuel López-Ibáñez 2008-02-01 17:05:42 UTC
See comment 17 and comment 19. This is fixed by chance by CCP, so not worth to keep it open.