[cfe-commits] r58106 - in /cfe/trunk: include/clang/Analysis/PathSensitive/MemRegion.h lib/Analysis/MemRegion.cpp

Ted Kremenek kremenek at apple.com
Fri Oct 24 13:30:09 PDT 2008


Author: kremenek
Date: Fri Oct 24 15:30:08 2008
New Revision: 58106

URL: http://llvm.org/viewvc/llvm-project?rev=58106&view=rev
Log:
Added region ObjCObjectRegion that represents an instance of an Objective-C object.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
    cfe/trunk/lib/Analysis/MemRegion.cpp

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h?rev=58106&r1=58105&r2=58106&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h Fri Oct 24 15:30:08 2008
@@ -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

Modified: cfe/trunk/lib/Analysis/MemRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/MemRegion.cpp?rev=58106&r1=58105&r2=58106&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/MemRegion.cpp (original)
+++ cfe/trunk/lib/Analysis/MemRegion.cpp Fri Oct 24 15:30:08 2008
@@ -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();





More information about the cfe-commits mailing list