diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-04-22 21:10:18 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-04-22 21:10:18 +0000 |
commit | eccf3e582114611d2b6c1915f709ddc6f6b7943e (patch) | |
tree | d7248cd192d9a8281effbf8912a71dfb840784f6 /clang/lib/Analysis/BasicValueFactory.cpp | |
parent | d5425e8f8db5d3ea7bdc949d6333ca5c2d91751d (diff) | |
download | bcm5719-llvm-eccf3e582114611d2b6c1915f709ddc6f6b7943e.tar.gz bcm5719-llvm-eccf3e582114611d2b6c1915f709ddc6f6b7943e.zip |
Added "nonlval::LValAsInteger" to represent abstract LVals casted to integers, allowing us to track lvals when they are casted back to pointers.
llvm-svn: 50108
Diffstat (limited to 'clang/lib/Analysis/BasicValueFactory.cpp')
-rw-r--r-- | clang/lib/Analysis/BasicValueFactory.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/clang/lib/Analysis/BasicValueFactory.cpp b/clang/lib/Analysis/BasicValueFactory.cpp index 88b360d1d0e..22fb2d1b6e7 100644 --- a/clang/lib/Analysis/BasicValueFactory.cpp +++ b/clang/lib/Analysis/BasicValueFactory.cpp @@ -14,15 +14,32 @@ //===----------------------------------------------------------------------===// #include "clang/Analysis/PathSensitive/BasicValueFactory.h" +#include "clang/Analysis/PathSensitive/RValues.h" using namespace clang; +typedef std::pair<RVal, unsigned> SizedRVal; + +namespace llvm { +template<> struct FoldingSetTrait<SizedRVal> { + static inline void Profile(const SizedRVal& X, llvm::FoldingSetNodeID& ID) { + X.first.Profile(ID); + ID.AddInteger(X.second); + } +}; +} + +typedef llvm::FoldingSet<llvm::FoldingSetNodeWrapper<SizedRVal> > + PersistentRValsTy; + BasicValueFactory::~BasicValueFactory() { // Note that the dstor for the contents of APSIntSet will never be called, // so we iterate over the set and invoke the dstor for each APSInt. This // frees an aux. memory allocated to represent very large constants. for (APSIntSetTy::iterator I=APSIntSet.begin(), E=APSIntSet.end(); I!=E; ++I) I->getValue().~APSInt(); + + delete (PersistentRValsTy*) PersistentRVals; } const llvm::APSInt& BasicValueFactory::getValue(const llvm::APSInt& X) { @@ -165,3 +182,29 @@ BasicValueFactory::EvaluateAPSInt(BinaryOperator::Opcode Op, return &getValue( V1 ^ V2 ); } } + + +const std::pair<RVal, unsigned>& +BasicValueFactory::getPersistentSizedRVal(const RVal& V, unsigned Bits) { + + // Lazily create the folding set. + if (!PersistentRVals) PersistentRVals = new PersistentRValsTy(); + + llvm::FoldingSetNodeID ID; + void* InsertPos; + V.Profile(ID); + ID.AddInteger(Bits); + + PersistentRValsTy& Map = *((PersistentRValsTy*) PersistentRVals); + + typedef llvm::FoldingSetNodeWrapper<SizedRVal> FoldNodeTy; + FoldNodeTy* P = Map.FindNodeOrInsertPos(ID, InsertPos); + + if (!P) { + P = (FoldNodeTy*) BPAlloc.Allocate<FoldNodeTy>(); + new (P) FoldNodeTy(std::make_pair(V, Bits)); + Map.InsertNode(P, InsertPos); + } + + return *P; +} |