This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Uninitialized use warning message
- From: Eyal Lebedinsky <eyal at eyal dot emu dot id dot au>
- To: gcc at gcc dot gnu dot org
- Date: Sat, 27 Aug 2005 10:08:03 +1000
- Subject: Re: Uninitialized use warning message
- References: <430F923C.4080803@sco.com>
Kean Johnston wrote:
> Hello everyone,
>
> There is a warning message I would dearly love to see improved
> a little. Its the one where you use a variable without it being
> initialized first:
>
> foo.c:123: warning: `foo' might be used unitialized in this function
>
> Obviously, there was some code somewhere that used variable
> `foo' to trigger the warning. What I would dearly love to see
> is the warning message be a bit more informative, along the
> lines of:
>
> foo.c:123: warning: `foo' might be used unitialized in this function
> foo.c:234: warning: possible use of unitialized `foo'
> foo.c:345: warning: possible use of unitialized `foo'
>
> You get the idea. Does anyone else think this would be useful?
> Do we even have sufficient data available to be able to produce
> such warnings? I figured I'd ask first before diving into the code.
Well, this is not this simple. It is usually easy for me to find where
it is used (possibly uninitialised). The harder part is finding the
control path that leads there without initialisation.
A common situation would be:
if (condition) {
flag = 1
msg = "Hello World";
} else
flag = 0; [1]
...
if (flag)
printf ("I say, %s\n", msg); [2]
Point [1] is where I "fail" to init 'msg', point [2] is where I
use it. I know that the program is safe, and if the flow analysis
can relate 'flag' and 'msg' then the warning would go away.
Which one would we want listed in the proposed new warning, 1 or 2?
Naturally, there can be multiple 1s and 2s for the same variable.
--
Eyal Lebedinsky (eyal@eyal.emu.id.au) <http://samba.org/eyal/>
attach .zip as .dat