r373743 - [NFCI] Improve the -Wbool-operation's warning message

Dávid Bolvanský via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 8 12:38:24 PDT 2019


Yeah, I tried to fix even that case but is not so simple so not worth any extra time/complexivity.

> Dňa 8. 10. 2019 o 19:09 užívateľ Arthur O'Dwyer <arthur.j.odwyer at gmail.com> napísal:
> 
> 
> On Mon, Oct 7, 2019 at 6:58 PM Dávid Bolvanský <david.bolvansky at gmail.com> wrote:
> >> FWIW I found the "always evaluates to 'true'" bit important to
> >> understand the warning.
> >
> > Yeah. I moved this check somewhere else, so we can print precise message:
> > r373973 should emit "bitwise negation of a boolean expression always
> > evaluates to 'true'; did you mean logical negation?" where possible.
> > In the suspicious case like int i = ~b there is a general message
> > "bitwise negation of a boolean expression; did you mean logical
> > negation?".
> >
> > I like it now. What do you think? fine for you?
> 
> I see. Yes, all the cases I tried produce appropriate diagnostics. I like it!
> 
>> Hm, there is no "bitwise negation of a boolean expression always
>> evaluates to 'true'; did you mean logical negation?" for chromium
>> case [ https://bugs.chromium.org/p/chromium/issues/detail?id=1011810 ]. I will try to fix it.
> 
> The important part there seems to be that the result of `~b` (which must be either -1 or -2) is used as the operand to `!=` or `==`.
> My opinion is that it is not worth the extra complication just to improve the error message for this case.
> It would be interesting to do some kind of general-purpose dataflow before emitting diagnostics...
> I notice that Clang's optimizer is smart enough to optimize
>     bool foo(bool a, bool b) {
>         return a == ~b;
>     }
>     bool bar(int x) {
>         return x + 1 < -INT_MAX;
>     }
> into `return 0`. If it could propagate that information up and produce a diagnostic, users might appreciate that. But the challenge as always is that we can never tell if the user might sometimes be doing that sort of thing on purpose (in inlined code, in macros, in generated code, etc).
> 
> my $.02,
> –Arthur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191008/89031ece/attachment-0001.html>


More information about the cfe-commits mailing list