Index: lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp +++ lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp @@ -36,6 +36,7 @@ ExprEngine &Eng) const; private: typedef llvm::SmallSet CFGBlocksSet; + typedef llvm::SmallSet StmtsSet; static inline const Stmt *getUnreachableStmt(const CFGBlock *CB); static void FindUnreachableEntryPoints(const CFGBlock *CB, @@ -54,6 +55,7 @@ if (Eng.hasWorkRemaining()) return; + StmtsSet ReachableStmts; const Decl *D = nullptr; CFG *C = nullptr; ParentMap *PM = nullptr; @@ -78,6 +80,7 @@ if (Optional BE = P.getAs()) { const CFGBlock *CB = BE->getBlock(); reachable.insert(CB->getBlockID()); + ReachableStmts.insert(getUnreachableStmt(CB)); } } @@ -147,6 +150,8 @@ PathDiagnosticLocation DL; SourceLocation SL; if (const Stmt *S = getUnreachableStmt(CB)) { + if (ReachableStmts.count(S)) + continue; SR = S->getSourceRange(); DL = PathDiagnosticLocation::createBegin(S, B.getSourceManager(), LC); SL = DL.asLocation(); Index: test/Analysis/unreachable-code-path.c =================================================================== --- test/Analysis/unreachable-code-path.c +++ test/Analysis/unreachable-code-path.c @@ -158,3 +158,14 @@ } } } + +// Block numbers in the ExplodedGraph and CFG mismatch. +void test12(int x) { + switch (x) { + case 1: + break; + case 2: + do { } while (0); + break; + } +}