From: Zhongxing Xu Date: Mon, 8 Feb 2010 07:58:06 +0000 (+0000) Subject: Unify the implementation of getLValueIvar and getLValueField of store managers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c1511e04998e685c9e030323e248363b9633267d;p=clang Unify the implementation of getLValueIvar and getLValueField of store managers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95535 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Checker/PathSensitive/Store.h b/include/clang/Checker/PathSensitive/Store.h index 9a5ebf36d6..2ab09a197e 100644 --- a/include/clang/Checker/PathSensitive/Store.h +++ b/include/clang/Checker/PathSensitive/Store.h @@ -102,9 +102,13 @@ public: return loc::MemRegionVal(MRMgr.getCompoundLiteralRegion(CL, LC)); } - virtual SVal getLValueIvar(const ObjCIvarDecl* decl, SVal base) = 0; + virtual SVal getLValueIvar(const ObjCIvarDecl* decl, SVal base) { + return getLValueFieldOrIvar(decl, base); + } - virtual SVal getLValueField(const FieldDecl* D, SVal Base) = 0; + virtual SVal getLValueField(const FieldDecl* D, SVal Base) { + return getLValueFieldOrIvar(D, Base); + } virtual SVal getLValueElement(QualType elementType, SVal offset, SVal Base)=0; @@ -195,6 +199,9 @@ protected: /// as another region. SVal CastRetrievedVal(SVal val, const TypedRegion *R, QualType castTy, bool performTestOnly = true); + +private: + SVal getLValueFieldOrIvar(const Decl* D, SVal Base); }; // FIXME: Do we still need this? diff --git a/lib/Checker/BasicStore.cpp b/lib/Checker/BasicStore.cpp index 8d52bf53be..de9643e91e 100644 --- a/lib/Checker/BasicStore.cpp +++ b/lib/Checker/BasicStore.cpp @@ -70,8 +70,6 @@ public: return store; } - SVal getLValueIvar(const ObjCIvarDecl* D, SVal Base); - SVal getLValueField(const FieldDecl *D, SVal Base); SVal getLValueElement(QualType elementType, SVal Offset, SVal Base); /// ArrayToPointer - Used by GRExprEngine::VistCast to handle implicit @@ -113,52 +111,6 @@ StoreManager* clang::CreateBasicStoreManager(GRStateManager& StMgr) { return new BasicStoreManager(StMgr); } -SVal BasicStoreManager::getLValueIvar(const ObjCIvarDecl* D, SVal Base) { - - if (Base.isUnknownOrUndef()) - return Base; - - Loc BaseL = cast(Base); - - if (isa(BaseL)) { - const MemRegion *BaseR = cast(BaseL).getRegion(); - return ValMgr.makeLoc(MRMgr.getObjCIvarRegion(D, BaseR)); - } - - return UnknownVal(); -} - -SVal BasicStoreManager::getLValueField(const FieldDecl* D, SVal Base) { - - if (Base.isUnknownOrUndef()) - return Base; - - Loc BaseL = cast(Base); - const MemRegion* BaseR = 0; - - switch(BaseL.getSubKind()) { - case loc::GotoLabelKind: - return UndefinedVal(); - - case loc::MemRegionKind: - BaseR = cast(BaseL).getRegion(); - break; - - case loc::ConcreteIntKind: - // While these seem funny, this can happen through casts. - // FIXME: What we should return is the field offset. For example, - // add the field offset to the integer value. That way funny things - // like this work properly: &(((struct foo *) 0xa)->f) - return Base; - - default: - assert ("Unhandled Base."); - return Base; - } - - return ValMgr.makeLoc(MRMgr.getFieldRegion(D, BaseR)); -} - SVal BasicStoreManager::getLValueElement(QualType elementType, SVal Offset, SVal Base) { diff --git a/lib/Checker/FlatStore.cpp b/lib/Checker/FlatStore.cpp index fdeeab9529..f427ae1cec 100644 --- a/lib/Checker/FlatStore.cpp +++ b/lib/Checker/FlatStore.cpp @@ -42,13 +42,6 @@ public: return 0; } - SVal getLValueVar(const VarDecl *VD, const LocationContext *LC) { - return loc::MemRegionVal(MRMgr.getVarRegion(VD, LC)); - } - - SVal getLValueString(const StringLiteral* sl); - SVal getLValueIvar(const ObjCIvarDecl* decl, SVal base); - SVal getLValueField(const FieldDecl* D, SVal Base); SVal getLValueElement(QualType elementType, SVal offset, SVal Base); SVal ArrayToPointer(Loc Array); Store RemoveDeadBindings(Store store, Stmt* Loc, SymbolReaper& SymReaper, @@ -133,18 +126,6 @@ Store FlatStoreManager::BindCompoundLiteral(Store store, return store; } -SVal FlatStoreManager::getLValueString(const StringLiteral* sl) { - return UnknownVal(); -} - -SVal FlatStoreManager::getLValueIvar(const ObjCIvarDecl* decl, SVal base) { - return UnknownVal(); -} - -SVal FlatStoreManager::getLValueField(const FieldDecl* D, SVal Base) { - return UnknownVal(); -} - SVal FlatStoreManager::getLValueElement(QualType elementType, SVal offset, SVal Base) { return UnknownVal(); diff --git a/lib/Checker/RegionStore.cpp b/lib/Checker/RegionStore.cpp index 139ef6a7e2..1917e53e82 100644 --- a/lib/Checker/RegionStore.cpp +++ b/lib/Checker/RegionStore.cpp @@ -232,12 +232,6 @@ public: /// the value is not specified. Store setImplicitDefaultValue(Store store, const MemRegion *R, QualType T); - SVal getLValueIvar(const ObjCIvarDecl* D, SVal Base); - - SVal getLValueField(const FieldDecl* D, SVal Base); - - SVal getLValueFieldOrIvar(const Decl* D, SVal Base); - SVal getLValueElement(QualType elementType, SVal Offset, SVal Base); @@ -658,55 +652,6 @@ Store RegionStoreManager::InvalidateRegions(Store store, StateMgr.getValueManager()); } - -//===----------------------------------------------------------------------===// -// getLValueXXX methods. -//===----------------------------------------------------------------------===// - -SVal RegionStoreManager::getLValueIvar(const ObjCIvarDecl* D, SVal Base) { - return getLValueFieldOrIvar(D, Base); -} - -SVal RegionStoreManager::getLValueField(const FieldDecl* D, SVal Base) { - return getLValueFieldOrIvar(D, Base); -} - -SVal RegionStoreManager::getLValueFieldOrIvar(const Decl* D, SVal Base) { - if (Base.isUnknownOrUndef()) - return Base; - - Loc BaseL = cast(Base); - const MemRegion* BaseR = 0; - - switch (BaseL.getSubKind()) { - case loc::MemRegionKind: - BaseR = cast(BaseL).getRegion(); - break; - - case loc::GotoLabelKind: - // These are anormal cases. Flag an undefined value. - return UndefinedVal(); - - case loc::ConcreteIntKind: - // While these seem funny, this can happen through casts. - // FIXME: What we should return is the field offset. For example, - // add the field offset to the integer value. That way funny things - // like this work properly: &(((struct foo *) 0xa)->f) - return Base; - - default: - assert(0 && "Unhandled Base."); - return Base; - } - - // NOTE: We must have this check first because ObjCIvarDecl is a subclass - // of FieldDecl. - if (const ObjCIvarDecl *ID = dyn_cast(D)) - return loc::MemRegionVal(MRMgr.getObjCIvarRegion(ID, BaseR)); - - return loc::MemRegionVal(MRMgr.getFieldRegion(cast(D), BaseR)); -} - SVal RegionStoreManager::getLValueElement(QualType elementType, SVal Offset, SVal Base) { diff --git a/lib/Checker/Store.cpp b/lib/Checker/Store.cpp index 5a8f885332..7190bdabb6 100644 --- a/lib/Checker/Store.cpp +++ b/lib/Checker/Store.cpp @@ -234,3 +234,39 @@ Store StoreManager::InvalidateRegions(Store store, return store; } + +SVal StoreManager::getLValueFieldOrIvar(const Decl* D, SVal Base) { + if (Base.isUnknownOrUndef()) + return Base; + + Loc BaseL = cast(Base); + const MemRegion* BaseR = 0; + + switch (BaseL.getSubKind()) { + case loc::MemRegionKind: + BaseR = cast(BaseL).getRegion(); + break; + + case loc::GotoLabelKind: + // These are anormal cases. Flag an undefined value. + return UndefinedVal(); + + case loc::ConcreteIntKind: + // While these seem funny, this can happen through casts. + // FIXME: What we should return is the field offset. For example, + // add the field offset to the integer value. That way funny things + // like this work properly: &(((struct foo *) 0xa)->f) + return Base; + + default: + assert(0 && "Unhandled Base."); + return Base; + } + + // NOTE: We must have this check first because ObjCIvarDecl is a subclass + // of FieldDecl. + if (const ObjCIvarDecl *ID = dyn_cast(D)) + return loc::MemRegionVal(MRMgr.getObjCIvarRegion(ID, BaseR)); + + return loc::MemRegionVal(MRMgr.getFieldRegion(cast(D), BaseR)); +}