r201829 - [analyzer] Fix a bug in IdenticalExprChecker concerning while loops.
Jordan Rose
jordan_rose at apple.com
Thu Feb 20 16:18:31 PST 2014
Author: jrose
Date: Thu Feb 20 18:18:31 2014
New Revision: 201829
URL: http://llvm.org/viewvc/llvm-project?rev=201829&view=rev
Log:
[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!
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
cfe/trunk/test/Analysis/identical-expressions.cpp
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp?rev=201829&r1=201828&r2=201829&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp Thu Feb 20 18:18:31 2014
@@ -361,8 +361,13 @@ static bool isIdenticalStmt(const ASTCon
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);
Modified: cfe/trunk/test/Analysis/identical-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/identical-expressions.cpp?rev=201829&r1=201828&r2=201829&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/identical-expressions.cpp (original)
+++ cfe/trunk/test/Analysis/identical-expressions.cpp Thu Feb 20 18:18:31 2014
@@ -1287,6 +1287,17 @@ void test_identical_branches_while(bool
}
}
+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}}
More information about the cfe-commits
mailing list