From a7f1b9e8804012ed8df25d93f5a06cb26c9bbd2b Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 24 Oct 2008 20:30:08 +0000 Subject: [PATCH] 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 --- .../clang/Analysis/PathSensitive/MemRegion.h | 44 ++++++++++++++++--- lib/Analysis/MemRegion.cpp | 21 +++++++++ 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/include/clang/Analysis/PathSensitive/MemRegion.h b/include/clang/Analysis/PathSensitive/MemRegion.h index e0ecb7180f..514760a4ac 100644 --- a/include/clang/Analysis/PathSensitive/MemRegion.h +++ b/include/clang/Analysis/PathSensitive/MemRegion.h @@ -39,7 +39,7 @@ public: // Typed regions. BEG_TYPED_REGIONS, VarRegionKind, FieldRegionKind, ElementRegionKind, - ObjCIvarRegionKind, + ObjCIvarRegionKind, ObjCObjectRegionKind, AnonTypedRegionKind, AnonPointeeRegionKind, END_TYPED_REGIONS }; private: @@ -127,7 +127,7 @@ protected: 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 @@ protected: 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 @@ class VarRegion : public DeclRegion { public: const VarDecl* getDecl() const { return cast(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 @@ public: void print(llvm::raw_ostream& os) const; const FieldDecl* getDecl() const { return cast(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 @@ public: } }; +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(D); + } + + QualType getType(ASTContext& C) const { + ObjCInterfaceDecl* ID = const_cast(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 @@ class ObjCIvarRegion : public DeclRegion { public: const ObjCIvarDecl* getDecl() const { return cast(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 @@ public: /// 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 9c76e452e8..5dad3560f0 100644 --- a/lib/Analysis/MemRegion.cpp +++ b/lib/Analysis/MemRegion.cpp @@ -230,6 +230,27 @@ MemRegionManager::getObjCIvarRegion(const ObjCIvarDecl* d, 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(data); + + if (!R) { + R = (ObjCObjectRegion*) A.Allocate(); + new (R) ObjCObjectRegion(d, superRegion); + Regions.InsertNode(R, InsertPos); + } + + return R; +} + + AnonPointeeRegion* MemRegionManager::getAnonPointeeRegion(const VarDecl* d) { llvm::FoldingSetNodeID ID; QualType T = d->getType(); -- 2.40.0