Commit Graph

10 Commits

Author SHA1 Message Date
Daniel Marjamaki 30e2a44a06 [Static Analyzer] Warn when inner and outer conditions are identical. The inner condition is always true.
Reviewed in http://reviews.llvm.org/D10892.

llvm-svn: 244435
2015-08-10 07:18:29 +00:00
Jordan Rose 50de57df6d [test] Turn off warnings for test/Analysis/identical-expressions.cpp.
Also, make it slightly clearer what's being tested by only differentiating integer
literals based on their suffix, rather than using a very large constant.

llvm-svn: 216133
2014-08-20 22:40:57 +00:00
Jordan Rose f3544e913d [analyzer] IdenticalExpr: don't try to compare integer literals with different widths.
PR20659. Patch by Anders Rönnholm.

llvm-svn: 216076
2014-08-20 16:51:26 +00:00
Jordan Rose b6100301e8 [analyzer] IdenticalExpr: use getBytes rather than getString to compare string literals.
PR20693. Patch by Anders Rönnholm.

llvm-svn: 216075
2014-08-20 16:51:18 +00:00
Jordan Rose a6839aaa9b [analyzer] Check all conditions in a chained if against each other.
Like the binary operator check of r201702, this actually checks the
condition of every if in a chain against every other condition, an
O(N^2) operation. In most cases N should be small enough to make this
practical, and checking all cases like this makes it much more likely
to catch a copy-paste error within the same series of branches.

Part of IdenticalExprChecker; patch by Daniel Fahlgren!

llvm-svn: 203585
2014-03-11 16:52:29 +00:00
Jordan Rose 45d71a2715 [analyzer] Fix a bug in IdenticalExprChecker concerning while loops.
Somehow both Daniel and I missed the fact that while loops are only identical
if they have identical bodies.

Patch by Daniel Fahlgren!

llvm-svn: 201829
2014-02-21 00:18:31 +00:00
Jordan Rose 94008121fa [analyzer] Extend IdenticalExprChecker to check logical and bitwise expressions.
IdenticalExprChecker now warns if any expressions in a logical or bitwise
chain (&&, ||, &, |, or ^) are the same. Unlike the previous patch, this
actually checks all subexpressions against each other (an O(N^2) operation,
but N is likely to be small).

Patch by Daniel Fahlgren!

llvm-svn: 201702
2014-02-19 17:44:16 +00:00
Jordan Rose 70e7e8718e [analyzer] Extend IdenticalExprChecker to check the two branches of an if.
This extends the checks for identical expressions to handle identical
statements, and compares the consequent and alternative ("then" and "else")
branches of an if-statement to see if they are identical, treating a single
statement surrounded by braces as equivalent to one without braces.

This does /not/ check subsequent branches in an if/else chain, let alone
branches that are not consecutive. This may improve in a future patch, but
it would certainly take more work.

Patch by Daniel Fahlgren!

llvm-svn: 201701
2014-02-19 17:44:11 +00:00
Jordan Rose 60bd88d341 [analyzer] Extend IdenticalExprChecker to check ternary operator results.
Warn if both result expressions of a ternary operator (? :) are the same.
Because only one of them will be executed, this warning will fire even if
the expressions have side effects.

Patch by Anders Rönnholm and Per Viberg!

llvm-svn: 196937
2013-12-10 18:18:06 +00:00
Jordan Rose 51327f9237 [analyzer] Add IdenticalExprChecker, to find copy-pasted code.
This syntactic checker looks for expressions on both sides of comparison
operators that are structurally the same. As a special case, the
floating-point idiom "x != x" for "isnan(x)" is left alone.

Currently this only checks comparison operators, but in the future we could
extend this to include logical operators or chained if-conditionals.

Checker by Per Viberg!

llvm-svn: 194236
2013-11-08 01:15:39 +00:00