Index: lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp +++ 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 S = I->getAs()) - return S->getStmt(); + if (Optional S = I->getAs()) { + if (isa(S->getStmt())) + return S->getStmt(); + } } if (const Stmt *S = CB->getTerminator()) return S; Index: test/Analysis/unreachable-code-path.c =================================================================== --- test/Analysis/unreachable-code-path.c +++ test/Analysis/unreachable-code-path.c @@ -158,3 +158,17 @@ } } } + +// 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; + } +}