constify MemRegion* returned by MemRegionManager::getXXXRegion() methods.

llvm-svn: 90503
This commit is contained in:
Ted Kremenek 2009-12-04 00:26:31 +00:00
parent ca9cf65455
commit 721fcc007e
4 changed files with 62 additions and 64 deletions

View File

@ -691,50 +691,50 @@ public:
/// getStackRegion - Retrieve the memory region associated with the /// getStackRegion - Retrieve the memory region associated with the
/// current stack frame. /// current stack frame.
MemSpaceRegion *getStackRegion(); const MemSpaceRegion *getStackRegion();
/// getStackArgumentsRegion - Retrieve the memory region associated with /// getStackArgumentsRegion - Retrieve the memory region associated with
/// function/method arguments of the current stack frame. /// function/method arguments of the current stack frame.
MemSpaceRegion *getStackArgumentsRegion(); const MemSpaceRegion *getStackArgumentsRegion();
/// getGlobalsRegion - Retrieve the memory region associated with /// getGlobalsRegion - Retrieve the memory region associated with
/// all global variables. /// all global variables.
MemSpaceRegion *getGlobalsRegion(); const MemSpaceRegion *getGlobalsRegion();
/// getHeapRegion - Retrieve the memory region associated with the /// getHeapRegion - Retrieve the memory region associated with the
/// generic "heap". /// generic "heap".
MemSpaceRegion *getHeapRegion(); const MemSpaceRegion *getHeapRegion();
/// getUnknownRegion - Retrieve the memory region associated with unknown /// getUnknownRegion - Retrieve the memory region associated with unknown
/// memory space. /// memory space.
MemSpaceRegion *getUnknownRegion(); const MemSpaceRegion *getUnknownRegion();
MemSpaceRegion *getCodeRegion(); const MemSpaceRegion *getCodeRegion();
/// getAllocaRegion - Retrieve a region associated with a call to alloca(). /// getAllocaRegion - Retrieve a region associated with a call to alloca().
AllocaRegion *getAllocaRegion(const Expr* Ex, unsigned Cnt); const AllocaRegion *getAllocaRegion(const Expr* Ex, unsigned Cnt);
/// getCompoundLiteralRegion - Retrieve the region associated with a /// getCompoundLiteralRegion - Retrieve the region associated with a
/// given CompoundLiteral. /// given CompoundLiteral.
CompoundLiteralRegion* const CompoundLiteralRegion*
getCompoundLiteralRegion(const CompoundLiteralExpr* CL); getCompoundLiteralRegion(const CompoundLiteralExpr* CL);
/// getSymbolicRegion - Retrieve or create a "symbolic" memory region. /// getSymbolicRegion - Retrieve or create a "symbolic" memory region.
SymbolicRegion* getSymbolicRegion(SymbolRef sym); const SymbolicRegion* getSymbolicRegion(SymbolRef sym);
StringRegion* getStringRegion(const StringLiteral* Str); const StringRegion* getStringRegion(const StringLiteral* Str);
/// getVarRegion - Retrieve or create the memory region associated with /// getVarRegion - Retrieve or create the memory region associated with
/// a specified VarDecl and LocationContext. /// a specified VarDecl and LocationContext.
VarRegion* getVarRegion(const VarDecl *D, const LocationContext *LC); const VarRegion* getVarRegion(const VarDecl *D, const LocationContext *LC);
/// getElementRegion - Retrieve the memory region associated with the /// getElementRegion - Retrieve the memory region associated with the
/// associated element type, index, and super region. /// associated element type, index, and super region.
ElementRegion *getElementRegion(QualType elementType, SVal Idx, const ElementRegion *getElementRegion(QualType elementType, SVal Idx,
const MemRegion *superRegion, const MemRegion *superRegion,
ASTContext &Ctx); ASTContext &Ctx);
ElementRegion *getElementRegionWithSuper(const ElementRegion *ER, const ElementRegion *getElementRegionWithSuper(const ElementRegion *ER,
const MemRegion *superRegion) { const MemRegion *superRegion) {
return getElementRegion(ER->getElementType(), ER->getIndex(), return getElementRegion(ER->getElementType(), ER->getIndex(),
superRegion, ER->getContext()); superRegion, ER->getContext());
@ -744,29 +744,30 @@ public:
/// a specified FieldDecl. 'superRegion' corresponds to the containing /// a specified FieldDecl. 'superRegion' corresponds to the containing
/// memory region (which typically represents the memory representing /// memory region (which typically represents the memory representing
/// a structure or class). /// a structure or class).
FieldRegion *getFieldRegion(const FieldDecl* fd, const FieldRegion *getFieldRegion(const FieldDecl* fd,
const MemRegion* superRegion); const MemRegion* superRegion);
FieldRegion *getFieldRegionWithSuper(const FieldRegion *FR, const FieldRegion *getFieldRegionWithSuper(const FieldRegion *FR,
const MemRegion *superRegion) { const MemRegion *superRegion) {
return getFieldRegion(FR->getDecl(), superRegion); return getFieldRegion(FR->getDecl(), superRegion);
} }
/// getObjCObjectRegion - Retrieve or create the memory region associated with /// getObjCObjectRegion - Retrieve or create the memory region associated with
/// the instance of a specified Objective-C class. /// the instance of a specified Objective-C class.
ObjCObjectRegion* getObjCObjectRegion(const ObjCInterfaceDecl* ID, const ObjCObjectRegion* getObjCObjectRegion(const ObjCInterfaceDecl* ID,
const MemRegion* superRegion); const MemRegion* superRegion);
/// getObjCIvarRegion - Retrieve or create the memory region associated with /// getObjCIvarRegion - Retrieve or create the memory region associated with
/// a specified Objective-c instance variable. 'superRegion' corresponds /// a specified Objective-c instance variable. 'superRegion' corresponds
/// to the containing region (which typically represents the Objective-C /// to the containing region (which typically represents the Objective-C
/// object). /// object).
ObjCIvarRegion *getObjCIvarRegion(const ObjCIvarDecl* ivd, const ObjCIvarRegion *getObjCIvarRegion(const ObjCIvarDecl* ivd,
const MemRegion* superRegion); const MemRegion* superRegion);
FunctionTextRegion *getFunctionTextRegion(const FunctionDecl *FD); const FunctionTextRegion *getFunctionTextRegion(const FunctionDecl *FD);
BlockTextRegion *getBlockTextRegion(const BlockDecl *BD, CanQualType locTy); const BlockTextRegion *getBlockTextRegion(const BlockDecl *BD,
BlockDataRegion *getBlockDataRegion(const BlockTextRegion *bc, CanQualType locTy);
const BlockDataRegion *getBlockDataRegion(const BlockTextRegion *bc,
const LocationContext *lc); const LocationContext *lc);
bool isGlobalsRegion(const MemRegion* R) { bool isGlobalsRegion(const MemRegion* R) {
@ -788,7 +789,7 @@ private:
RegionTy* getSubRegion(const A1 a1, const A2 a2, RegionTy* getSubRegion(const A1 a1, const A2 a2,
const MemRegion* superRegion); const MemRegion* superRegion);
MemSpaceRegion* LazyAllocate(MemSpaceRegion*& region); const MemSpaceRegion* LazyAllocate(MemSpaceRegion*& region);
}; };
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -404,7 +404,7 @@ void RegionRawOffset::dumpToStream(llvm::raw_ostream& os) const {
// MemRegionManager methods. // MemRegionManager methods.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
MemSpaceRegion* MemRegionManager::LazyAllocate(MemSpaceRegion*& region) { const MemSpaceRegion *MemRegionManager::LazyAllocate(MemSpaceRegion*& region) {
if (!region) { if (!region) {
region = (MemSpaceRegion*) A.Allocate<MemSpaceRegion>(); region = (MemSpaceRegion*) A.Allocate<MemSpaceRegion>();
new (region) MemSpaceRegion(this); new (region) MemSpaceRegion(this);
@ -413,27 +413,27 @@ MemSpaceRegion* MemRegionManager::LazyAllocate(MemSpaceRegion*& region) {
return region; return region;
} }
MemSpaceRegion* MemRegionManager::getStackRegion() { const MemSpaceRegion *MemRegionManager::getStackRegion() {
return LazyAllocate(stack); return LazyAllocate(stack);
} }
MemSpaceRegion* MemRegionManager::getStackArgumentsRegion() { const MemSpaceRegion *MemRegionManager::getStackArgumentsRegion() {
return LazyAllocate(stackArguments); return LazyAllocate(stackArguments);
} }
MemSpaceRegion* MemRegionManager::getGlobalsRegion() { const MemSpaceRegion *MemRegionManager::getGlobalsRegion() {
return LazyAllocate(globals); return LazyAllocate(globals);
} }
MemSpaceRegion* MemRegionManager::getHeapRegion() { const MemSpaceRegion *MemRegionManager::getHeapRegion() {
return LazyAllocate(heap); return LazyAllocate(heap);
} }
MemSpaceRegion* MemRegionManager::getUnknownRegion() { const MemSpaceRegion *MemRegionManager::getUnknownRegion() {
return LazyAllocate(unknown); return LazyAllocate(unknown);
} }
MemSpaceRegion* MemRegionManager::getCodeRegion() { const MemSpaceRegion *MemRegionManager::getCodeRegion() {
return LazyAllocate(code); return LazyAllocate(code);
} }
@ -441,11 +441,11 @@ MemSpaceRegion* MemRegionManager::getCodeRegion() {
// Constructing regions. // Constructing regions.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
StringRegion* MemRegionManager::getStringRegion(const StringLiteral* Str) { const StringRegion* MemRegionManager::getStringRegion(const StringLiteral* Str) {
return getRegion<StringRegion>(Str); return getRegion<StringRegion>(Str);
} }
VarRegion* MemRegionManager::getVarRegion(const VarDecl *D, const VarRegion* MemRegionManager::getVarRegion(const VarDecl *D,
const LocationContext *LC) { const LocationContext *LC) {
// FIXME: Once we implement scope handling, we will need to properly lookup // FIXME: Once we implement scope handling, we will need to properly lookup
@ -457,9 +457,9 @@ VarRegion* MemRegionManager::getVarRegion(const VarDecl *D,
return getRegion<VarRegion>(D, LC); return getRegion<VarRegion>(D, LC);
} }
BlockDataRegion *MemRegionManager::getBlockDataRegion(const BlockTextRegion *BC, const BlockDataRegion *
const LocationContext *LC) MemRegionManager::getBlockDataRegion(const BlockTextRegion *BC,
{ const LocationContext *LC) {
// FIXME: Once we implement scope handling, we will need to properly lookup // FIXME: Once we implement scope handling, we will need to properly lookup
// 'D' to the proper LocationContext. For now, just strip down to the // 'D' to the proper LocationContext. For now, just strip down to the
// StackFrame. // StackFrame.
@ -469,12 +469,12 @@ BlockDataRegion *MemRegionManager::getBlockDataRegion(const BlockTextRegion *BC,
return getSubRegion<BlockDataRegion>(BC, LC, getStackRegion()); return getSubRegion<BlockDataRegion>(BC, LC, getStackRegion());
} }
CompoundLiteralRegion* const CompoundLiteralRegion*
MemRegionManager::getCompoundLiteralRegion(const CompoundLiteralExpr* CL) { MemRegionManager::getCompoundLiteralRegion(const CompoundLiteralExpr* CL) {
return getRegion<CompoundLiteralRegion>(CL); return getRegion<CompoundLiteralRegion>(CL);
} }
ElementRegion* const ElementRegion*
MemRegionManager::getElementRegion(QualType elementType, SVal Idx, MemRegionManager::getElementRegion(QualType elementType, SVal Idx,
const MemRegion* superRegion, const MemRegion* superRegion,
ASTContext& Ctx){ ASTContext& Ctx){
@ -497,40 +497,42 @@ MemRegionManager::getElementRegion(QualType elementType, SVal Idx,
return R; return R;
} }
FunctionTextRegion * const FunctionTextRegion *
MemRegionManager::getFunctionTextRegion(const FunctionDecl *FD) { MemRegionManager::getFunctionTextRegion(const FunctionDecl *FD) {
return getRegion<FunctionTextRegion>(FD); return getRegion<FunctionTextRegion>(FD);
} }
BlockTextRegion *MemRegionManager::getBlockTextRegion(const BlockDecl *BD, const BlockTextRegion *
CanQualType locTy) { MemRegionManager::getBlockTextRegion(const BlockDecl *BD, CanQualType locTy) {
return getRegion<BlockTextRegion>(BD, locTy); return getRegion<BlockTextRegion>(BD, locTy);
} }
/// getSymbolicRegion - Retrieve or create a "symbolic" memory region. /// getSymbolicRegion - Retrieve or create a "symbolic" memory region.
SymbolicRegion* MemRegionManager::getSymbolicRegion(SymbolRef sym) { const SymbolicRegion *MemRegionManager::getSymbolicRegion(SymbolRef sym) {
return getRegion<SymbolicRegion>(sym); return getRegion<SymbolicRegion>(sym);
} }
FieldRegion* MemRegionManager::getFieldRegion(const FieldDecl* d, const FieldRegion *
MemRegionManager::getFieldRegion(const FieldDecl* d,
const MemRegion* superRegion){ const MemRegion* superRegion){
return getSubRegion<FieldRegion>(d, superRegion); return getSubRegion<FieldRegion>(d, superRegion);
} }
ObjCIvarRegion* const ObjCIvarRegion*
MemRegionManager::getObjCIvarRegion(const ObjCIvarDecl* d, MemRegionManager::getObjCIvarRegion(const ObjCIvarDecl* d,
const MemRegion* superRegion) { const MemRegion* superRegion) {
return getSubRegion<ObjCIvarRegion>(d, superRegion); return getSubRegion<ObjCIvarRegion>(d, superRegion);
} }
ObjCObjectRegion* const ObjCObjectRegion*
MemRegionManager::getObjCObjectRegion(const ObjCInterfaceDecl* d, MemRegionManager::getObjCObjectRegion(const ObjCInterfaceDecl* d,
const MemRegion* superRegion) { const MemRegion* superRegion) {
return getSubRegion<ObjCObjectRegion>(d, superRegion); return getSubRegion<ObjCObjectRegion>(d, superRegion);
} }
AllocaRegion* MemRegionManager::getAllocaRegion(const Expr* E, unsigned cnt) { const AllocaRegion*
MemRegionManager::getAllocaRegion(const Expr* E, unsigned cnt) {
return getRegion<AllocaRegion>(E, cnt); return getRegion<AllocaRegion>(E, cnt);
} }

View File

@ -820,9 +820,8 @@ SVal RegionStoreManager::ArrayToPointer(Loc Array) {
T = AT->getElementType(); T = AT->getElementType();
SVal ZeroIdx = ValMgr.makeZeroArrayIndex(); SVal ZeroIdx = ValMgr.makeZeroArrayIndex();
ElementRegion* ER = MRMgr.getElementRegion(T, ZeroIdx, ArrayR, getContext()); return loc::MemRegionVal(MRMgr.getElementRegion(T, ZeroIdx, ArrayR,
getContext()));
return loc::MemRegionVal(ER);
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -1465,9 +1464,7 @@ const GRState *
RegionStoreManager::BindCompoundLiteral(const GRState *state, RegionStoreManager::BindCompoundLiteral(const GRState *state,
const CompoundLiteralExpr* CL, const CompoundLiteralExpr* CL,
SVal V) { SVal V) {
return Bind(state, loc::MemRegionVal(MRMgr.getCompoundLiteralRegion(CL)), V);
CompoundLiteralRegion* R = MRMgr.getCompoundLiteralRegion(CL);
return Bind(state, loc::MemRegionVal(R), V);
} }
const GRState *RegionStoreManager::setImplicitDefaultValue(const GRState *state, const GRState *RegionStoreManager::setImplicitDefaultValue(const GRState *state,
@ -1520,7 +1517,7 @@ const GRState *RegionStoreManager::BindArray(const GRState *state,
break; break;
SVal Idx = ValMgr.makeArrayIndex(i); SVal Idx = ValMgr.makeArrayIndex(i);
ElementRegion* ER = MRMgr.getElementRegion(ElementTy, Idx, R, const ElementRegion* ER = MRMgr.getElementRegion(ElementTy, Idx, R,
getContext()); getContext());
SVal V = ValMgr.makeIntVal(str[j], sizeof(char)*8, true); SVal V = ValMgr.makeIntVal(str[j], sizeof(char)*8, true);
@ -1549,7 +1546,7 @@ const GRState *RegionStoreManager::BindArray(const GRState *state,
break; break;
SVal Idx = ValMgr.makeArrayIndex(i); SVal Idx = ValMgr.makeArrayIndex(i);
ElementRegion* ER = MRMgr.getElementRegion(ElementTy, Idx, R, getContext()); const ElementRegion *ER = MRMgr.getElementRegion(ElementTy, Idx, R, getContext());
if (CAT->getElementType()->isStructureType()) if (CAT->getElementType()->isStructureType())
state = BindStruct(state, ER, *VI); state = BindStruct(state, ER, *VI);
@ -1871,8 +1868,7 @@ GRState const *RegionStoreManager::EnterStackFrame(GRState const *state,
// Copy the arg expression value to the arg variables. // Copy the arg expression value to the arg variables.
for (; AI != AE; ++AI, ++PI) { for (; AI != AE; ++AI, ++PI) {
SVal ArgVal = state->getSVal(*AI); SVal ArgVal = state->getSVal(*AI);
MemRegion *R = MRMgr.getVarRegion(*PI, frame); state = Bind(state, ValMgr.makeLoc(MRMgr.getVarRegion(*PI, frame)), ArgVal);
state = Bind(state, ValMgr.makeLoc(R), ArgVal);
} }
return state; return state;

View File

@ -138,15 +138,14 @@ ValueManager::getDerivedRegionValueSymbolVal(SymbolRef parentSymbol,
} }
DefinedSVal ValueManager::getFunctionPointer(const FunctionDecl* FD) { DefinedSVal ValueManager::getFunctionPointer(const FunctionDecl* FD) {
CodeTextRegion *R = MemMgr.getFunctionTextRegion(FD); return loc::MemRegionVal(MemMgr.getFunctionTextRegion(FD));
return loc::MemRegionVal(R);
} }
DefinedSVal ValueManager::getBlockPointer(const BlockDecl *D, DefinedSVal ValueManager::getBlockPointer(const BlockDecl *D,
CanQualType locTy, CanQualType locTy,
const LocationContext *LC) { const LocationContext *LC) {
BlockTextRegion *BC = MemMgr.getBlockTextRegion(D, locTy); const BlockTextRegion *BC = MemMgr.getBlockTextRegion(D, locTy);
BlockDataRegion *BD = MemMgr.getBlockDataRegion(BC, LC); const BlockDataRegion *BD = MemMgr.getBlockDataRegion(BC, LC);
return loc::MemRegionVal(BD); return loc::MemRegionVal(BD);
} }