aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/BasicValueFactory.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-04-22 21:10:18 +0000
committerTed Kremenek <kremenek@apple.com>2008-04-22 21:10:18 +0000
commit0fe33bc94a822e315585e5cde1964d3c3b9052f9 (patch)
tree37a7aaad6e07752e567ddef1b23ca47b3ec7bbcb /lib/Analysis/BasicValueFactory.cpp
parent9fdf9c6d3530bb85f3166e6460d841e2ff8e1a2c (diff)
Added "nonlval::LValAsInteger" to represent abstract LVals casted to integers, allowing us to track lvals when they are casted back to pointers.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50108 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/BasicValueFactory.cpp')
-rw-r--r--lib/Analysis/BasicValueFactory.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/Analysis/BasicValueFactory.cpp b/lib/Analysis/BasicValueFactory.cpp
index 88b360d1d0..22fb2d1b6e 100644
--- a/lib/Analysis/BasicValueFactory.cpp
+++ b/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;
+}