diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp | 9 | ||||
-rw-r--r-- | clang/test/Analysis/identical-expressions.cpp | 11 |
2 files changed, 18 insertions, 2 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp index a76dff120be..6abfc14877e 100644 --- a/clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp @@ -361,8 +361,13 @@ static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1, const WhileStmt *WStmt1 = cast<WhileStmt>(Stmt1); const WhileStmt *WStmt2 = cast<WhileStmt>(Stmt2); - return isIdenticalStmt(Ctx, WStmt1->getCond(), WStmt2->getCond(), - IgnoreSideEffects); + if (!isIdenticalStmt(Ctx, WStmt1->getCond(), WStmt2->getCond(), + IgnoreSideEffects)) + return false; + if (!isIdenticalStmt(Ctx, WStmt1->getBody(), WStmt2->getBody(), + IgnoreSideEffects)) + return false; + return true; } case Stmt::IfStmtClass: { const IfStmt *IStmt1 = cast<IfStmt>(Stmt1); diff --git a/clang/test/Analysis/identical-expressions.cpp b/clang/test/Analysis/identical-expressions.cpp index 950cdd93ff4..e1f51af7c6f 100644 --- a/clang/test/Analysis/identical-expressions.cpp +++ b/clang/test/Analysis/identical-expressions.cpp @@ -1287,6 +1287,17 @@ void test_identical_branches_while(bool b) { } } +void test_identical_branches_while_2(bool b) { + int i = 10; + if (b) { // no-warning + while (func()) + i--; + } else { + while (func()) + i++; + } +} + void test_identical_branches_do_while(bool b) { int i = 10; if (b) { // expected-warning {{true and false branches are identical}} |