Somehow both Daniel and I missed the fact that while loops are only identical
if they have identical bodies.
Patch by Daniel Fahlgren!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201829
91177308-0d34-0410-b5e6-
96231b3b80d8
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);
}
}
+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}}