I have a second patch to be committed immediately. Please review that one. Then we can discuss the design.
On Thu, Nov 13, 2008 at 3:37 PM, Ted Kremenek <[EMAIL PROTECTED]> wrote: > I'm not certain if this will work. alloca() often (always?) returns a > void*, so it basically represents an untyped glob of memory. It's pointee > type is "void", but that's not actually a type for an element. That's why > it doesn't subtype TypedRegion. > > One question is how to represent: > > char* p = (char*) alloca(8); > > alloca() itself returns a new region. To me the cast such layer a new > region on top of that region with the "char*" type information. That was > the point of the AnonTypedRegion (to add typing to a previously untyped glob > of memory). > > > On Nov 12, 2008, at 11:31 PM, Zhongxing Xu wrote: > > Author: zhongxingxu >> Date: Thu Nov 13 01:30:58 2008 >> New Revision: 59229 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=59229&view=rev >> Log: >> Change AllocaRegion to subclass TypedRegion. We need to know >> ElementRegion's >> type when assigning to it. >> >> 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=59229&r1=59228&r2=59229&view=diff >> >> >> ============================================================================== >> --- cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h (original) >> +++ cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h Thu Nov 13 >> 01:30:58 2008 >> @@ -37,9 +37,9 @@ >> 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 @@ >> } >> }; >> >> -/// 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 @@ >> } >> }; >> >> +/// 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; >> >> Modified: cfe/trunk/lib/Analysis/MemRegion.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/MemRegion.cpp?rev=59229&r1=59228&r2=59229&view=diff >> >> >> ============================================================================== >> --- cfe/trunk/lib/Analysis/MemRegion.cpp (original) >> +++ cfe/trunk/lib/Analysis/MemRegion.cpp Thu Nov 13 01:30:58 2008 >> @@ -105,8 +105,18 @@ >> >> 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."); >> } >> >> >> //===----------------------------------------------------------------------===// >> >> >> _______________________________________________ >> cfe-commits mailing list >> [email protected] >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >> > >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
