User account creation filtered due to spam.
int foo(int x)
if (x) return a;
This function should trigger the "‘a’ may be used uninitialized" warning when compiled with -O -Wall, but it doesn't; there are no diagnostics at all. The assembly output (x86-64) is just
movl $0, %eax
Looking at optimization dumps, this is what we have right before CCP1:
foo (int x)
if (x_2(D) != 0)
goto <bb 3>;
goto <bb 4>;
a_4 = a_3(D);
goto <bb 5>;
a_5 = 0;
# a_1 = PHI <a_4(3), a_5(4)>
but right *after* CCP1, we have instead
# a_1 = PHI <a_4(3), 0(4)>
-- I presume that CCP notices that one of the inputs to the PHI is undefined and ignores that possibility under the "well, if that happened, there would be undefined behavior, so we can assume that can't happen" principle. CDDCE1 then erases the remainder of the code and we're left with
foo (int x)
which has no uninitialized variable accesses, of course. I'm not sure exactly where uninitialized warnings happen these days, but clearly it's after this point.
As far as a fix, I recommend either that any pass that can make use of the "that variable is uninitialized so we're going to ignore the possibility of that control path" principle should emit -Wuninitialized warnings, or (my personal preference) we scrap the notion of doing -Wuninitialized from inside the optimizers, and switch to something predictable, like Java's definite assignment rules.
If this testcase works in GCC 4.3.5 is just by chance. This is the old PR18501. There is plenty of analysis, discussion and proposals there for anyone interested in giving it a try.
*** This bug has been marked as a duplicate of bug 18501 ***
This regression is triggered by revision 133341: