[PATCH] D24905: Fix unreachable code false positive, vardecl in switch
Daniel Marjamäki via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 28 01:24:13 PDT 2016
danielmarjamaki removed rL LLVM as the repository for this revision.
danielmarjamaki updated this revision to Diff 72775.
danielmarjamaki added a comment.
Use !isa<DeclStmt>. Suggestion by Gabor.
https://reviews.llvm.org/D24905
Files:
lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
test/Analysis/unreachable-code-path.c
Index: test/Analysis/unreachable-code-path.c
===================================================================
--- test/Analysis/unreachable-code-path.c
+++ 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: 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<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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24905.72775.patch
Type: text/x-patch
Size: 1222 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160928/c4506107/attachment.bin>
More information about the cfe-commits
mailing list