forked from OSchip/llvm-project
Added CompoundLiteralRegion to represent the (temporary) memory allocated for a compound literal.
llvm-svn: 58270
This commit is contained in:
parent
b88d775201
commit
bc48caf383
|
@ -36,14 +36,17 @@ class MemRegionManager;
|
|||
class MemRegion : public llvm::FoldingSetNode {
|
||||
public:
|
||||
enum Kind { MemSpaceRegionKind, SymbolicRegionKind,
|
||||
// Subregions.
|
||||
CompoundLiteralRegionKind,
|
||||
// Typed regions.
|
||||
BEG_TYPED_REGIONS,
|
||||
StringRegionKind, ElementRegionKind,
|
||||
BEG_DECL_REGIONS,
|
||||
VarRegionKind, FieldRegionKind,
|
||||
ObjCIvarRegionKind, ObjCObjectRegionKind,
|
||||
END_DECL_REGIONS,
|
||||
AnonTypedRegionKind, AnonPointeeRegionKind,
|
||||
StringRegionKind, ElementRegionKind,
|
||||
// Decl Regions.
|
||||
BEG_DECL_REGIONS,
|
||||
VarRegionKind, FieldRegionKind,
|
||||
ObjCIvarRegionKind, ObjCObjectRegionKind,
|
||||
END_DECL_REGIONS,
|
||||
AnonTypedRegionKind, AnonPointeeRegionKind,
|
||||
END_TYPED_REGIONS };
|
||||
private:
|
||||
const Kind kind;
|
||||
|
@ -213,6 +216,30 @@ public:
|
|||
/// AnonHeapRegion - anonymous region created by malloc().
|
||||
class AnonHeapRegion : public AnonTypedRegion {
|
||||
};
|
||||
|
||||
/// CompoundLiteralRegion - A memory region representing a compound literal.
|
||||
/// Compound literals are essentially temporaries that are stack allocated
|
||||
/// or in the global constant pool.
|
||||
class CompoundLiteralRegion : public SubRegion {
|
||||
private:
|
||||
friend class MemRegionManager;
|
||||
const CompoundLiteralExpr* CL;
|
||||
|
||||
CompoundLiteralRegion(const CompoundLiteralExpr* cl, const MemRegion* sReg)
|
||||
: SubRegion(sReg,CompoundLiteralRegionKind), CL(cl) {}
|
||||
|
||||
static void ProfileRegion(llvm::FoldingSetNodeID& ID,
|
||||
const CompoundLiteralExpr* CL,
|
||||
const MemRegion* superRegion);
|
||||
public:
|
||||
void Profile(llvm::FoldingSetNodeID& ID) const;
|
||||
|
||||
void print(llvm::raw_ostream& os) const;
|
||||
|
||||
static bool classof(const MemRegion* R) {
|
||||
return R->getKind() == CompoundLiteralRegionKind;
|
||||
}
|
||||
};
|
||||
|
||||
class DeclRegion : public TypedRegion {
|
||||
protected:
|
||||
|
@ -392,6 +419,11 @@ public:
|
|||
/// memory space.
|
||||
MemSpaceRegion* getUnknownRegion();
|
||||
|
||||
/// getCompoundLiteralRegion - Retrieve the region associated with a
|
||||
/// given CompoundLiteral.
|
||||
CompoundLiteralRegion*
|
||||
getCompoundLiteralRegion(const CompoundLiteralExpr* CL);
|
||||
|
||||
/// getSymbolicRegion - Retrieve or create a "symbolic" memory region.
|
||||
SymbolicRegion* getSymbolicRegion(const SymbolID sym);
|
||||
|
||||
|
@ -406,7 +438,7 @@ public:
|
|||
return getVarRegion(vd, vd->hasLocalStorage() ? getStackRegion()
|
||||
: getGlobalsRegion());
|
||||
}
|
||||
|
||||
|
||||
ElementRegion* getElementRegion(SVal Idx, const MemRegion* superRegion);
|
||||
|
||||
/// getFieldRegion - Retrieve or create the memory region associated with
|
||||
|
|
|
@ -53,6 +53,18 @@ void AnonTypedRegion::Profile(llvm::FoldingSetNodeID& ID) const {
|
|||
AnonTypedRegion::ProfileRegion(ID, T, superRegion);
|
||||
}
|
||||
|
||||
void CompoundLiteralRegion::Profile(llvm::FoldingSetNodeID& ID) const {
|
||||
CompoundLiteralRegion::ProfileRegion(ID, CL, superRegion);
|
||||
}
|
||||
|
||||
void CompoundLiteralRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
|
||||
const CompoundLiteralExpr* CL,
|
||||
const MemRegion* superRegion) {
|
||||
ID.AddInteger((unsigned) CompoundLiteralRegionKind);
|
||||
ID.AddPointer(CL);
|
||||
ID.AddPointer(superRegion);
|
||||
}
|
||||
|
||||
void DeclRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, const Decl* D,
|
||||
const MemRegion* superRegion, Kind k) {
|
||||
ID.AddInteger((unsigned) k);
|
||||
|
@ -123,6 +135,11 @@ void ElementRegion::print(llvm::raw_ostream& os) const {
|
|||
os << '['; Index.print(os); os << ']';
|
||||
}
|
||||
|
||||
void CompoundLiteralRegion::print(llvm::raw_ostream& os) const {
|
||||
// FIXME: More elaborate pretty-printing.
|
||||
os << "{ " << (void*) CL << " }";
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// MemRegionManager methods.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -190,6 +207,30 @@ VarRegion* MemRegionManager::getVarRegion(const VarDecl* d,
|
|||
return R;
|
||||
}
|
||||
|
||||
CompoundLiteralRegion*
|
||||
MemRegionManager::getCompoundLiteralRegion(const CompoundLiteralExpr* CL) {
|
||||
// Is this compound literal allocated on the stack or is part of the
|
||||
// global constant pool?
|
||||
const MemRegion* superRegion = CL->isFileScope() ?
|
||||
getGlobalsRegion() : getStackRegion();
|
||||
|
||||
// Profile the compound literal.
|
||||
llvm::FoldingSetNodeID ID;
|
||||
CompoundLiteralRegion::ProfileRegion(ID, CL, superRegion);
|
||||
|
||||
void* InsertPos;
|
||||
MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
|
||||
CompoundLiteralRegion* R = cast_or_null<CompoundLiteralRegion>(data);
|
||||
|
||||
if (!R) {
|
||||
R = (CompoundLiteralRegion*) A.Allocate<CompoundLiteralRegion>();
|
||||
new (R) CompoundLiteralRegion(CL, superRegion);
|
||||
Regions.InsertNode(R, InsertPos);
|
||||
}
|
||||
|
||||
return R;
|
||||
}
|
||||
|
||||
ElementRegion* MemRegionManager::getElementRegion(SVal Idx,
|
||||
const MemRegion* superRegion){
|
||||
llvm::FoldingSetNodeID ID;
|
||||
|
|
Loading…
Reference in New Issue