diff options
| author | Daniel Marjamaki <daniel.marjamaki@evidente.se> | 2016-09-28 10:39:53 +0000 |
|---|---|---|
| committer | Daniel Marjamaki <daniel.marjamaki@evidente.se> | 2016-09-28 10:39:53 +0000 |
| commit | 2593b402ced66c14e59f59fcbb2ce92a4e55a04d (patch) | |
| tree | c9e7e6be9c957ed95fc3ecdf78f174ab1b0f05eb /clang | |
| parent | e6d01e08c6c1c156a42eecc84d268e93bbd53490 (diff) | |
| download | bcm5719-llvm-2593b402ced66c14e59f59fcbb2ce92a4e55a04d.tar.gz bcm5719-llvm-2593b402ced66c14e59f59fcbb2ce92a4e55a04d.zip | |
[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
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp | 6 | ||||
| -rw-r--r-- | clang/test/Analysis/unreachable-code-path.c | 15 |
2 files changed, 19 insertions, 2 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp index 892e713d241..ff07a64d9b1 100644 --- a/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp @@ -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; diff --git a/clang/test/Analysis/unreachable-code-path.c b/clang/test/Analysis/unreachable-code-path.c index 08019d9cbe3..f547f553246 100644 --- a/clang/test/Analysis/unreachable-code-path.c +++ b/clang/test/Analysis/unreachable-code-path.c @@ -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; + } +} + |

