Add StringRegion to MemRegions.

llvm-svn: 58137
This commit is contained in:
Zhongxing Xu 2008-10-25 14:13:41 +00:00
parent 80422b07c5
commit d1aac353e5
2 changed files with 68 additions and 2 deletions

View File

@ -38,8 +38,11 @@ public:
enum Kind { MemSpaceRegionKind, SymbolicRegionKind,
// Typed regions.
BEG_TYPED_REGIONS,
VarRegionKind, FieldRegionKind, ElementRegionKind,
StringRegionKind, ElementRegionKind,
BEG_DECL_REGIONS,
VarRegionKind, FieldRegionKind,
ObjCIvarRegionKind, ObjCObjectRegionKind,
END_DECL_REGIONS,
AnonTypedRegionKind, AnonPointeeRegionKind,
END_TYPED_REGIONS };
private:
@ -135,6 +138,35 @@ public:
}
};
/// StringRegion - Region associated with a StringLiteral.
class StringRegion : public TypedRegion {
friend class MemRegionManager;
const StringLiteral* Str;
protected:
StringRegion(const StringLiteral* str, MemRegion* sreg)
: TypedRegion(sreg, StringRegionKind), Str(str) {}
static void ProfileRegion(llvm::FoldingSetNodeID& ID,
const StringLiteral* Str,
const MemRegion* superRegion);
public:
QualType getType(ASTContext&) const {
return Str->getType();
}
void Profile(llvm::FoldingSetNodeID& ID) const {
ProfileRegion(ID, Str, superRegion);
}
static bool classof(const MemRegion* R) {
return R->getKind() == StringRegionKind;
}
};
/// AnonTypedRegion - An "anonymous" region that simply types a chunk
/// of memory.
class AnonTypedRegion : public TypedRegion {
@ -195,6 +227,11 @@ protected:
public:
const Decl* getDecl() const { return D; }
void Profile(llvm::FoldingSetNodeID& ID) const;
static bool classof(const MemRegion* R) {
unsigned k = R->getKind();
return k > BEG_DECL_REGIONS && k < END_DECL_REGIONS;
}
};
class VarRegion : public DeclRegion {
@ -352,6 +389,8 @@ public:
/// getSymbolicRegion - Retrieve or create a "symbolic" memory region.
SymbolicRegion* getSymbolicRegion(const SymbolID sym);
StringRegion* getStringRegion(const StringLiteral* Str);
/// getVarRegion - Retrieve or create the memory region associated with
/// a specified VarDecl. 'superRegion' corresponds to the containing
/// memory region, and 'off' is the offset within the containing region.

View File

@ -25,6 +25,14 @@ void MemSpaceRegion::Profile(llvm::FoldingSetNodeID& ID) const {
ID.AddInteger((unsigned)getKind());
}
void StringRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
const StringLiteral* Str,
const MemRegion* superRegion) {
ID.AddInteger((unsigned) StringRegionKind);
ID.AddPointer(Str);
ID.AddPointer(superRegion);
}
void AnonTypedRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, QualType T,
const MemRegion* superRegion) {
ID.AddInteger((unsigned) AnonTypedRegionKind);
@ -138,6 +146,25 @@ MemSpaceRegion* MemRegionManager::getUnknownRegion() {
return LazyAllocate(unknown);
}
StringRegion* MemRegionManager::getStringRegion(const StringLiteral* Str) {
llvm::FoldingSetNodeID ID;
MemSpaceRegion* GlobalsR = getGlobalsRegion();
StringRegion::ProfileRegion(ID, Str, GlobalsR);
void* InsertPos;
MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
StringRegion* R = cast_or_null<StringRegion>(data);
if (!R) {
R = (StringRegion*) A.Allocate<StringRegion>();
new (R) StringRegion(Str, GlobalsR);
Regions.InsertNode(R, InsertPos);
}
return R;
}
VarRegion* MemRegionManager::getVarRegion(const VarDecl* d,
const MemRegion* superRegion) {
llvm::FoldingSetNodeID ID;