https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89501
Bug ID: 89501 Summary: Odd lack of warning about missing initialization Product: gcc Version: 8.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: torva...@linux-foundation.org Target Milestone: --- Created attachment 45820 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45820&action=edit You can compile this to see a lack of warning. We had a simple kernel patch that introduced a stupid bug due to an uninitialized variable, and while we got it all sorted out and the fix was trivial, people were surprised by the lack of warning for the uninitialized case. I'm adding a test-case as an attachment that largely matches the kernel code that didn't warn. But it boils down to a pattern of int ret; /* UNINITIALIZED */ if (somecondition) { ret = functioncall(x); if (ret) return ret; } .. some more work .. return ret; /* Possibly uninitialized return value! */ What I *suspect* happens is (a) gcc sees that there is only one assignment to "ret" (b) in the same basic block as the assignment, there is a test against "ret" being nonzero that goes out. and what I think happens is that (a) causes gcc to consider that assignment to be the defining assignment (which makes all kinds of sense in an SSA world), and then (b) means that gcc decides that clearly "ret" has to be zero in any case that doesn't go out due to the if-test. So it turns out that gcc almost by mistake generates code that works (and doesn't warn about it, exactly because it works), even though the source code was clearly buggy. The attached test-case is stupid but intentionally made to be as close to the kernel source case as possible. With it, I can do: Look, ma: no warning: gcc -O2 -S -Wall test.c but this gives the expected warning: gcc -O2 -S -Wall -DHIDE_PROBLEM test.c regardless, this is not a huge problem for us, but I decided to make a report since we have a test case, and maybe somebody gets excited about it. Thanks, Linus