Added 'extents' for Regions.
Added 'getExtent()' to StoreManager.
Implemented 'getExtent()' for BasicStoreManager.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55321 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp
index 2ed89c6..c2482bc 100644
--- a/lib/Analysis/BasicStore.cpp
+++ b/lib/Analysis/BasicStore.cpp
@@ -25,9 +25,12 @@
 class VISIBILITY_HIDDEN BasicStoreManager : public StoreManager {
   typedef llvm::ImmutableMap<VarDecl*,RVal> VarBindingsTy;  
   VarBindingsTy::Factory VBFactory;
+  ASTContext& C;
   
 public:
-  BasicStoreManager(llvm::BumpPtrAllocator& A) : VBFactory(A) {}
+  BasicStoreManager(llvm::BumpPtrAllocator& A, ASTContext& c)
+    : VBFactory(A), C(c) {}
+  
   virtual ~BasicStoreManager() {}
 
   virtual RVal GetRVal(Store St, LVal LV, QualType T);  
@@ -51,13 +54,23 @@
 
   virtual void print(Store store, std::ostream& Out,
                      const char* nl, const char *sep);
+  
+  virtual RegionExtent getExtent(GRStateManager& SM, Region R);
 };  
   
 } // end anonymous namespace
 
 
-StoreManager* clang::CreateBasicStoreManager(llvm::BumpPtrAllocator& A) {
-  return new BasicStoreManager(A);
+StoreManager* clang::CreateBasicStoreManager(llvm::BumpPtrAllocator& A,
+                                             ASTContext& C) {
+  return new BasicStoreManager(A, C);
+}
+
+RegionExtent BasicStoreManager::getExtent(GRStateManager& SM, Region R) {
+  if (VarRegion *VR = dyn_cast<VarRegion>(&R))
+    return VR->getExtent(SM.getBasicVals());
+  
+  return UnknownExtent();
 }
 
 RVal BasicStoreManager::GetRVal(Store St, LVal LV, QualType T) {
@@ -75,30 +88,8 @@
       return T ? *T : UnknownVal();
     }
       
-    case lval::SymbolValKind: {
-      
-      // FIXME: This is a broken representation of memory, and is prone
-      //  to crashing the analyzer when addresses to symbolic values are
-      //  passed through casts.  We need a better representation of symbolic
-      //  memory (or just memory in general); probably we should do this
-      //  as a plugin class (similar to GRTransferFuncs).
-      
-#if 0      
-      const lval::SymbolVal& SV = cast<lval::SymbolVal>(LV);
-      assert (T.getTypePtr());
-      
-      // Punt on "symbolic" function pointers.
-      if (T->isFunctionType())
-        return UnknownVal();      
-      
-      if (T->isPointerType())
-        return lval::SymbolVal(SymMgr.getContentsOfSymbol(SV.getSymbol()));
-      else
-        return nonlval::SymbolVal(SymMgr.getContentsOfSymbol(SV.getSymbol()));
-#endif
-      
+    case lval::SymbolValKind:
       return UnknownVal();
-    }
       
     case lval::ConcreteIntKind:
       // Some clients may call GetRVal with such an option simply because
diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp
index 93ea525..a14695d 100644
--- a/lib/Analysis/GRExprEngine.cpp
+++ b/lib/Analysis/GRExprEngine.cpp
@@ -120,7 +120,7 @@
     G(CoreEngine.getGraph()),
     Liveness(L),
     Builder(NULL),
-    StateMgr(G.getContext(), CreateBasicStoreManager(G.getAllocator()),
+    StateMgr(G.getContext(), CreateBasicStoreManager(G.getAllocator(), Ctx),
              G.getAllocator(), G.getCFG(), L),
     SymMgr(StateMgr.getSymbolManager()),
     CurrentStmt(NULL),
diff --git a/lib/Analysis/Regions.cpp b/lib/Analysis/Regions.cpp
new file mode 100644
index 0000000..b725316
--- /dev/null
+++ b/lib/Analysis/Regions.cpp
@@ -0,0 +1,34 @@
+//==- Regions.cpp - Abstract memory locations ----------------------*- C++ -*-//
+//             
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file defines Region and its subclasses.  Regions represent abstract
+//  memory locations.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Analysis/PathSensitive/Regions.h"
+#include "clang/Analysis/PathSensitive/BasicValueFactory.h"
+#include "clang/AST/ASTContext.h"
+
+using namespace clang;
+
+RegionExtent VarRegion::getExtent(BasicValueFactory& BV) const {
+  QualType T = getDecl()->getType();
+  
+  // FIXME: Add support for VLAs.  This may require passing in additional
+  //  information, or tracking a different region type.
+  if (!T.getTypePtr()->isConstantSizeType())
+    return UnknownExtent();
+
+  ASTContext& C = BV.getContext();
+  assert (!T->isObjCInterfaceType()); // @interface not a possible VarDecl type.
+  assert (T != C.VoidTy); // void not a possible VarDecl type.  
+  return IntExtent(BV.getValue(C.getTypeSize(T), C.VoidPtrTy));
+}
+