------- Comment #1 from manu at gcc dot gnu dot org  2010-03-14 15:45 -------
In GCC 4.3.x you need optimization enabled for Wuninitialized.

In GCC 4.4.1 and GCC 4.5 (trunk) I get warnings in line 6 with -O1 -O2 and -O3.

We do not get a warning with -O0 because the default definition appears in a
PHI node:

<bb 2>:
  [pr43361.C : 6 : 3] goto <bb 4>;

<bb 3>:
  [pr43361.C : 7:19] std::basic_ostream<char>::operator<< ([pr43361.C : 7]
&cout, i_1);
  [pr43361.C : 8:18] [pr43361.C : 8] array[i_1] = i_1;
  [pr43361.C : 6:3] i_4 = i_1 + 1;

<bb 4>:
  # i_1 = PHI <i_2(D)(2), [pr43361.C : 6:3] i_4(3)>
  [pr43361.C : 6:3] D.21125_3 = i_1 <= 9;
  [pr43361.C : 6:3] if (D.21125_3 != 0)
    goto <bb 3>;
  else
    goto <bb 5>;

<bb 5>:
  [pr43361.C : 0:0] D.21127_5 = 0;
  return D.21127_5;


This can be seen as a natural limitation of the analysis at -O0 or a problem
with the way GCC represents loops:

for (init; test; next) { for-body }; is transformed to:

init:
 init;
 goto eval
body:
  for-body;
  next;
  goto eval;
eval:
 (test) ? goto body : goto finish;
finish:

So, although we know what "test" is evaluated at least once after init, GCC
doesn't know that with -O0.

In any case, there is no trivial fix (but there is a workaround: use
optimization).


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org
OtherBugsDependingO|                            |24639
              nThis|                            |
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-03-14 15:45:50
               date|                            |
            Summary|[g++-4.3..g++-4.5] for-loops|missing uninitialzied
                   |are in the way of           |warning without optimization
                   |Wuninitialized?             |(loop representation)


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43361

Reply via email to