- Remove AnonTypedRegion, which is not to be used.
- Prepare AnonPointeeRegioin for later use.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58595 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Analysis/PathSensitive/MemRegion.h b/include/clang/Analysis/PathSensitive/MemRegion.h
index 08c1a85..9226a04 100644
--- a/include/clang/Analysis/PathSensitive/MemRegion.h
+++ b/include/clang/Analysis/PathSensitive/MemRegion.h
@@ -47,7 +47,7 @@
                   VarRegionKind, FieldRegionKind,
                   ObjCIvarRegionKind, ObjCObjectRegionKind,
                  END_DECL_REGIONS,
-               AnonTypedRegionKind, AnonPointeeRegionKind,
+               AnonPointeeRegionKind,
               END_TYPED_REGIONS };  
 private:
   const Kind kind;
@@ -199,53 +199,35 @@
   }
 };
 
-/// AnonTypedRegion - An "anonymous" region that simply types a chunk
-///  of memory.
-class AnonTypedRegion : public TypedRegion {
-protected:
-  QualType T;
+/// AnonPointeeRegion - anonymous regions pointed-to by pointer function
+///  parameters or pointer globals. In RegionStoreManager, we assume pointer
+///  parameters or globals point at some anonymous region. Such regions are not
+///  the regions associated with the pointer variables themselves.  They are
+///  identified with the VarDecl of the pointer variable. We create them lazily.
 
+class AnonPointeeRegion : public TypedRegion {
   friend class MemRegionManager;
-  
-  AnonTypedRegion(QualType t, MemRegion* sreg)
-    : TypedRegion(sreg, AnonTypedRegionKind), T(t) {}
+  // VD - the pointer variable that points at this region.
+  const VarDecl* Pointer;
 
-  static void ProfileRegion(llvm::FoldingSetNodeID& ID, QualType T,
-                            const MemRegion* superRegion);
+  AnonPointeeRegion(const VarDecl* d, MemRegion* sreg)
+    : TypedRegion(sreg, AnonPointeeRegionKind), Pointer(d) {}
 
 public:
-  QualType getType(ASTContext& C) const { return C.getCanonicalType(T); }
-  
+  QualType getType(ASTContext& C) const;
 
-  void Profile(llvm::FoldingSetNodeID& ID) const;
-  
+  static void ProfileRegion(llvm::FoldingSetNodeID& ID, const VarDecl* PVD,
+                            const MemRegion* superRegion);
+
+  void Profile(llvm::FoldingSetNodeID& ID) const {
+    ProfileRegion(ID, Pointer, superRegion);
+  }
+
   static bool classof(const MemRegion* R) {
-    return R->getKind() == AnonTypedRegionKind;
+    return R->getKind() == AnonPointeeRegionKind;
   }
 };
 
-/// AnonPointeeRegion - anonymous regions pointed-at by pointer function
-///  parameters or pointer globals. In RegionStoreManager, we assume pointer
-///  parameters or globals point at some anonymous region initially. Such
-///  regions are not the regions associated with the pointers themselves, but
-///  are identified with the VarDecl of the parameters or globals.
-class AnonPointeeRegion : public AnonTypedRegion {
-  friend class MemRegionManager;
-  // VD - the pointer variable that points at this region.
-  const VarDecl* VD;
-
-  AnonPointeeRegion(const VarDecl* d, QualType t, MemRegion* sreg)
-    : AnonTypedRegion(t, sreg), VD(d) {}
-
-public:
-  static void ProfileRegion(llvm::FoldingSetNodeID& ID, const VarDecl* PVD,
-                            QualType T, const MemRegion* superRegion);
-};
-
-/// AnonHeapRegion - anonymous region created by malloc().
-class AnonHeapRegion : public AnonTypedRegion {
-};
-  
 /// CompoundLiteralRegion - A memory region representing a compound literal.
 ///   Compound literals are essentially temporaries that are stack allocated
 ///   or in the global constant pool.
diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp
index 14da4db..85ad3d8 100644
--- a/lib/Analysis/MemRegion.cpp
+++ b/lib/Analysis/MemRegion.cpp
@@ -44,26 +44,22 @@
   ProfileRegion(ID, Ex, Cnt);
 }
 
-void AnonTypedRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, QualType T,
-                                    const MemRegion* superRegion) {
-  ID.AddInteger((unsigned) AnonTypedRegionKind);
-  ID.Add(T);
-  ID.AddPointer(superRegion);
+QualType AnonPointeeRegion::getType(ASTContext& C) const {
+  QualType T = C.getCanonicalType(Pointer->getType());
+  PointerType* PTy = cast<PointerType>(T.getTypePtr());
+
+  QualType PointeeTy = C.getCanonicalType(PTy->getPointeeType());
+  return PointeeTy;
 }
 
 void AnonPointeeRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, 
-                                      const VarDecl* VD, QualType T,
+                                      const VarDecl* VD,
                                       const MemRegion* superRegion) {
   ID.AddInteger((unsigned) AnonPointeeRegionKind);
-  ID.Add(T);
   ID.AddPointer(VD);
   ID.AddPointer(superRegion);
 }
 
-void AnonTypedRegion::Profile(llvm::FoldingSetNodeID& ID) const {
-  AnonTypedRegion::ProfileRegion(ID, T, superRegion);
-}
-
 void CompoundLiteralRegion::Profile(llvm::FoldingSetNodeID& ID) const {
   CompoundLiteralRegion::ProfileRegion(ID, CL, superRegion);
 }
@@ -346,11 +342,9 @@
 
 AnonPointeeRegion* MemRegionManager::getAnonPointeeRegion(const VarDecl* d) {
   llvm::FoldingSetNodeID ID;
-  QualType T = d->getType();
-  QualType PointeeType = cast<PointerType>(T.getTypePtr())->getPointeeType();
   MemRegion* superRegion = getUnknownRegion();
 
-  AnonPointeeRegion::ProfileRegion(ID, d, PointeeType, superRegion);
+  AnonPointeeRegion::ProfileRegion(ID, d, superRegion);
 
   void* InsertPos;
   MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
@@ -358,7 +352,7 @@
 
   if (!R) {
     R = (AnonPointeeRegion*) A.Allocate<AnonPointeeRegion>();
-    new (R) AnonPointeeRegion(d, PointeeType, superRegion);
+    new (R) AnonPointeeRegion(d, superRegion);
     Regions.InsertNode(R, InsertPos);
   }