Message ID | 20211018174137.579907-1-pbonzini@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [GIT,PULL] KVM fixes for Linux 5.15-rc7 | expand |
On Mon, Oct 18, 2021 at 7:42 AM Paolo Bonzini <pbonzini@redhat.com> wrote: > > * avoid warning with -Wbitwise-instead-of-logical Christ. Please no. Guys, you can't just mindlessly shut off warnings without even thinking about the code. Apparently the compiler gives completely insane warning "fixes" suggestions, and somebody just completely mindlessly followed that compiler badness. The way to do a logical "or" (instead of a bitwise one on two boolean expressions) is to use "||". Instead, the code was changed to completely insane (int) boolexpr1 | (int) boolexpr2 thing, which is entirely illegible and pointless, and no sane person should ever write code like that. In other words, the *proper* fix to a warning is to look at the code, and *unsderstand* the code and the warning, instead of some mindless conversion to just avoid a warning. NEVER EVER do mindless changes to source code because the compiler tells you to. Apparently the clang people wrote a particularly bad warning "explanation", and that's on clang. I'm not going to pull this. The clang warning fix is wrong, and then another commit literally disables accounting for another non-fatal run-time warning. Again - warnings are not an excuse to just "mindlessly shut up the warning". They need some thought. None of this kind of "I'll do wrong things just to make the warning go away" garbage that this pull request has two very different examples of. I'm adding some clang people, because apparently that note: cast one or both operands to int to silence this warning thing came from clang. Somebody in the clang community really needs to re-think their "informational" messages. Giving people those kinds of insane suggestions is a disservice to everybody. Clang should fix their stupid "note" before release. Please, guys. Linus
On 18/10/21 19:57, Linus Torvalds wrote: > The way to do a logical "or" (instead of a bitwise one on two boolean > expressions) is to use "||". > > Instead, the code was changed to completely insane > > (int) boolexpr1 | (int) boolexpr2 > > thing, which is entirely illegible and pointless, and no sane person > should ever write code like that. > > In other words, the*proper* fix to a warning is to look at the code, > and*unsderstand* the code and the warning, instead of some mindless > conversion to just avoid a warning. The code is not wrong, there is a comment explaining it: * Use a bitwise-OR instead of a logical-OR to aggregate the reserved * bits and EPT's invalid memtype/XWR checks to avoid an extra Jcc * (this is extremely unlikely to be short-circuited as true). Paolo
On Mon, Oct 18, 2021 at 8:03 AM Paolo Bonzini <pbonzini@redhat.com> wrote: > > The code is not wrong, there is a comment explaining it: > > * Use a bitwise-OR instead of a logical-OR to aggregate the reserved > * bits and EPT's invalid memtype/XWR checks to avoid an extra Jcc > * (this is extremely unlikely to be short-circuited as true). That makes very little sense. It seems to be avoiding a 'jcc' and replace it with a 'setcc' and an 'or'. Which is likely both bigger and slower. If the jcc were unpredictable, maybe that would be one thing. But at least from a quick look, that doesn't even seem likely The other use of that function has a "WARN_ONCE()" on it, so presumably it normally doesn't ever trigger either of the boolean conditions. Very strange code. Linus
On 18/10/21 20:15, Linus Torvalds wrote: >> * Use a bitwise-OR instead of a logical-OR to aggregate the reserved >> * bits and EPT's invalid memtype/XWR checks to avoid an extra Jcc >> * (this is extremely unlikely to be short-circuited as true). > That makes very little sense. > > It seems to be avoiding a 'jcc' and replace it with a 'setcc' and an > 'or'. Which is likely both bigger and slower. The compiler knows that the setcc is unnecessary, because a!=0|b!=0 is the same as (a|b)!=0. > If the jcc were unpredictable, maybe that would be one thing. But at > least from a quick look, that doesn't even seem likely > > The other use of that function has a "WARN_ONCE()" on it, so > presumably it normally doesn't ever trigger either of the boolean > conditions. Yes, and that was why it used a "|". Anyway, not worth arguing for or against; I'll just change it to logical OR. Paolo