[PATCH] check for Incorrect logic in operator

Anders Rönnholm Anders.Ronnholm at evidente.se
Mon Oct 28 01:55:08 PDT 2013


Thanks for your comments.
I was told that it was preferable to update the CFG. The reason is that all analyses built on top on the CFG will benefit: -Wuninitialized, static analyzer, warnings, etc. I wonder if Anna or Ted could provide their opinions about this patch?
//Anders

From: Richard Trieu [mailto:rtrieu at google.com]
Sent: den 26 oktober 2013 01:43
To: Jordan Rose
Cc: Anders Rönnholm; cfe-commits at cs.uiuc.edu
Subject: Re: [PATCH] check for Incorrect logic in operator

A few high level comments.

"-fblocks -Wunreachable-code" is there any reason your test cases have these flags?
"if (!x == 10) {}" there is an existing warning for this called -Wlogical-not-parentheses.  The check should be folded into there.
"if ((x < y) == 10) {}" ditto this and -Wtautological-compare-out-of-range
"logical disjunction always evaluates to true"  I wouldn't expect all programmers to understand what a logical disjunction is.

If you check out -Wlogical-not-parentheses and -Wtautological-compare-out-of-range, they are in lib/Sema/SemaChecking.cpp.  Why did you use a CFG approach instead?

On Fri, Oct 25, 2013 at 10:18 AM, Jordan Rose <jordan_rose at apple.com<mailto:jordan_rose at apple.com>> wrote:
Richard Trieu has worked on a number of similar warnings. Maybe he can take a look?

Jordan


On Oct 25, 2013, at 8:18, Anders Rönnholm <Anders.Ronnholm at evidente.se<mailto:Anders.Ronnholm at evidente.se>> wrote:

> Hi,
> Resending the patch I sent last week. Anyone want to have a look at it?
>
> //Anders
>
> -----Original Message-----
> From: Anders Rönnholm
> Sent: den 18 oktober 2013 16:05
> To: cfe-commits at cs.uiuc.edu<mailto:cfe-commits at cs.uiuc.edu>
> Subject: [PATCH] check for Incorrect logic in operator
>
> Hi,
>
> I have a new patch I like to get reviewed. It checks for incorrect logics in relational,equal and logic operators in cfgbuilder when trying to evaluate bool. A warning is emitted in Sema when an error occurs.
>
> eg.
> if (x != 2 || x != 3) { } always true
> if ((x < y) <= 10) {}  always true
>
> Thanks,
> Anders
> <incorrectoperatorlogic.diff>_______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu<mailto:cfe-commits at cs.uiuc.edu>
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131028/44560039/attachment.html>


More information about the cfe-commits mailing list