diff options
-rw-r--r-- | include/clang/Analysis/PathSensitive/MemRegion.h | 51 | ||||
-rw-r--r-- | lib/Analysis/MemRegion.cpp | 50 | ||||
-rw-r--r-- | lib/Analysis/RegionStore.cpp | 18 | ||||
-rw-r--r-- | lib/Analysis/ValueManager.cpp | 7 |
4 files changed, 62 insertions, 64 deletions
diff --git a/include/clang/Analysis/PathSensitive/MemRegion.h b/include/clang/Analysis/PathSensitive/MemRegion.h index 8e7c035d9d..8b13b9069e 100644 --- a/include/clang/Analysis/PathSensitive/MemRegion.h +++ b/include/clang/Analysis/PathSensitive/MemRegion.h @@ -691,50 +691,50 @@ public: /// getStackRegion - Retrieve the memory region associated with the /// current stack frame. - MemSpaceRegion *getStackRegion(); + const MemSpaceRegion *getStackRegion(); /// getStackArgumentsRegion - Retrieve the memory region associated with /// function/method arguments of the current stack frame. - MemSpaceRegion *getStackArgumentsRegion(); + const MemSpaceRegion *getStackArgumentsRegion(); /// getGlobalsRegion - Retrieve the memory region associated with /// all global variables. - MemSpaceRegion *getGlobalsRegion(); + const MemSpaceRegion *getGlobalsRegion(); /// getHeapRegion - Retrieve the memory region associated with the /// generic "heap". - MemSpaceRegion *getHeapRegion(); + const MemSpaceRegion *getHeapRegion(); /// getUnknownRegion - Retrieve the memory region associated with unknown /// memory space. - MemSpaceRegion *getUnknownRegion(); + const MemSpaceRegion *getUnknownRegion(); - MemSpaceRegion *getCodeRegion(); + const MemSpaceRegion *getCodeRegion(); /// 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 /// given CompoundLiteral. - CompoundLiteralRegion* + const CompoundLiteralRegion* getCompoundLiteralRegion(const CompoundLiteralExpr* CL); /// 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 /// 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 /// associated element type, index, and super region. - ElementRegion *getElementRegion(QualType elementType, SVal Idx, + const ElementRegion *getElementRegion(QualType elementType, SVal Idx, const MemRegion *superRegion, ASTContext &Ctx); - ElementRegion *getElementRegionWithSuper(const ElementRegion *ER, + const ElementRegion *getElementRegionWithSuper(const ElementRegion *ER, const MemRegion *superRegion) { return getElementRegion(ER->getElementType(), ER->getIndex(), superRegion, ER->getContext()); @@ -744,29 +744,30 @@ public: /// a specified FieldDecl. 'superRegion' corresponds to the containing /// memory region (which typically represents the memory representing /// a structure or class). - FieldRegion *getFieldRegion(const FieldDecl* fd, - const MemRegion* superRegion); + const FieldRegion *getFieldRegion(const FieldDecl* fd, + const MemRegion* superRegion); - FieldRegion *getFieldRegionWithSuper(const FieldRegion *FR, - const MemRegion *superRegion) { + const FieldRegion *getFieldRegionWithSuper(const FieldRegion *FR, + const MemRegion *superRegion) { return getFieldRegion(FR->getDecl(), superRegion); } /// getObjCObjectRegion - Retrieve or create the memory region associated with /// the instance of a specified Objective-C class. - ObjCObjectRegion* getObjCObjectRegion(const ObjCInterfaceDecl* ID, - const MemRegion* superRegion); + const ObjCObjectRegion* getObjCObjectRegion(const ObjCInterfaceDecl* ID, + const MemRegion* superRegion); /// getObjCIvarRegion - Retrieve or create the memory region associated with /// a specified Objective-c instance variable. 'superRegion' corresponds /// to the containing region (which typically represents the Objective-C /// object). - ObjCIvarRegion *getObjCIvarRegion(const ObjCIvarDecl* ivd, - const MemRegion* superRegion); + const ObjCIvarRegion *getObjCIvarRegion(const ObjCIvarDecl* ivd, + const MemRegion* superRegion); - FunctionTextRegion *getFunctionTextRegion(const FunctionDecl *FD); - BlockTextRegion *getBlockTextRegion(const BlockDecl *BD, CanQualType locTy); - BlockDataRegion *getBlockDataRegion(const BlockTextRegion *bc, + const FunctionTextRegion *getFunctionTextRegion(const FunctionDecl *FD); + const BlockTextRegion *getBlockTextRegion(const BlockDecl *BD, + CanQualType locTy); + const BlockDataRegion *getBlockDataRegion(const BlockTextRegion *bc, const LocationContext *lc); bool isGlobalsRegion(const MemRegion* R) { @@ -788,7 +789,7 @@ private: RegionTy* getSubRegion(const A1 a1, const A2 a2, const MemRegion* superRegion); - MemSpaceRegion* LazyAllocate(MemSpaceRegion*& region); + const MemSpaceRegion* LazyAllocate(MemSpaceRegion*& region); }; //===----------------------------------------------------------------------===// diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp index 9ca1f11638..2eb9d8e3ee 100644 --- a/lib/Analysis/MemRegion.cpp +++ b/lib/Analysis/MemRegion.cpp @@ -404,7 +404,7 @@ void RegionRawOffset::dumpToStream(llvm::raw_ostream& os) const { // MemRegionManager methods. //===----------------------------------------------------------------------===// -MemSpaceRegion* MemRegionManager::LazyAllocate(MemSpaceRegion*& region) { +const MemSpaceRegion *MemRegionManager::LazyAllocate(MemSpaceRegion*& region) { if (!region) { region = (MemSpaceRegion*) A.Allocate<MemSpaceRegion>(); new (region) MemSpaceRegion(this); @@ -413,27 +413,27 @@ MemSpaceRegion* MemRegionManager::LazyAllocate(MemSpaceRegion*& region) { return region; } -MemSpaceRegion* MemRegionManager::getStackRegion() { +const MemSpaceRegion *MemRegionManager::getStackRegion() { return LazyAllocate(stack); } -MemSpaceRegion* MemRegionManager::getStackArgumentsRegion() { +const MemSpaceRegion *MemRegionManager::getStackArgumentsRegion() { return LazyAllocate(stackArguments); } -MemSpaceRegion* MemRegionManager::getGlobalsRegion() { +const MemSpaceRegion *MemRegionManager::getGlobalsRegion() { return LazyAllocate(globals); } -MemSpaceRegion* MemRegionManager::getHeapRegion() { +const MemSpaceRegion *MemRegionManager::getHeapRegion() { return LazyAllocate(heap); } -MemSpaceRegion* MemRegionManager::getUnknownRegion() { +const MemSpaceRegion *MemRegionManager::getUnknownRegion() { return LazyAllocate(unknown); } -MemSpaceRegion* MemRegionManager::getCodeRegion() { +const MemSpaceRegion *MemRegionManager::getCodeRegion() { return LazyAllocate(code); } @@ -441,12 +441,12 @@ MemSpaceRegion* MemRegionManager::getCodeRegion() { // Constructing regions. //===----------------------------------------------------------------------===// -StringRegion* MemRegionManager::getStringRegion(const StringLiteral* Str) { +const StringRegion* MemRegionManager::getStringRegion(const StringLiteral* Str) { return getRegion<StringRegion>(Str); } -VarRegion* MemRegionManager::getVarRegion(const VarDecl *D, - const LocationContext *LC) { +const VarRegion* MemRegionManager::getVarRegion(const VarDecl *D, + const LocationContext *LC) { // FIXME: Once we implement scope handling, we will need to properly lookup // 'D' to the proper LocationContext. For now, just strip down to the @@ -457,9 +457,9 @@ VarRegion* MemRegionManager::getVarRegion(const VarDecl *D, return getRegion<VarRegion>(D, LC); } -BlockDataRegion *MemRegionManager::getBlockDataRegion(const BlockTextRegion *BC, - const LocationContext *LC) -{ +const BlockDataRegion * +MemRegionManager::getBlockDataRegion(const BlockTextRegion *BC, + const LocationContext *LC) { // FIXME: Once we implement scope handling, we will need to properly lookup // 'D' to the proper LocationContext. For now, just strip down to the // StackFrame. @@ -469,12 +469,12 @@ BlockDataRegion *MemRegionManager::getBlockDataRegion(const BlockTextRegion *BC, return getSubRegion<BlockDataRegion>(BC, LC, getStackRegion()); } -CompoundLiteralRegion* +const CompoundLiteralRegion* MemRegionManager::getCompoundLiteralRegion(const CompoundLiteralExpr* CL) { return getRegion<CompoundLiteralRegion>(CL); } -ElementRegion* +const ElementRegion* MemRegionManager::getElementRegion(QualType elementType, SVal Idx, const MemRegion* superRegion, ASTContext& Ctx){ @@ -497,40 +497,42 @@ MemRegionManager::getElementRegion(QualType elementType, SVal Idx, return R; } -FunctionTextRegion * +const FunctionTextRegion * MemRegionManager::getFunctionTextRegion(const FunctionDecl *FD) { return getRegion<FunctionTextRegion>(FD); } -BlockTextRegion *MemRegionManager::getBlockTextRegion(const BlockDecl *BD, - CanQualType locTy) { +const BlockTextRegion * +MemRegionManager::getBlockTextRegion(const BlockDecl *BD, CanQualType locTy) { return getRegion<BlockTextRegion>(BD, locTy); } /// getSymbolicRegion - Retrieve or create a "symbolic" memory region. -SymbolicRegion* MemRegionManager::getSymbolicRegion(SymbolRef sym) { +const SymbolicRegion *MemRegionManager::getSymbolicRegion(SymbolRef sym) { return getRegion<SymbolicRegion>(sym); } -FieldRegion* MemRegionManager::getFieldRegion(const FieldDecl* d, - const MemRegion* superRegion) { +const FieldRegion * +MemRegionManager::getFieldRegion(const FieldDecl* d, + const MemRegion* superRegion){ return getSubRegion<FieldRegion>(d, superRegion); } -ObjCIvarRegion* +const ObjCIvarRegion* MemRegionManager::getObjCIvarRegion(const ObjCIvarDecl* d, const MemRegion* superRegion) { return getSubRegion<ObjCIvarRegion>(d, superRegion); } -ObjCObjectRegion* +const ObjCObjectRegion* MemRegionManager::getObjCObjectRegion(const ObjCInterfaceDecl* d, const MemRegion* 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); } diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index a9cd582bf8..13462f4785 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -820,9 +820,8 @@ SVal RegionStoreManager::ArrayToPointer(Loc Array) { T = AT->getElementType(); SVal ZeroIdx = ValMgr.makeZeroArrayIndex(); - ElementRegion* ER = MRMgr.getElementRegion(T, ZeroIdx, ArrayR, getContext()); - - return loc::MemRegionVal(ER); + return loc::MemRegionVal(MRMgr.getElementRegion(T, ZeroIdx, ArrayR, + getContext())); } //===----------------------------------------------------------------------===// @@ -1465,9 +1464,7 @@ const GRState * RegionStoreManager::BindCompoundLiteral(const GRState *state, const CompoundLiteralExpr* CL, SVal V) { - - CompoundLiteralRegion* R = MRMgr.getCompoundLiteralRegion(CL); - return Bind(state, loc::MemRegionVal(R), V); + return Bind(state, loc::MemRegionVal(MRMgr.getCompoundLiteralRegion(CL)), V); } const GRState *RegionStoreManager::setImplicitDefaultValue(const GRState *state, @@ -1520,8 +1517,8 @@ const GRState *RegionStoreManager::BindArray(const GRState *state, break; SVal Idx = ValMgr.makeArrayIndex(i); - ElementRegion* ER = MRMgr.getElementRegion(ElementTy, Idx, R, - getContext()); + const ElementRegion* ER = MRMgr.getElementRegion(ElementTy, Idx, R, + getContext()); SVal V = ValMgr.makeIntVal(str[j], sizeof(char)*8, true); state = Bind(state, loc::MemRegionVal(ER), V); @@ -1549,7 +1546,7 @@ const GRState *RegionStoreManager::BindArray(const GRState *state, break; 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()) 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. for (; AI != AE; ++AI, ++PI) { SVal ArgVal = state->getSVal(*AI); - MemRegion *R = MRMgr.getVarRegion(*PI, frame); - state = Bind(state, ValMgr.makeLoc(R), ArgVal); + state = Bind(state, ValMgr.makeLoc(MRMgr.getVarRegion(*PI, frame)), ArgVal); } return state; diff --git a/lib/Analysis/ValueManager.cpp b/lib/Analysis/ValueManager.cpp index 22a821149d..1e7a5fced0 100644 --- a/lib/Analysis/ValueManager.cpp +++ b/lib/Analysis/ValueManager.cpp @@ -138,15 +138,14 @@ ValueManager::getDerivedRegionValueSymbolVal(SymbolRef parentSymbol, } DefinedSVal ValueManager::getFunctionPointer(const FunctionDecl* FD) { - CodeTextRegion *R = MemMgr.getFunctionTextRegion(FD); - return loc::MemRegionVal(R); + return loc::MemRegionVal(MemMgr.getFunctionTextRegion(FD)); } DefinedSVal ValueManager::getBlockPointer(const BlockDecl *D, CanQualType locTy, const LocationContext *LC) { - BlockTextRegion *BC = MemMgr.getBlockTextRegion(D, locTy); - BlockDataRegion *BD = MemMgr.getBlockDataRegion(BC, LC); + const BlockTextRegion *BC = MemMgr.getBlockTextRegion(D, locTy); + const BlockDataRegion *BD = MemMgr.getBlockDataRegion(BC, LC); return loc::MemRegionVal(BD); } |