]> granicus.if.org Git - clang/commitdiff
CompoundVal now uses an ImmutableList<SVal> to store its set of SVals. This change...
authorTed Kremenek <kremenek@apple.com>
Thu, 30 Oct 2008 17:44:46 +0000 (17:44 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 30 Oct 2008 17:44:46 +0000 (17:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58437 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/PathSensitive/BasicValueFactory.h
include/clang/Analysis/PathSensitive/SVals.h
lib/Analysis/BasicValueFactory.cpp
lib/Analysis/SVals.cpp

index 8d4ff9e541a5de315d2a1b85c6c58a822945e391..82ed8558be96658e1113e1eef92db8e2d54c9c2e 100644 (file)
 #define LLVM_CLANG_ANALYSIS_BASICVALUEFACTORY_H
 
 #include "clang/Analysis/PathSensitive/SymbolManager.h"
+#include "clang/Analysis/PathSensitive/SVals.h"
 #include "clang/AST/ASTContext.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/APSInt.h"
-
-namespace llvm {
-  class BumpPtrAllocator;
-}
+#include "llvm/ADT/ImmutableList.h"
 
 namespace clang {
   
-class SVal;
-
 class CompoundValData : public llvm::FoldingSetNode {
   QualType T;
-  unsigned NumVals;
-  SVal* Vals;
+  llvm::ImmutableList<SVal> L;
 
 public:
-  CompoundValData(QualType t, const SVal* vals, unsigned n,
-                  llvm::BumpPtrAllocator& A);
+  CompoundValData(QualType t, llvm::ImmutableList<SVal> l) 
+    : T(t), L(l) {}
 
-  static void Profile(llvm::FoldingSetNodeID& ID, QualType T, unsigned N, 
-                      const SVal* Vals);
+  static void Profile(llvm::FoldingSetNodeID& ID, QualType T,
+                      llvm::ImmutableList<SVal> L);
 
-  void Profile(llvm::FoldingSetNodeID& ID) {
-    Profile(ID, T, NumVals, Vals);
-  }
+  void Profile(llvm::FoldingSetNodeID& ID) { Profile(ID, T, L); }
 };
 
 class BasicValueFactory {
@@ -62,11 +55,13 @@ class BasicValueFactory {
   void*         PersistentSVals;
   void*         PersistentSValPairs;
 
-  llvm::FoldingSet<CompoundValData> CompoundValDataSet;
+  llvm::ImmutableList<SVal>::Factory SValListFactory;
+  llvm::FoldingSet<CompoundValData>  CompoundValDataSet;
 
 public:
   BasicValueFactory(ASTContext& ctx, llvm::BumpPtrAllocator& Alloc) 
-  : Ctx(ctx), BPAlloc(Alloc), PersistentSVals(0), PersistentSValPairs(0) {}
+  : Ctx(ctx), BPAlloc(Alloc), PersistentSVals(0), PersistentSValPairs(0),
+    SValListFactory(Alloc) {}
 
   ~BasicValueFactory();
 
@@ -87,8 +82,16 @@ public:
   const SymIntConstraint& getConstraint(SymbolID sym, BinaryOperator::Opcode Op,
                                         const llvm::APSInt& V);
 
-  const CompoundValData* getCompoundValData(QualType T, const SVal* Vals,
-                                            unsigned NumVals);
+  const CompoundValData* getCompoundValData(QualType T, 
+                                            llvm::ImmutableList<SVal> Vals);
+  
+  llvm::ImmutableList<SVal> getEmptySValList() {
+    return SValListFactory.GetEmptyList();
+  }
+  
+  llvm::ImmutableList<SVal> consVals(SVal X, llvm::ImmutableList<SVal> L) {
+    return SValListFactory.Add(X, L);
+  }
 
   const llvm::APSInt* EvaluateAPSInt(BinaryOperator::Opcode Op,
                                      const llvm::APSInt& V1,
index 43f8a9107936bc276fcc36cbc4d061aedac8807d..8cc993e1a30a69ab8b9bd05f4c9c0d3a32ba9c3f 100644 (file)
 #ifndef LLVM_CLANG_ANALYSIS_RVALUE_H
 #define LLVM_CLANG_ANALYSIS_RVALUE_H
 
-#include "clang/Analysis/PathSensitive/BasicValueFactory.h"
+#include "clang/Analysis/PathSensitive/SymbolManager.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/ADT/ImmutableList.h"
   
 //==------------------------------------------------------------------------==//
 //  Base SVal types.
 //==------------------------------------------------------------------------==//
 
 namespace clang {
-  
+
+class CompoundValData;
+class BasicValueFactory;
 class MemRegion;
 class GRStateManager;
   
@@ -170,7 +173,7 @@ public:
     
   static NonLoc MakeIntTruthVal(BasicValueFactory& BasicVals, bool b);
 
-  static NonLoc MakeCompoundVal(QualType T, SVal* Vals, unsigned NumSVals,
+  static NonLoc MakeCompoundVal(QualType T, llvm::ImmutableList<SVal> Vals,
                                 BasicValueFactory& BasicVals);
 
   // Implement isa<T> support.
@@ -312,10 +315,7 @@ public:
     return V->getSubKind() == LocAsIntegerKind;
   }
   
-  static inline LocAsInteger Make(BasicValueFactory& Vals, Loc V,
-                                   unsigned Bits) {    
-    return LocAsInteger(Vals.getPersistentSValWithData(V, Bits));
-  }
+  static LocAsInteger Make(BasicValueFactory& Vals, Loc V, unsigned Bits);
 };
 
 class CompoundVal : public NonLoc {
index 18fdbdfaaa57cb48ad229b5f8062c5943e278d98..5b7041bc43cdd5046a1c38268086c0e2b80cbde5 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #include "clang/Analysis/PathSensitive/BasicValueFactory.h"
-#include "clang/Analysis/PathSensitive/SVals.h"
 
 using namespace clang;
 
-CompoundValData::CompoundValData(QualType t, const SVal* vals, unsigned n,
-                                 llvm::BumpPtrAllocator& A)
-  : T(t), NumVals(n) {
-
-  Vals = (SVal*) A.Allocate<SVal>(n);
-
-  new (Vals) SVal[n];
-
-  for (unsigned i = 0; i < n; ++i)
-    Vals[i] = vals[i];
-}
-
 void CompoundValData::Profile(llvm::FoldingSetNodeID& ID, QualType T, 
-                              unsigned N, const SVal* Vals) {
+                              llvm::ImmutableList<SVal> L) {
   T.Profile(ID);
-  ID.AddInteger(N);
-  for (unsigned i = 0; i < N; ++i)
-    Vals[i].Profile(ID);
+  ID.AddPointer(L.getInternalPointer());
 }
 
 typedef std::pair<SVal, uintptr_t> SValData;
 typedef std::pair<SVal, SVal> SValPair;
 
-
 namespace llvm {
 template<> struct FoldingSetTrait<SValData> {
   static inline void Profile(const SValData& X, llvm::FoldingSetNodeID& ID) {
@@ -127,17 +111,18 @@ BasicValueFactory::getConstraint(SymbolID sym, BinaryOperator::Opcode Op,
 }
 
 const CompoundValData* 
-BasicValueFactory::getCompoundValData(QualType T, const SVal* Vals,
-                                      unsigned NumVals) {
+BasicValueFactory::getCompoundValData(QualType T,
+                                      llvm::ImmutableList<SVal> Vals) {
+  
   llvm::FoldingSetNodeID ID;
-  CompoundValData::Profile(ID, T, NumVals, Vals);
+  CompoundValData::Profile(ID, T, Vals);
   void* InsertPos;
 
   CompoundValData* D = CompoundValDataSet.FindNodeOrInsertPos(ID, InsertPos);
 
   if (!D) {
     D = (CompoundValData*) BPAlloc.Allocate<CompoundValData>();
-    new (D) CompoundValData(T, Vals, NumVals, BPAlloc);
+    new (D) CompoundValData(T, Vals);
     CompoundValDataSet.InsertNode(D, InsertPos);
   }
 
index 8d5b8ab57410cf6d1a80770d8c124ec633d0b99b..b323087f5c97cb02370ca7d51305d4ed9096153a 100644 (file)
@@ -245,9 +245,9 @@ NonLoc NonLoc::MakeIntTruthVal(BasicValueFactory& BasicVals, bool b) {
   return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
 }
 
-NonLoc NonLoc::MakeCompoundVal(QualType T, SVal* Vals, unsigned NumSVals,
+NonLoc NonLoc::MakeCompoundVal(QualType T, llvm::ImmutableList<SVal> Vals,
                                BasicValueFactory& BasicVals) {
-  return nonloc::CompoundVal(BasicVals.getCompoundValData(T, Vals, NumSVals));
+  return nonloc::CompoundVal(BasicVals.getCompoundValData(T, Vals));
 }
 
 SVal SVal::GetSymbolValue(SymbolManager& SymMgr, VarDecl* D) {
@@ -260,6 +260,11 @@ SVal SVal::GetSymbolValue(SymbolManager& SymMgr, VarDecl* D) {
   return nonloc::SymbolVal(SymMgr.getSymbol(D));
 }
 
+nonloc::LocAsInteger nonloc::LocAsInteger::Make(BasicValueFactory& Vals, Loc V,
+                                                unsigned Bits) {
+  return LocAsInteger(Vals.getPersistentSValWithData(V, Bits));
+}
+
 //===----------------------------------------------------------------------===//
 // Utility methods for constructing Locs.
 //===----------------------------------------------------------------------===//
@@ -353,7 +358,7 @@ void NonLoc::print(std::ostream& Out) const {
       Out << " [as " << C.getNumBits() << " bit integer]";
       break;
     }
-      
+            
     default:
       assert (false && "Pretty-printed not implemented for this NonLoc.");
       break;