diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-09-16 18:44:52 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-09-16 18:44:52 +0000 |
commit | d452758bb6b59340528a26def9ecc24b329d4ecf (patch) | |
tree | 25346308283c18880c7584738c0907dec5968242 /lib | |
parent | 3f61c18dd765c27bf900b22dc3a5f2a68e2364a1 (diff) |
ProgramPoint now takes the space of two pointers instead of one. This change was
motivated because it became clear that the number of subclasses of ProgramPoint
would expand and we ran out of bits to represent a pointer variant. As a plus of
this change, BlockEdge program points can now be represented explicitly without
using a cache of CFGBlock* pairs in CFG.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56245 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/CFG.cpp | 58 | ||||
-rw-r--r-- | lib/Analysis/BugReporter.cpp | 7 | ||||
-rw-r--r-- | lib/Analysis/GRCoreEngine.cpp | 20 | ||||
-rw-r--r-- | lib/Analysis/GRExprEngine.cpp | 9 | ||||
-rw-r--r-- | lib/Analysis/ProgramPoint.cpp | 64 |
5 files changed, 14 insertions, 144 deletions
diff --git a/lib/AST/CFG.cpp b/lib/AST/CFG.cpp index 78c8dca423..b18f90497f 100644 --- a/lib/AST/CFG.cpp +++ b/lib/AST/CFG.cpp @@ -1213,69 +1213,11 @@ unsigned CFG::getNumBlkExprs() { } //===----------------------------------------------------------------------===// -// Internal Block-Edge Set; used for modeling persistent <CFGBlock*,CFGBlock*> -// pairs for use with ProgramPoint. -//===----------------------------------------------------------------------===// - -typedef std::pair<CFGBlock*,CFGBlock*> BPairTy; - -namespace llvm { - template<> struct FoldingSetTrait<BPairTy*> { - static void Profile(const BPairTy* X, FoldingSetNodeID& profile) { - profile.AddPointer(X->first); - profile.AddPointer(X->second); - } - }; -} - -typedef llvm::FoldingSetNodeWrapper<BPairTy*> PersistPairTy; -typedef llvm::FoldingSet<PersistPairTy> BlkEdgeSetTy; - -const std::pair<CFGBlock*,CFGBlock*>* -CFG::getBlockEdgeImpl(const CFGBlock* B1, const CFGBlock* B2) { - - if (!BlkEdgeSet) - BlkEdgeSet = new BlkEdgeSetTy(); - - BlkEdgeSetTy* p = static_cast<BlkEdgeSetTy*>(BlkEdgeSet); - - // Profile the edges. - llvm::FoldingSetNodeID profile; - void* InsertPos; - - profile.AddPointer(B1); - profile.AddPointer(B2); - - PersistPairTy* V = p->FindNodeOrInsertPos(profile, InsertPos); - - if (!V) { - assert (llvm::AlignOf<BPairTy>::Alignment_LessEqual_8Bytes); - - // Allocate the pair, forcing an 8-byte alignment. - BPairTy* pair = (BPairTy*) Alloc.Allocate(sizeof(*pair), 8); - - new (pair) BPairTy(const_cast<CFGBlock*>(B1), - const_cast<CFGBlock*>(B2)); - - // Allocate the meta data to store the pair in the FoldingSet. - PersistPairTy* ppair = (PersistPairTy*) Alloc.Allocate<PersistPairTy>(); - new (ppair) PersistPairTy(pair); - - p->InsertNode(ppair, InsertPos); - - return pair; - } - - return V->getValue(); -} - -//===----------------------------------------------------------------------===// // Cleanup: CFG dstor. //===----------------------------------------------------------------------===// CFG::~CFG() { delete reinterpret_cast<const BlkExprMapTy*>(BlkExprMap); - delete reinterpret_cast<BlkEdgeSetTy*>(BlkEdgeSet); } //===----------------------------------------------------------------------===// diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp index 7e3db7aba4..b163eea1b8 100644 --- a/lib/Analysis/BugReporter.cpp +++ b/lib/Analysis/BugReporter.cpp @@ -689,13 +689,10 @@ bool BugTypeCacheLocation::isCached(BugReport& R) { } bool BugTypeCacheLocation::isCached(ProgramPoint P) { - - void* p = P.getRawData(); - - if (CachedErrors.count(p)) + if (CachedErrors.count(P)) return true; - CachedErrors.insert(p); + CachedErrors.insert(P); return false; } diff --git a/lib/Analysis/GRCoreEngine.cpp b/lib/Analysis/GRCoreEngine.cpp index a7e1458e7a..84a8d5522d 100644 --- a/lib/Analysis/GRCoreEngine.cpp +++ b/lib/Analysis/GRCoreEngine.cpp @@ -69,7 +69,7 @@ bool GRCoreEngineImpl::ExecuteWorkList(unsigned Steps) { // Construct an edge representing the // starting location in the function. - BlockEdge StartLoc(getCFG(), Entry, Succ); + BlockEdge StartLoc(Entry, Succ); // Set the current block counter to being empty. WList->setBlockCounter(BCounterFactory.GetEmptyCounter()); @@ -230,7 +230,7 @@ void GRCoreEngineImpl::HandleBlockExit(CFGBlock * B, ExplodedNodeImpl* Pred) { assert (B->succ_size() == 1 && "Blocks with no terminator should have at most 1 successor."); - GenerateNode(BlockEdge(getCFG(),B,*(B->succ_begin())), Pred->State, Pred); + GenerateNode(BlockEdge(B, *(B->succ_begin())), Pred->State, Pred); } void GRCoreEngineImpl::HandleBranch(Expr* Cond, Stmt* Term, CFGBlock * B, @@ -350,8 +350,7 @@ ExplodedNodeImpl* GRBranchNodeBuilderImpl::generateNodeImpl(const void* State, bool IsNew; ExplodedNodeImpl* Succ = - Eng.G->getNodeImpl(BlockEdge(Eng.getCFG(), Src, branch ? DstT : DstF), - State, &IsNew); + Eng.G->getNodeImpl(BlockEdge(Src, branch ? DstT : DstF), State, &IsNew); Succ->addPredecessor(Pred); @@ -382,8 +381,7 @@ GRIndirectGotoNodeBuilderImpl::generateNodeImpl(const Iterator& I, bool IsNew; ExplodedNodeImpl* Succ = - Eng.G->getNodeImpl(BlockEdge(Eng.getCFG(), Src, I.getBlock(), true), - St, &IsNew); + Eng.G->getNodeImpl(BlockEdge(Src, I.getBlock()), St, &IsNew); Succ->addPredecessor(Pred); @@ -407,9 +405,8 @@ GRSwitchNodeBuilderImpl::generateCaseStmtNodeImpl(const Iterator& I, bool IsNew; - ExplodedNodeImpl* Succ = Eng.G->getNodeImpl(BlockEdge(Eng.getCFG(), Src, - I.getBlock()), - St, &IsNew); + ExplodedNodeImpl* Succ = Eng.G->getNodeImpl(BlockEdge(Src, I.getBlock()), + St, &IsNew); Succ->addPredecessor(Pred); if (IsNew) { @@ -431,9 +428,8 @@ GRSwitchNodeBuilderImpl::generateDefaultCaseNodeImpl(const void* St, bool IsNew; - ExplodedNodeImpl* Succ = Eng.G->getNodeImpl(BlockEdge(Eng.getCFG(), Src, - DefaultBlock), - St, &IsNew); + ExplodedNodeImpl* Succ = Eng.G->getNodeImpl(BlockEdge(Src, DefaultBlock), + St, &IsNew); Succ->addPredecessor(Pred); if (IsNew) { diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index d8c0320d66..aa5ab6af7f 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -2324,17 +2324,16 @@ template <typename ITERATOR> static void AddSources(std::vector<GRExprEngine::NodeTy*>& Sources, ITERATOR I, ITERATOR E) { - llvm::SmallPtrSet<void*,10> CachedSources; + llvm::SmallSet<ProgramPoint,10> CachedSources; for ( ; I != E; ++I ) { GRExprEngine::NodeTy* N = GetGraphNode(I); - void* p = N->getLocation().getRawData(); + ProgramPoint P = N->getLocation(); - if (CachedSources.count(p)) + if (CachedSources.count(P)) continue; - CachedSources.insert(p); - + CachedSources.insert(P); Sources.push_back(N); } } diff --git a/lib/Analysis/ProgramPoint.cpp b/lib/Analysis/ProgramPoint.cpp deleted file mode 100644 index d95680ff38..0000000000 --- a/lib/Analysis/ProgramPoint.cpp +++ /dev/null @@ -1,64 +0,0 @@ -//= ProgramPoint.cpp - Program Points for Path-Sensitive Analysis --*- 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 methods for subclasses of ProgramPoint. -// -//===----------------------------------------------------------------------===// - -#include "clang/AST/CFG.h" -#include "clang/Analysis/ProgramPoint.h" - -using namespace clang; - -BlockEdge::BlockEdge(CFG& cfg, const CFGBlock* B1, const CFGBlock* B2) { - if (B1->succ_size() == 1) { - assert (*(B1->succ_begin()) == B2); - setRawData(B1, BlockEdgeSrcKind); - } - else if (B2->pred_size() == 1) { - assert (*(B2->pred_begin()) == B1); - setRawData(B2, BlockEdgeDstKind); - } - else - setRawData(cfg.getBlockEdgeImpl(B1,B2), BlockEdgeAuxKind); -} - -CFGBlock* BlockEdge::getSrc() const { - switch (getKind()) { - default: - assert (false && "Invalid BlockEdgeKind."); - return NULL; - - case BlockEdgeSrcKind: - return reinterpret_cast<CFGBlock*>(getRawPtr()); - - case BlockEdgeDstKind: - return *(reinterpret_cast<CFGBlock*>(getRawPtr())->pred_begin()); - - case BlockEdgeAuxKind: - return reinterpret_cast<BPair*>(getRawPtr())->first; - } -} - -CFGBlock* BlockEdge::getDst() const { - switch (getKind()) { - default: - assert (false && "Invalid BlockEdgeKind."); - return NULL; - - case BlockEdgeSrcKind: - return *(reinterpret_cast<CFGBlock*>(getRawPtr())->succ_begin()); - - case BlockEdgeDstKind: - return reinterpret_cast<CFGBlock*>(getRawPtr()); - - case BlockEdgeAuxKind: - return reinterpret_cast<BPair*>(getRawPtr())->second; - } -} |