[StaticAnalyzer] Fix false positives for vardecls that are technically unreachable but they are needed.

Example:

    switch (x) {
      int a;  // <- This is unreachable but needed
    case 1:
      a = ...

Differential Revision: https://reviews.llvm.org/D24905

llvm-svn: 282574
This commit is contained in:
Daniel Marjamaki 2016-09-28 10:39:53 +00:00
parent e6d01e08c6
commit 2593b402ce
2 changed files with 19 additions and 2 deletions

View File

@ -191,8 +191,10 @@ void UnreachableCodeChecker::FindUnreachableEntryPoints(const CFGBlock *CB,
// 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;

View File

@ -158,3 +158,18 @@ void testInlined() {
}
}
}
// 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;
}
}