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.
State-Changed-From-To: open->suspended State-Changed-Why: The well-known if (p) set q; if (p) use q; problem.
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.
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~
*** Bug 19062 has been marked as a duplicate of this bug. ***
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
*** Bug 21357 has been marked as a duplicate of this bug. ***
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.
Actually this is easy to find a testcase where we do warn (turning off DOM is an easy example)
*** Bug 21750 has been marked as a duplicate of this bug. ***
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);
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
*** Bug 27289 has been marked as a duplicate of this bug. ***
Some year we'll have to use the control dependence graph to see if all the conditions are the same :)
*** Bug 29479 has been marked as a duplicate of this bug. ***
*** Bug 30086 has been marked as a duplicate of this bug. ***
*** Bug 31688 has been marked as a duplicate of this bug. ***
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.
> 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.
(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.
See comment 17 and comment 19. This is fixed by chance by CCP, so not worth to keep it open.