To summarize various replies in the thread: This is a variation of an unfixed 2004 GCC bug. Clang detects the issue when the right warnings are enabled. Those warnings are disabled currently. A developer is auditing and fixing all such instances found by Clang so that they can reenable those warnings.
What are the right warnings?
GCC proves an uninitialized variable must be 0 and doesn't warn about it
11–20 of 67 posts
Re: GCC proves an uninitialized variable must be 0 and doesn't warn about it
#12It look like a bug to me, since inode->i_nlink may be zero, and then ret is uninitialized (optimizing the final "return ret" to "return 0" should be safe (but is not necessarily worth it, depending on the target instruction set and ABI), although if warnings are enabled, it seem like the warning should still be displayed).
So after the if, the compiler sees that ret is either 0, or an undefined value.
It picks 0 as the undefined value since that's a good optimization, so ret is now always 0, and (in this case) there is no warning.
Re: GCC proves an uninitialized variable must be 0 and doesn't warn about it
#13Re: GCC proves an uninitialized variable must be 0 and doesn't warn about it
#14Re: GCC proves an uninitialized variable must be 0 and doesn't warn about it
#15Random question - what are the _underscores_ that show up frequently in Linus's responses?
Re: GCC proves an uninitialized variable must be 0 and doesn't warn about it
#16Random question - what are the _underscores_ that show up frequently in Linus's responses?
Re: GCC proves an uninitialized variable must be 0 and doesn't warn about it
#17Random question - what are the _underscores_ that show up frequently in Linus's responses?
It's for emphasis. Some people use asterisks. He uses underscores.
Re: GCC proves an uninitialized variable must be 0 and doesn't warn about it
#18It look like a bug to me, since inode->i_nlink may be zero, and then ret is uninitialized (optimizing the final "return ret" to "return 0" should be safe (but is not necessarily worth it, depending on the target instruction set and ABI), although if warnings are enabled, it seem like the warning should still be displayed).
The compiler is allowed to do that. Since it would be undefined behavior to read the undefined variable, the compiler gets to pick whatever value it wants for it. So after the if, the compiler sees that ret is either 0, or an undefined value. It picks 0 as the undefined value since that's a good optimization, so ret is now always 0, and (in this case) there is no warning.
Re: GCC proves an uninitialized variable must be 0 and doesn't warn about it
#19Re: GCC proves an uninitialized variable must be 0 and doesn't warn about it
#20It has to be assuming that, because it is the only path that doesn't lead to undefined behavior.