On Mon, Feb 25, 2019 at 12:34 PM Hugh Dickins wrote: > > Seems like a gcc bug? But I don't have a decent recent gcc to hand > to submit a proper report, hope someone else can shed light on it. I don't have a _very_ recent gcc either, but with gcc-8.2.1 the attached test-case gives me: [torvalds@i7 ~]$ gcc -O2 -S -Wall test.c with no warning, and then [torvalds@i7 ~]$ gcc -O2 -S -Wall -DHIDE_PROBLEM test.c test.c: In function ‘shmem_link’: test.c:60:9: warning: ‘ret’ may be used uninitialized in this function [-Wmaybe-uninitialized] return ret; ^~~ *does* show the expected warning. So it is the presence of that if (ret) return ret; that suppresses the warning. 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. In fact, if I then look at the code generation, gcc will actually do this (edited to be more legible): movl (%rbx), %eax <- load inode->i_nlink testl %eax, %eax je .L1 ... ... call d_instantiate xorl %eax, %eax <- explicitly zero 'ret'! .L1: popq %rbx popq %rbp popq %r12 ret so at least with my compiler, it *effectively* zeroed ret (in %rax) anyway, and it all just _happened_ to get the right result even though 'ret' wasn't actually initialized. Which is why it all worked just fine. And depending on how gcc works internally, it really may not just be a random mistake of register allocation, but really because gcc kind of _thought_ that 'ret' was zero-initialized due to the combination of the one single assigment and test for zero. So it turns out that the patch to initialize to zero doesn't do anything, probably for the same reason that gcc didn't warn about the missing initialization. Gcc kind of added an initialization of its own there. I'm not entirely sure if any gcc developer would be interested in this as a test-case, but I guess I can try to do a bugzilla. Adding a few gcc people who have been on previous kernel gcc bugzilla discussions, just in case they have something to add. The gcc bugzilla is this: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89501 and I tried to make it be self-explanatory, but I wrote the bugzilla in parallel with this email, and maybe there's some missing context either there (or here). Linus