[PATCH] Bitwise comparison always true

Anders Rönnholm Anders.Ronnholm at evidente.se
Mon May 19 05:24:17 PDT 2014


Hi,

Added testcases and changed to getValue(). Yes support for negative values will be added when i do the same for my previous CFG patch.

//Anders
________________________________________
Från: Jordan Rose [jordan_rose at apple.com]
Skickat: den 16 maj 2014 18:36
Till: Anders Rönnholm
Cc: cfe-commits at cs.uiuc.edu; Daniel Marjamäki
Ämne: Re: [PATCH] Bitwise comparison always true

Nifty. Some comments:

+      llvm::APSInt L1, L2;
+      IntLiteral->EvaluateAsInt(L1, *Context);
+      IntLiteral2->EvaluateAsInt(L2, *Context);

IntegerLiteral extends APIntStorage, so you can skip the complicated EvaluateAsInt path and just go with IntLiteral->getValue(). Note that this returns an APInt because a minus sign is not part of the literal. You can add that in a separate patch, though.

Please add some tests that show "8 & x" instead of "x & 8". I see that it's already handled, but it should be in the tests as well. Please also add tests where the number being used for the bitwise op is not a power of 2, and where neither of them are.

Jordan


On May 16, 2014, at 4:42 , Anders Rönnholm <Anders.Ronnholm at evidente.se> wrote:

> Hi,
>
> I have made a small patch which improves the CFG equality operator evaluation to detect logical errors in bitwise comparisons.
>
> It finds logical errors in and/or operations that always evaluates to true/false such as.
> (x & 8) == 4
>
> //Anders
> <bitwisecomparison.diff>_______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

-------------- next part --------------
A non-text attachment was scrubbed...
Name: bitwisecomparison.diff
Type: text/x-patch
Size: 5693 bytes
Desc: bitwisecomparison.diff
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140519/5ef6e554/attachment.bin>


More information about the cfe-commits mailing list