This revision was automatically updated to reflect the committed changes. Closed by commit rL282574: [StaticAnalyzer] Fix false positives for vardecls that are technically… (authored by danielmarjamaki).
Changed prior to commit: https://reviews.llvm.org/D24905?vs=72775&id=72793#toc Repository: rL LLVM https://reviews.llvm.org/D24905 Files: cfe/trunk/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp cfe/trunk/test/Analysis/unreachable-code-path.c Index: cfe/trunk/test/Analysis/unreachable-code-path.c =================================================================== --- cfe/trunk/test/Analysis/unreachable-code-path.c +++ cfe/trunk/test/Analysis/unreachable-code-path.c @@ -158,3 +158,18 @@ } } } + +// 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; + } +} + Index: cfe/trunk/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp =================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp +++ cfe/trunk/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<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;
Index: cfe/trunk/test/Analysis/unreachable-code-path.c =================================================================== --- cfe/trunk/test/Analysis/unreachable-code-path.c +++ cfe/trunk/test/Analysis/unreachable-code-path.c @@ -158,3 +158,18 @@ } } } + +// 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; + } +} + Index: cfe/trunk/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp =================================================================== --- cfe/trunk/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp +++ cfe/trunk/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<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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits