Hi,

This fixes a false positive in the identical expression checker. While
statements only checked the condition and not the body.

I don't know how I could miss that when I implemented it, sorry.

Best regards,
Daniel Fahlgren
Index: lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp	(revision 201802)
+++ lib/StaticAnalyzer/Checkers/IdenticalExprChecker.cpp	(working copy)
@@ -361,8 +361,13 @@
     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);
Index: test/Analysis/identical-expressions.cpp
===================================================================
--- test/Analysis/identical-expressions.cpp	(revision 201802)
+++ test/Analysis/identical-expressions.cpp	(working copy)
@@ -1287,6 +1287,17 @@
   }
 }
 
+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}}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to