summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
diff options
context:
space:
mode:
authorDaniel Marjamaki <daniel.marjamaki@evidente.se>2015-08-10 07:18:29 +0000
committerDaniel Marjamaki <daniel.marjamaki@evidente.se>2015-08-10 07:18:29 +0000
commit30e2a44a06a4bd61f9c607e0d7e2447e0dc488db (patch)
tree79dee54f4fec6a87e80b9b5ac8f2a92aaff4a4ce /clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
parent001e2e42286ac0ed98577ad3f4e99fbd15760f6b (diff)
downloadbcm5719-llvm-30e2a44a06a4bd61f9c607e0d7e2447e0dc488db.tar.gz
bcm5719-llvm-30e2a44a06a4bd61f9c607e0d7e2447e0dc488db.zip
[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
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
index 58d0783f397..23fa2d11a7e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
@@ -108,6 +108,24 @@ bool FindIdenticalExprVisitor::VisitIfStmt(const IfStmt *I) {
const Stmt *Stmt1 = I->getThen();
const Stmt *Stmt2 = I->getElse();
+ // Check for identical inner condition:
+ //
+ // if (x<10) {
+ // if (x<10) {
+ // ..
+ if (const CompoundStmt *CS = dyn_cast<CompoundStmt>(Stmt1)) {
+ if (!CS->body_empty()) {
+ const IfStmt *InnerIf = dyn_cast<IfStmt>(*CS->body_begin());
+ if (InnerIf && isIdenticalStmt(AC->getASTContext(), I->getCond(), InnerIf->getCond(), /*ignoreSideEffects=*/ false)) {
+ PathDiagnosticLocation ELoc(InnerIf->getCond(), BR.getSourceManager(), AC);
+ BR.EmitBasicReport(AC->getDecl(), Checker, "Identical conditions",
+ categories::LogicError,
+ "conditions of the inner and outer statements are identical",
+ ELoc);
+ }
+ }
+ }
+
// Check for identical conditions:
//
// if (b) {
OpenPOWER on IntegriCloud