diff options
author | Tom Care <tom.care@uqconnect.edu.au> | 2010-10-06 23:02:25 +0000 |
---|---|---|
committer | Tom Care <tom.care@uqconnect.edu.au> | 2010-10-06 23:02:25 +0000 |
commit | ea53e82c784281f7a2e342c04854b3e544457cd2 (patch) | |
tree | 5e845b5ea1c6f136484a31c4955baf23c202372f /clang/lib/Checker/UnreachableCodeChecker.cpp | |
parent | 25cd3bfbd718533676733f7029b6c372bb791e80 (diff) | |
download | bcm5719-llvm-ea53e82c784281f7a2e342c04854b3e544457cd2.tar.gz bcm5719-llvm-ea53e82c784281f7a2e342c04854b3e544457cd2.zip |
UnreachableCodeChecker cleanup and improvements
- Fixed some iterator style issues
- Don't process blocks that have been visited already
- Fixed a case where a unreachable block cycle was not reported
- Minor test case changes
- Added one test case from flow-sensitive version of the check. More coming.
llvm-svn: 115861
Diffstat (limited to 'clang/lib/Checker/UnreachableCodeChecker.cpp')
-rw-r--r-- | clang/lib/Checker/UnreachableCodeChecker.cpp | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/clang/lib/Checker/UnreachableCodeChecker.cpp b/clang/lib/Checker/UnreachableCodeChecker.cpp index 52fb0caba08..68542197147 100644 --- a/clang/lib/Checker/UnreachableCodeChecker.cpp +++ b/clang/lib/Checker/UnreachableCodeChecker.cpp @@ -91,7 +91,7 @@ void UnreachableCodeChecker::VisitEndAnalysis(ExplodedGraph &G, ASTContext &Ctx = B.getContext(); // Find CFGBlocks that were not covered by any node - for (CFG::const_iterator I = C->begin(); I != C->end(); ++I) { + for (CFG::const_iterator I = C->begin(), E = C->end(); I != E; ++I) { const CFGBlock *CB = *I; // Check if the block is unreachable if (reachable.count(CB->getBlockID())) @@ -102,7 +102,8 @@ void UnreachableCodeChecker::VisitEndAnalysis(ExplodedGraph &G, continue; // Find the entry points for this block - FindUnreachableEntryPoints(CB); + if (!visited.count(CB->getBlockID())) + FindUnreachableEntryPoints(CB); // This block may have been pruned; check if we still want to report it if (reachable.count(CB->getBlockID())) @@ -149,28 +150,19 @@ void UnreachableCodeChecker::VisitEndAnalysis(ExplodedGraph &G, // Recursively finds the entry point(s) for this dead CFGBlock. void UnreachableCodeChecker::FindUnreachableEntryPoints(const CFGBlock *CB) { - bool allPredecessorsReachable = true; - visited.insert(CB->getBlockID()); - for (CFGBlock::const_pred_iterator I = CB->pred_begin(); I != CB->pred_end(); - ++I) { - // Recurse over all unreachable blocks + for (CFGBlock::const_pred_iterator I = CB->pred_begin(), E = CB->pred_end(); + I != E; ++I) { if (!reachable.count((*I)->getBlockID())) { - // At least one predeccessor was unreachable - allPredecessorsReachable = false; - - // Only visit the block once + // If we find an unreachable predecessor, mark this block as reachable so + // we don't report this block + reachable.insert(CB->getBlockID()); if (!visited.count((*I)->getBlockID())) + // If we haven't previously visited the unreachable predecessor, recurse FindUnreachableEntryPoints(*I); } } - - // If at least one predecessor is unreachable, mark this block as reachable - // so we don't report this block. - if (!allPredecessorsReachable) { - reachable.insert(CB->getBlockID()); - } } // Find the Stmt* in a CFGBlock for reporting a warning |