diff options
author | Zhongxing Xu <xuzhongxing@gmail.com> | 2008-11-13 07:30:58 +0000 |
---|---|---|
committer | Zhongxing Xu <xuzhongxing@gmail.com> | 2008-11-13 07:30:58 +0000 |
commit | 56af9773056eb064937c872845c0da6e3d46d4b4 (patch) | |
tree | b5452f147a6179525bec044236b1493568d1627b | |
parent | ea817281b3a7c16f96a89ccd89699b22603a6811 (diff) |
Change AllocaRegion to subclass TypedRegion. We need to know ElementRegion's
type when assigning to it.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59229 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Analysis/PathSensitive/MemRegion.h | 66 | ||||
-rw-r--r-- | lib/Analysis/MemRegion.cpp | 14 |
2 files changed, 49 insertions, 31 deletions
diff --git a/include/clang/Analysis/PathSensitive/MemRegion.h b/include/clang/Analysis/PathSensitive/MemRegion.h index 04d904623e..2de2a3ed14 100644 --- a/include/clang/Analysis/PathSensitive/MemRegion.h +++ b/include/clang/Analysis/PathSensitive/MemRegion.h @@ -37,9 +37,9 @@ class MemRegionManager; class MemRegion : public llvm::FoldingSetNode { public: enum Kind { MemSpaceRegionKind, SymbolicRegionKind, - AllocaRegionKind, // Typed regions. BEG_TYPED_REGIONS, + AllocaRegionKind, CompoundLiteralRegionKind, StringRegionKind, ElementRegionKind, // Decl Regions. @@ -102,34 +102,6 @@ public: } }; -/// AllocaRegion - A region that represents an untyped blob of bytes created -/// by a call to 'alloca'. -class AllocaRegion : public SubRegion { - friend class MemRegionManager; -protected: - unsigned Cnt; // Block counter. Used to distinguish different pieces of - // memory allocated by alloca at the same call site. - const Expr* Ex; - - AllocaRegion(const Expr* ex, unsigned cnt, const MemRegion* superRegion) - : SubRegion(superRegion, AllocaRegionKind), Cnt(cnt), Ex(ex) {} - -public: - - const Expr* getExpr() const { return Ex; } - - void Profile(llvm::FoldingSetNodeID& ID) const; - - static void ProfileRegion(llvm::FoldingSetNodeID& ID, const Expr* Ex, - unsigned Cnt); - - void print(llvm::raw_ostream& os) const; - - static bool classof(const MemRegion* R) { - return R->getKind() == AllocaRegionKind; - } -}; - /// SymbolicRegion - A special, "non-concrete" region. Unlike other region /// clases, SymbolicRegion represents a region that serves as an alias for /// either a real region, a NULL pointer, etc. It essentially is used to @@ -170,6 +142,42 @@ public: } }; +/// AllocaRegion - A region that represents an untyped blob of bytes created +/// by a call to 'alloca'. +class AllocaRegion : public TypedRegion { + friend class MemRegionManager; +protected: + unsigned Cnt; // Block counter. Used to distinguish different pieces of + // memory allocated by alloca at the same call site. + const Expr* Ex; + + QualType T; + + AllocaRegion(const Expr* ex, unsigned cnt, const MemRegion* superRegion) + : TypedRegion(superRegion, AllocaRegionKind), Cnt(cnt), Ex(ex) {} + +public: + + const Expr* getExpr() const { return Ex; } + + void setType(QualType t) { T = t; } + + QualType getType(ASTContext& C) const { + return C.getCanonicalType(T); + } + + void Profile(llvm::FoldingSetNodeID& ID) const; + + static void ProfileRegion(llvm::FoldingSetNodeID& ID, const Expr* Ex, + unsigned Cnt); + + void print(llvm::raw_ostream& os) const; + + static bool classof(const MemRegion* R) { + return R->getKind() == AllocaRegionKind; + } +}; + /// StringRegion - Region associated with a StringLiteral. class StringRegion : public TypedRegion { friend class MemRegionManager; diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp index ae575f1164..a292d98e60 100644 --- a/lib/Analysis/MemRegion.cpp +++ b/lib/Analysis/MemRegion.cpp @@ -105,8 +105,18 @@ void ElementRegion::Profile(llvm::FoldingSetNodeID& ID) const { QualType ElementRegion::getType(ASTContext& C) const { QualType T = cast<TypedRegion>(superRegion)->getType(C); - ArrayType* AT = cast<ArrayType>(T.getTypePtr()); - return AT->getElementType(); + + if (isa<ArrayType>(T.getTypePtr())) { + ArrayType* AT = cast<ArrayType>(T.getTypePtr()); + return AT->getElementType(); + } + else if (isa<AllocaRegion>(superRegion)) { + PointerType* PtrT = cast<PointerType>(T.getTypePtr()); + QualType PTy = PtrT->getPointeeType(); + return C.getCanonicalType(PTy); + } + else + assert(0 && "SuperRegion type unsupported."); } //===----------------------------------------------------------------------===// |