TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

GCC proves an uninitialized variable must be 0 and doesn't warn about it

114 pointsby tbodtabout 6 years ago

8 comments

floatingatollabout 6 years ago
To summarize various replies in the thread:<p>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.
评论 #19302963 未加载
rcdmdabout 6 years ago
Explanation here (from 2004): <a href="https:&#x2F;&#x2F;gcc.gnu.org&#x2F;ml&#x2F;gcc&#x2F;2004-12&#x2F;msg00681.html" rel="nofollow">https:&#x2F;&#x2F;gcc.gnu.org&#x2F;ml&#x2F;gcc&#x2F;2004-12&#x2F;msg00681.html</a><p>It&#x27;s not that GCC proves the uninitialized variable must be 0, it&#x27;s just that CCP sets it to 0 and everything happens to work out in specific cases.
评论 #19308251 未加载
ncmncmabout 6 years ago
What I don&#x27;t understand is why it doesn&#x27;t optimize away the check on (inode-&gt;i_nlink), since it is assuming the code in the dependent block always runs.<p>It has to be assuming that, because it is the only path that doesn&#x27;t lead to undefined behavior.
评论 #19304904 未加载
dandigangiabout 6 years ago
Random question - what are the _underscores_ that show up frequently in Linus&#x27;s responses?
评论 #19305613 未加载
评论 #19303880 未加载
评论 #19303886 未加载
wyldfireabout 6 years ago
Aside: static analysis is a great initial effort but to really get confidence you should use techniques like sanitizers (MSan in this case) or valgrind. (This is general advice, not always applicable to kernels).
评论 #19304520 未加载
评论 #19304647 未加载
pfdietzabout 6 years ago
A simple way to avoid this problem is prohibit, in that code base, local variable declarations without initializers. If the initializer truly was unneeded the compiler would be able to eliminate it in almost all cases. Risking undefined behavior for hypothetical microspeedups is just dumb. If a case occurs where leaving out the initializer is both useful and safe then the initializer could be removed there, after deliberate review.
zzo38computerabout 6 years ago
It look like a bug to me, since inode-&gt;i_nlink may be zero, and then ret is uninitialized (optimizing the final &quot;return ret&quot; to &quot;return 0&quot; 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).
评论 #19303729 未加载
saagarjhaabout 6 years ago
Unrelated, but it&#x27;s interesting to see the &quot;new&quot; Linus: no cursing, and no calling people morons.
评论 #19345681 未加载
评论 #19302828 未加载
评论 #19302826 未加载
评论 #19302823 未加载