diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-02-23 02:39:16 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-02-23 02:39:16 +0000 |
commit | 3d2eed823d534ee370cfd7742c1e96ab3ee9a80b (patch) | |
tree | 92df6ef40692029ba1bb1076d24f68de3fceed48 /lib/Analysis/ReachableCode.cpp | |
parent | f067d8eecfd56a56b4192882bf86d0857c92dcc5 (diff) |
Start moving some of the logic for the unreachable code analysis out of libSema
and into libAnalysis.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96872 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ReachableCode.cpp')
-rw-r--r-- | lib/Analysis/ReachableCode.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/Analysis/ReachableCode.cpp b/lib/Analysis/ReachableCode.cpp new file mode 100644 index 0000000000..269aaf02c1 --- /dev/null +++ b/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; +} |