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

Daniel Fahlgren daniel at fahlgren.se
Thu Feb 20 23:16:16 PST 2014


This patch makes the IdenticalExprChecker warn about code like:

if (i == 1) {
} else if (i == 1) {

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

Daniel Fahlgren
-------------- next part --------------
A non-text attachment was scrubbed...
Name: chained_if_stmts.patch
Type: text/x-patch
Size: 2892 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140221/ea1cf63c/attachment.bin>

More information about the cfe-commits mailing list