------- Comment #2 from rguenth at gcc dot gnu dot org 2010-03-15 11:27 ------- (In reply to comment #1) > 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).
The trivial fix would be to compute post-dominator info and check if the edge with the uninitialized use is executed on all paths from function entry to exit (its source and destination post-dominate the entry bb). -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43361