summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/ReachableCode.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-02-23 02:39:16 +0000
committerTed Kremenek <kremenek@apple.com>2010-02-23 02:39:16 +0000
commit7296de9ae3420ebfa25c6644bbb6831403acbd5b (patch)
treed6ccf671fcf44e317ffa02f86b4603f5b1aad6d9 /clang/lib/Analysis/ReachableCode.cpp
parent7e5c4906dd1e2d28eaa01325ac66f9badf559cae (diff)
downloadbcm5719-llvm-7296de9ae3420ebfa25c6644bbb6831403acbd5b.tar.gz
bcm5719-llvm-7296de9ae3420ebfa25c6644bbb6831403acbd5b.zip
Start moving some of the logic for the unreachable code analysis out of libSema
and into libAnalysis. llvm-svn: 96872
Diffstat (limited to 'clang/lib/Analysis/ReachableCode.cpp')
-rw-r--r--clang/lib/Analysis/ReachableCode.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp
new file mode 100644
index 00000000000..269aaf02c18
--- /dev/null
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -0,0 +1,52 @@
+//=- ReachableCodePathInsensitive.cpp ---------------------------*- C++ --*-==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements a flow-sensitive, path-insensitive analysis of
+// determining reachable blocks within a CFG.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/SmallVector.h"
+#include "clang/Analysis/Analyses/ReachableCode.h"
+#include "clang/Analysis/CFG.h"
+
+using namespace clang;
+
+/// ScanReachableFromBlock - Mark all blocks reachable from Start.
+/// Returns the total number of blocks that were marked reachable.
+unsigned clang::ScanReachableFromBlock(const CFGBlock &Start,
+ llvm::BitVector &Reachable) {
+ unsigned count = 0;
+ llvm::SmallVector<const CFGBlock*, 12> WL;
+
+ // Prep work queue
+ Reachable.set(Start.getBlockID());
+ ++count;
+ WL.push_back(&Start);
+
+ // Find the reachable blocks from 'Start'.
+ while (!WL.empty()) {
+ const CFGBlock *item = WL.back();
+ WL.pop_back();
+
+ // Look at the successors and mark then reachable.
+ for (CFGBlock::const_succ_iterator I=item->succ_begin(), E=item->succ_end();
+ I != E; ++I)
+ if (const CFGBlock *B = *I) {
+ unsigned blockID = B->getBlockID();
+ if (!Reachable[blockID]) {
+ Reachable.set(blockID);
+ ++count;
+ WL.push_back(B);
+ }
+ }
+ }
+ return count;
+}
OpenPOWER on IntegriCloud