[PATCH] Detect identical conditions in if-else-if statements

Daniel Fahlgren daniel at fahlgren.se
Wed Mar 5 09:36:52 PST 2014


Hi,

ping, any comments?

Best regards,
Daniel Fahlgren

On Fri, 2014-02-21 at 08:16 +0100, Daniel Fahlgren wrote:
> Hi,
> 
> This patch makes the IdenticalExprChecker warn about code like:
> 
> if (i == 1) {
>   foo1();
> } else if (i == 1) {
>   foo2();
> }
> 
> The logic is the same as for binary operators. We only need to check the
> current if statement and the following ones. Just as with the binary
> operator check that will be O(n^2), but if you have a very large number
> of chained if-else-if statements that might be a reason for a warning of
> its own ;)
> 
> I ran scan-build on PHP and openssl and didn't notice any major increase
> in build time. For PHP it took 1% longer, and openssl was 0.3% faster
> with this checker enabled. That includes all other checks done by
> alpha.core.IdenticalExpr.
> 
> Cheers,
> Daniel Fahlgren
> _______________________________________________
> 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