Added region ObjCObjectRegion that represents an instance of an Objective-C object.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58106 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Analysis/PathSensitive/MemRegion.h b/include/clang/Analysis/PathSensitive/MemRegion.h
index e0ecb71..514760a 100644
--- a/include/clang/Analysis/PathSensitive/MemRegion.h
+++ b/include/clang/Analysis/PathSensitive/MemRegion.h
@@ -39,7 +39,7 @@
               // Typed regions.
               BEG_TYPED_REGIONS,
               VarRegionKind, FieldRegionKind, ElementRegionKind,
-              ObjCIvarRegionKind,
+              ObjCIvarRegionKind, ObjCObjectRegionKind,
               AnonTypedRegionKind, AnonPointeeRegionKind,
               END_TYPED_REGIONS };  
 private:
@@ -127,7 +127,7 @@
   TypedRegion(const MemRegion* sReg, Kind k) : SubRegion(sReg, k) {}
   
 public:
-  virtual QualType getType() const = 0;
+  virtual QualType getType(ASTContext&) const = 0;
     
   static bool classof(const MemRegion* R) {
     unsigned k = R->getKind();
@@ -150,7 +150,7 @@
                             const MemRegion* superRegion);
 
 public:
-  QualType getType() const { return T; }
+  QualType getType(ASTContext&) const { return T; }
   
 
   void Profile(llvm::FoldingSetNodeID& ID) const;
@@ -210,7 +210,7 @@
   
 public:  
   const VarDecl* getDecl() const { return cast<VarDecl>(D); }
-  QualType getType() const { return getDecl()->getType(); }
+  QualType getType(ASTContext&) const { return getDecl()->getType(); }
   
   void print(llvm::raw_ostream& os) const;
   
@@ -230,7 +230,7 @@
   void print(llvm::raw_ostream& os) const;
   
   const FieldDecl* getDecl() const { return cast<FieldDecl>(D); }
-  QualType getType() const { return getDecl()->getType(); }
+  QualType getType(ASTContext&) const { return getDecl()->getType(); }
 
   static void ProfileRegion(llvm::FoldingSetNodeID& ID, FieldDecl* FD,
                       const MemRegion* superRegion) {
@@ -242,6 +242,33 @@
   }
 };
   
+class ObjCObjectRegion : public DeclRegion {
+  
+  friend class MemRegionManager;
+  
+  ObjCObjectRegion(const ObjCInterfaceDecl* ivd, const MemRegion* sReg)
+  : DeclRegion(ivd, sReg, ObjCObjectRegionKind) {}
+  
+  static void ProfileRegion(llvm::FoldingSetNodeID& ID, ObjCInterfaceDecl* ivd,
+                            const MemRegion* superRegion) {
+    DeclRegion::ProfileRegion(ID, ivd, superRegion, ObjCObjectRegionKind);
+  }
+  
+public:
+  const ObjCInterfaceDecl* getInterface() const {
+    return cast<ObjCInterfaceDecl>(D);
+  }
+  
+  QualType getType(ASTContext& C) const {
+    ObjCInterfaceDecl* ID = const_cast<ObjCInterfaceDecl*>(getInterface());
+    return C.getObjCInterfaceType(ID);
+  }
+  
+  static bool classof(const MemRegion* R) {
+    return R->getKind() == ObjCObjectRegionKind;
+  }
+};  
+  
 class ObjCIvarRegion : public DeclRegion {
   
   friend class MemRegionManager;
@@ -256,7 +283,7 @@
   
 public:
   const ObjCIvarDecl* getDecl() const { return cast<ObjCIvarDecl>(D); }
-  QualType getType() const { return getDecl()->getType(); }
+  QualType getType(ASTContext&) const { return getDecl()->getType(); }
   
   static bool classof(const MemRegion* R) {
     return R->getKind() == ObjCIvarRegionKind;
@@ -343,6 +370,11 @@
   ///  a structure or class).
   FieldRegion* getFieldRegion(const FieldDecl* fd, const MemRegion* superRegion);
   
+  /// getObjCObjectRegion - Retrieve or create the memory region associated with
+  ///  the instance of a specified Objective-C class.
+  ObjCObjectRegion* getObjCObjectRegion(const ObjCInterfaceDecl* ID,
+                                  const MemRegion* superRegion);
+  
   /// getObjCIvarRegion - Retrieve or create the memory region associated with
   ///   a specified Objective-c instance variable.  'superRegion' corresponds
   ///   to the containing region (which typically represents the Objective-C
diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp
index 9c76e45..5dad356 100644
--- a/lib/Analysis/MemRegion.cpp
+++ b/lib/Analysis/MemRegion.cpp
@@ -230,6 +230,27 @@
   return R;
 }
 
+ObjCObjectRegion*
+MemRegionManager::getObjCObjectRegion(const ObjCInterfaceDecl* d,
+                                    const MemRegion* superRegion) {
+  llvm::FoldingSetNodeID ID;
+  DeclRegion::ProfileRegion(ID, d, superRegion,
+                            MemRegion::ObjCObjectRegionKind);
+  
+  void* InsertPos;
+  MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
+  ObjCObjectRegion* R = cast_or_null<ObjCObjectRegion>(data);
+  
+  if (!R) {
+    R = (ObjCObjectRegion*) A.Allocate<ObjCObjectRegion>();
+    new (R) ObjCObjectRegion(d, superRegion);
+    Regions.InsertNode(R, InsertPos);
+  }
+  
+  return R;
+}
+
+
 AnonPointeeRegion* MemRegionManager::getAnonPointeeRegion(const VarDecl* d) {
   llvm::FoldingSetNodeID ID;
   QualType T = d->getType();