Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
xdu.c: Fixes need to compile xdu.c with -O2
I've choosen 'n/a' as initial string, because this clearly isn't a filename.
- Loading branch information
b5fda28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler detects the possible use of the uninitialized pointers only with -O2 ? Interesting.
b5fda28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b5fda28
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with latest gcc. See https://godbolt.org/z/yt-uN_
Well, -O0 is "Reduce compilation time and make debugging produce the expected results."
With -O1 it does a data flow analysis (producing the warning by the way) and tries to avoid conditional jumps.
Fun fact 1: It does so by preloading one of the case options into the variable. So in the default case we will no longer see random stack value in it, but the value of case 1 instead. I guess its legit to replace a "undefined" value with any other value.
Fun fact 2 : It tries to avoid a jump by using "cmove" (conditional move). However, as the conditional distinguished between case 2 and default and in the default case, the value is undefined anyway, it could have avoided the conditional move as well and just load the case 2 value instead.
In this reduced case (with no side effects in the case branches) it could even be reduced to
and avoid any conditional jump and possible pipeline stall.
Oh, I just see, that clang does exactly this! Switch to x64-46 clang (trunk).
A pitty, the kernel can't be compiler with clang yet (or can it?)