Seongbae Park ??? ??? wrote:
David,
Just in case you haven't noticed this thread - I figured you may want
to comment on it.
Seongbae
---------- Forwarded message ----------
From: Manuel López-Ibáñez <[EMAIL PROTECTED]>
Date: Wed, Oct 22, 2008 at 2:00 PM
Subject: Re: conditional assigments vs. "may be used uninitialized"
To: Hallvard B Furuseth <[EMAIL PROTECTED]>
Cc: gcc@gcc.gnu.org
2008/10/22 Hallvard B Furuseth <[EMAIL PROTECTED]>:
Info node (gcc)Warning Options mentions that gcc warns about
int save_y;
if (change_y) save_y = y, y = new_y;
...
if (change_y) y = save_y;
However that's not always true, so it looks like gcc does have
the smarts to drop the warning. Could that be improved?
Currently gcc relies on jump threading to get this right (path
sensitivity). I have a patch that does predicate aware uninitialized
variable analysis which does not rely on any such transformations. It
covers the following cases (simple example shown):
Example 1:
flag = 0;
if (some_condition)
{
v = ....
flag = 1;
}
....
if (flag)
{
use (v);
}
This case usually results from inline transformation as in:
if (init_var(&v) == false)
return;
use (v);
Example 2:
if (cond1)
v = ...
...
if (cond2)
use (v);
if cond1 is a superset of cond2, no warning is given.
For instance:
if (x > 0 || y > 0)
v = ...
...
if (x > 10)
if ( m < 0)
use (v);
The patch is pretty big, so I am waiting for stage1 is reopened to submit.
Thanks,
David
In the case of Wuninitialized warnings, if GCC gets the answer right,
it may not get the answer by the same reasoning as you. A notable
example is the following code:
1 sub()
2 {
3 int i = 0;
4 int j = 0;
5 int k;
6
7 while ((i | j) == 0)
8 {
9 k = 10;
10 i = sub ();
11 }
12
13 return k;
14 }
Here GCC does not warn for line 13. But GCC never knows that the loop
is executed at least once. In fact what happens is that GCC assumes
that the uninitialized value of k is 10 and hence it propagates this
value so line 13 becomes return 10. If you substitute 0 by a variable
in line 7 there is still no warning.
If you are interested in improving uninitialized warnings I would
suggest to take a look to
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings
(It is perhaps a bit outdated, since a few things have improved in GCC 4.4).
Cheers,
Manuel.