[PATCH] D24905: Fix unreachable code false positive, vardecl in switch

Daniel Marjamäki via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 28 03:48:54 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL282574: [StaticAnalyzer] Fix false positives for vardecls that are technically… (authored by danielmarjamaki).

Changed prior to commit:
  https://reviews.llvm.org/D24905?vs=72775&id=72793#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24905

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
  cfe/trunk/test/Analysis/unreachable-code-path.c

Index: cfe/trunk/test/Analysis/unreachable-code-path.c
===================================================================
--- cfe/trunk/test/Analysis/unreachable-code-path.c
+++ cfe/trunk/test/Analysis/unreachable-code-path.c
@@ -158,3 +158,18 @@
     }
   }
 }
+
+// Don't warn about unreachable VarDecl.
+void dostuff(int*A);
+void varDecl(int X) {
+  switch (X) {
+    int A; // No warning here.
+  case 1:
+    dostuff(&A);
+    break;
+  case 2:
+    dostuff(&A);
+    break;
+  }
+}
+
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
@@ -191,8 +191,10 @@
 // Find the Stmt* in a CFGBlock for reporting a warning
 const Stmt *UnreachableCodeChecker::getUnreachableStmt(const CFGBlock *CB) {
   for (CFGBlock::const_iterator I = CB->begin(), E = CB->end(); I != E; ++I) {
-    if (Optional<CFGStmt> S = I->getAs<CFGStmt>())
-      return S->getStmt();
+    if (Optional<CFGStmt> S = I->getAs<CFGStmt>()) {
+      if (!isa<DeclStmt>(S->getStmt()))
+        return S->getStmt();
+    }
   }
   if (const Stmt *S = CB->getTerminator())
     return S;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24905.72793.patch
Type: text/x-patch
Size: 1282 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160928/a7f0b5e1/attachment.bin>


More information about the cfe-commits mailing list