[PATCH] Bitwise comparison always true

Jordan Rose jordan_rose at apple.com
Fri May 16 09:36:21 PDT 2014


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





More information about the cfe-commits mailing list