forked from OSchip/llvm-project
[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:
parent
e6d01e08c6
commit
2593b402ce
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue