clang  6.0.0svn
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
clang::ento::StoreManager Class Referenceabstract

#include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"

Collaboration diagram for clang::ento::StoreManager:
Collaboration graph
[legend]

Classes

class  BindingsHandler
 
class  FindUniqueBinding
 

Public Types

typedef SmallVector< const MemRegion *, 8 > InvalidatedRegions
 

Public Member Functions

virtual ~StoreManager ()
 
virtual SVal getBinding (Store store, Loc loc, QualType T=QualType())=0
 Return the value bound to specified location in a given state. More...
 
virtual Optional< SValgetDefaultBinding (Store store, const MemRegion *R)=0
 Return the default value bound to a region in a given store. More...
 
Optional< SValgetDefaultBinding (nonloc::LazyCompoundVal lcv)
 Return the default value bound to a LazyCompoundVal. More...
 
virtual StoreRef Bind (Store store, Loc loc, SVal val)=0
 Return a store with the specified value bound to the given location. More...
 
virtual StoreRef BindDefault (Store store, const MemRegion *R, SVal V)
 
virtual StoreRef killBinding (Store ST, Loc L)=0
 Create a new store with the specified binding removed. More...
 
virtual StoreRef getInitialStore (const LocationContext *InitLoc)=0
 getInitialStore - Returns the initial "empty" store representing the value bindings upon entry to an analyzed function. More...
 
MemRegionManagergetRegionManager ()
 getRegionManager - Returns the internal RegionManager object that is used to query and manipulate MemRegion objects. More...
 
virtual Loc getLValueVar (const VarDecl *VD, const LocationContext *LC)
 
Loc getLValueCompoundLiteral (const CompoundLiteralExpr *CL, const LocationContext *LC)
 
virtual SVal getLValueIvar (const ObjCIvarDecl *decl, SVal base)
 
virtual SVal getLValueField (const FieldDecl *D, SVal Base)
 
virtual SVal getLValueElement (QualType elementType, NonLoc offset, SVal Base)
 
virtual DefinedOrUnknownSVal getSizeInElements (ProgramStateRef state, const MemRegion *region, QualType EleTy)
 
virtual SVal ArrayToPointer (Loc Array, QualType ElementTy)=0
 ArrayToPointer - Used by ExprEngine::VistCast to handle implicit conversions between arrays and pointers. More...
 
SVal evalDerivedToBase (SVal Derived, const CastExpr *Cast)
 Evaluates a chain of derived-to-base casts through the path specified in Cast. More...
 
SVal evalDerivedToBase (SVal Derived, const CXXBasePath &CastPath)
 Evaluates a chain of derived-to-base casts through the specified path. More...
 
SVal evalDerivedToBase (SVal Derived, QualType DerivedPtrType, bool IsVirtual)
 Evaluates a derived-to-base cast through a single level of derivation. More...
 
SVal attemptDownCast (SVal Base, QualType DerivedPtrType, bool &Failed)
 Attempts to do a down cast. More...
 
const ElementRegionGetElementZeroRegion (const SubRegion *R, QualType T)
 
const MemRegioncastRegion (const MemRegion *region, QualType CastToTy)
 castRegion - Used by ExprEngine::VisitCast to handle casts from a MemRegion* to a specific location type. More...
 
virtual StoreRef removeDeadBindings (Store store, const StackFrameContext *LCtx, SymbolReaper &SymReaper)=0
 
virtual bool includedInBindings (Store store, const MemRegion *region) const =0
 
virtual void incrementReferenceCount (Store store)
 If the StoreManager supports it, increment the reference count of the specified Store object. More...
 
virtual void decrementReferenceCount (Store store)
 If the StoreManager supports it, decrement the reference count of the specified Store object. More...
 
virtual StoreRef invalidateRegions (Store store, ArrayRef< SVal > Values, const Expr *E, unsigned Count, const LocationContext *LCtx, const CallEvent *Call, InvalidatedSymbols &IS, RegionAndSymbolInvalidationTraits &ITraits, InvalidatedRegions *InvalidatedTopLevel, InvalidatedRegions *Invalidated)=0
 invalidateRegions - Clears out the specified regions from the store, marking their values as unknown. More...
 
StoreRef enterStackFrame (Store store, const CallEvent &Call, const StackFrameContext *CalleeCtx)
 enterStackFrame - Let the StoreManager to do something when execution engine is about to execute into a callee. More...
 
virtual bool scanReachableSymbols (Store S, const MemRegion *R, ScanReachableSymbols &Visitor)=0
 Finds the transitive closure of symbols within the given region. More...
 
virtual void print (Store store, raw_ostream &Out, const char *nl, const char *sep)=0
 
virtual void iterBindings (Store store, BindingsHandler &f)=0
 iterBindings - Iterate over the bindings in the Store. More...
 

Protected Member Functions

 StoreManager (ProgramStateManager &stateMgr)
 
const ElementRegionMakeElementRegion (const SubRegion *baseRegion, QualType pointeeTy, uint64_t index=0)
 
SVal CastRetrievedVal (SVal val, const TypedValueRegion *region, QualType castTy, bool performTestOnly=true)
 CastRetrievedVal - Used by subclasses of StoreManager to implement implicit casts that arise from loads from regions that are reinterpreted as another region. More...
 

Protected Attributes

SValBuildersvalBuilder
 
ProgramStateManagerStateMgr
 
MemRegionManagerMRMgr
 MRMgr - Manages region objects associated with this StoreManager. More...
 
ASTContextCtx
 

Detailed Description

Definition at line 39 of file Store.h.

Member Typedef Documentation

◆ InvalidatedRegions

Definition at line 185 of file Store.h.

Constructor & Destructor Documentation

◆ StoreManager()

StoreManager::StoreManager ( ProgramStateManager stateMgr)
protected

Definition at line 24 of file Store.cpp.

◆ ~StoreManager()

virtual clang::ento::StoreManager::~StoreManager ( )
inlinevirtual

Definition at line 51 of file Store.h.

References getBinding(), getDefaultBinding(), and clang::T.

Member Function Documentation

◆ ArrayToPointer()

virtual SVal clang::ento::StoreManager::ArrayToPointer ( Loc  Array,
QualType  ElementTy 
)
pure virtual

ArrayToPointer - Used by ExprEngine::VistCast to handle implicit conversions between arrays and pointers.

Referenced by getSizeInElements().

◆ attemptDownCast()

SVal StoreManager::attemptDownCast ( SVal  Base,
QualType  DerivedPtrType,
bool Failed 
)

Attempts to do a down cast.

Used to model BaseToDerived and C++ dynamic_cast. The callback may result in the following 3 scenarios:

  • Successful cast (ex: derived is subclass of base).
  • Failed cast (ex: derived is definitely not a subclass of base). The distinction of this case from the next one is necessary to model dynamic_cast.
  • We don't know (base is a symbolic region and we don't have enough info to determine if the cast will succeed at run time). The function returns an SVal representing the derived class; it's valid only if Failed flag is set to false.

Definition at line 296 of file Store.cpp.

References evalDerivedToBase(), clang::CXXBasePaths::front(), clang::Type::getAsCXXRecordDecl(), clang::ento::SVal::getAsRegion(), getCXXRecordType(), clang::Type::getPointeeType(), clang::QualType::isNull(), clang::Type::isVoidType(), and clang::ento::MemRegion::StripCasts().

Referenced by clang::CXXInstanceCall::getInitialStackFrameContents(), and getSizeInElements().

◆ Bind()

virtual StoreRef clang::ento::StoreManager::Bind ( Store  store,
Loc  loc,
SVal  val 
)
pure virtual

Return a store with the specified value bound to the given location.

Parameters
[in]storeThe store in which to make the binding.
[in]locThe symbolic memory location.
[in]valThe value to bind to location loc.
Returns
A StoreRef object that contains the same bindings as store with the addition of having the value specified by val bound to the location given for loc.

Referenced by getDefaultBinding().

◆ BindDefault()

StoreRef StoreManager::BindDefault ( Store  store,
const MemRegion R,
SVal  V 
)
virtual

Definition at line 52 of file Store.cpp.

Referenced by getDefaultBinding().

◆ castRegion()

const MemRegion * StoreManager::castRegion ( const MemRegion region,
QualType  CastToTy 
)

◆ CastRetrievedVal()

SVal StoreManager::CastRetrievedVal ( SVal  V,
const TypedValueRegion R,
QualType  castTy,
bool  performTestOnly = true 
)
protected

◆ decrementReferenceCount()

virtual void clang::ento::StoreManager::decrementReferenceCount ( Store  store)
inlinevirtual

If the StoreManager supports it, decrement the reference count of the specified Store object.

If the reference count hits 0, the memory associated with the object is recycled.

Definition at line 183 of file Store.h.

Referenced by clang::ento::StoreRef::operator=(), clang::ento::ProgramState::~ProgramState(), and clang::ento::StoreRef::~StoreRef().

◆ enterStackFrame()

StoreRef StoreManager::enterStackFrame ( Store  store,
const CallEvent Call,
const StackFrameContext CalleeCtx 
)

enterStackFrame - Let the StoreManager to do something when execution engine is about to execute into a callee.

Definition at line 28 of file Store.cpp.

References clang::ento::CallEvent::getInitialStackFrameContents().

◆ evalDerivedToBase() [1/3]

SVal StoreManager::evalDerivedToBase ( SVal  Derived,
const CastExpr Cast 
)

Evaluates a chain of derived-to-base casts through the path specified in Cast.

Definition at line 237 of file Store.cpp.

References clang::CastExpr::getSubExpr(), clang::Expr::getType(), and regionMatchesCXXRecordType().

Referenced by adjustReturnValue(), attemptDownCast(), getSizeInElements(), clang::ento::ExprEngine::ProcessBaseDtor(), and clang::ento::ExprEngine::VisitCXXConstructExpr().

◆ evalDerivedToBase() [2/3]

SVal StoreManager::evalDerivedToBase ( SVal  Derived,
const CXXBasePath CastPath 
)

Evaluates a chain of derived-to-base casts through the specified path.

Definition at line 253 of file Store.cpp.

◆ evalDerivedToBase() [3/3]

SVal StoreManager::evalDerivedToBase ( SVal  Derived,
QualType  DerivedPtrType,
bool  IsVirtual 
)

Evaluates a derived-to-base cast through a single level of derivation.

Definition at line 264 of file Store.cpp.

References clang::ento::SVal::getAs(), clang::Type::getAsCXXRecordDecl(), clang::ento::MemRegionManager::getCXXBaseObjectRegion(), clang::Type::getPointeeCXXRecordDecl(), and MRMgr.

◆ getBinding()

virtual SVal clang::ento::StoreManager::getBinding ( Store  store,
Loc  loc,
QualType  T = QualType() 
)
pure virtual

Return the value bound to specified location in a given state.

Parameters
[in]storeThe store in which to make the lookup.
[in]locThe symbolic memory location.
[in]TAn optional type that provides a hint indicating the expected type of the returned value. This is used if the value is lazily computed.
Returns
The value bound to the location loc.

Referenced by evalComparison(), getAsPointeeSymbol(), and ~StoreManager().

◆ getDefaultBinding() [1/2]

virtual Optional<SVal> clang::ento::StoreManager::getDefaultBinding ( Store  store,
const MemRegion R 
)
pure virtual

Return the default value bound to a region in a given store.

The default binding is the value of sub-regions that were not initialized separately from their base region. For example, if the structure is zero-initialized upon construction, this method retrieves the concrete zero value, even if some or all fields were later overwritten manually. Default binding may be an unknown, undefined, concrete, or symbolic value.

Parameters
[in]storeThe store in which to make the lookup.
[in]RThe region to find the default binding for.
Returns
The default value bound to the region in the store, if a default binding exists.

Referenced by getDefaultBinding(), and ~StoreManager().

◆ getDefaultBinding() [2/2]

Optional<SVal> clang::ento::StoreManager::getDefaultBinding ( nonloc::LazyCompoundVal  lcv)
inline

Return the default value bound to a LazyCompoundVal.

The default binding is used to represent the value of any fields or elements within the structure represented by the LazyCompoundVal which were not initialized explicitly separately from the whole structure. Default binding may be an unknown, undefined, concrete, or symbolic value.

Parameters
[in]lcvThe lazy compound value.
Returns
The default value bound to the LazyCompoundVal lcv, if a default binding exists.

Definition at line 82 of file Store.h.

References Bind(), BindDefault(), getDefaultBinding(), getInitialStore(), clang::ento::nonloc::LazyCompoundVal::getRegion(), clang::ento::nonloc::LazyCompoundVal::getStore(), and killBinding().

◆ GetElementZeroRegion()

const ElementRegion * StoreManager::GetElementZeroRegion ( const SubRegion R,
QualType  T 
)

◆ getInitialStore()

virtual StoreRef clang::ento::StoreManager::getInitialStore ( const LocationContext InitLoc)
pure virtual

getInitialStore - Returns the initial "empty" store representing the value bindings upon entry to an analyzed function.

Referenced by getDefaultBinding().

◆ getLValueCompoundLiteral()

Loc clang::ento::StoreManager::getLValueCompoundLiteral ( const CompoundLiteralExpr CL,
const LocationContext LC 
)
inline

◆ getLValueElement()

SVal StoreManager::getLValueElement ( QualType  elementType,
NonLoc  offset,
SVal  Base 
)
virtual

◆ getLValueField()

virtual SVal clang::ento::StoreManager::getLValueField ( const FieldDecl D,
SVal  Base 
)
inlinevirtual

Definition at line 121 of file Store.h.

References getLValueElement().

◆ getLValueIvar()

SVal StoreManager::getLValueIvar ( const ObjCIvarDecl decl,
SVal  base 
)
virtual

Definition at line 430 of file Store.cpp.

Referenced by getLValueCompoundLiteral().

◆ getLValueVar()

virtual Loc clang::ento::StoreManager::getLValueVar ( const VarDecl VD,
const LocationContext LC 
)
inlinevirtual

◆ getRegionManager()

MemRegionManager& clang::ento::StoreManager::getRegionManager ( )
inline

getRegionManager - Returns the internal RegionManager object that is used to query and manipulate MemRegion objects.

Definition at line 108 of file Store.h.

References MRMgr.

◆ getSizeInElements()

virtual DefinedOrUnknownSVal clang::ento::StoreManager::getSizeInElements ( ProgramStateRef  state,
const MemRegion region,
QualType  EleTy 
)
inlinevirtual

◆ includedInBindings()

virtual bool clang::ento::StoreManager::includedInBindings ( Store  store,
const MemRegion region 
) const
pure virtual

Referenced by getSizeInElements().

◆ incrementReferenceCount()

virtual void clang::ento::StoreManager::incrementReferenceCount ( Store  store)
inlinevirtual

If the StoreManager supports it, increment the reference count of the specified Store object.

Definition at line 178 of file Store.h.

Referenced by clang::ento::StoreRef::operator=(), clang::ento::ProgramState::ProgramState(), and clang::ento::StoreRef::StoreRef().

◆ invalidateRegions()

virtual StoreRef clang::ento::StoreManager::invalidateRegions ( Store  store,
ArrayRef< SVal Values,
const Expr E,
unsigned  Count,
const LocationContext LCtx,
const CallEvent Call,
InvalidatedSymbols IS,
RegionAndSymbolInvalidationTraits ITraits,
InvalidatedRegions InvalidatedTopLevel,
InvalidatedRegions Invalidated 
)
pure virtual

invalidateRegions - Clears out the specified regions from the store, marking their values as unknown.

Depending on the store, this may also invalidate additional regions that may have changed based on accessing the given regions. Optionally, invalidates non-static globals as well.

Parameters
[in]storeThe initial store
[in]ValuesThe values to invalidate.
[in]EThe current statement being evaluated. Used to conjure symbols to mark the values of invalidated regions.
[in]CountThe current block count. Used to conjure symbols to mark the values of invalidated regions.
[in]CallThe call expression which will be used to determine which globals should get invalidated.
[in,out]ISA set to fill with any symbols that are no longer accessible. Pass NULL if this information will not be used.
[in]ITraitsInformation about invalidation for a particular region/symbol.
[in,out]InvalidatedTopLevelA vector to fill with regions explicitly being invalidated. Pass NULL if this information will not be used.
[in,out]InvalidatedA vector to fill with any regions being invalidated. This should include any regions explicitly invalidated even if they do not currently have bindings. Pass NULL if this information will not be used.

◆ iterBindings()

virtual void clang::ento::StoreManager::iterBindings ( Store  store,
BindingsHandler f 
)
pure virtual

iterBindings - Iterate over the bindings in the Store.

Referenced by clang::ento::StoreManager::FindUniqueBinding::getRegion().

◆ killBinding()

virtual StoreRef clang::ento::StoreManager::killBinding ( Store  ST,
Loc  L 
)
pure virtual

Create a new store with the specified binding removed.

Parameters
STthe original store, that is the basis for the new store.
Lthe location whose binding should be removed.

Referenced by getDefaultBinding().

◆ MakeElementRegion()

const ElementRegion * StoreManager::MakeElementRegion ( const SubRegion baseRegion,
QualType  pointeeTy,
uint64_t  index = 0 
)
protected

◆ print()

virtual void clang::ento::StoreManager::print ( Store  store,
raw_ostream &  Out,
const char *  nl,
const char *  sep 
)
pure virtual

◆ removeDeadBindings()

virtual StoreRef clang::ento::StoreManager::removeDeadBindings ( Store  store,
const StackFrameContext LCtx,
SymbolReaper SymReaper 
)
pure virtual

Referenced by getSizeInElements().

◆ scanReachableSymbols()

virtual bool clang::ento::StoreManager::scanReachableSymbols ( Store  S,
const MemRegion R,
ScanReachableSymbols Visitor 
)
pure virtual

Finds the transitive closure of symbols within the given region.

Returns false if the visitor aborted the scan.

Referenced by clang::ento::ScanReachableSymbols::scan().

Member Data Documentation

◆ Ctx

ASTContext& clang::ento::StoreManager::Ctx
protected

Definition at line 46 of file Store.h.

Referenced by castRegion(), CastRetrievedVal(), GetElementZeroRegion(), and getLValueElement().

◆ MRMgr

MemRegionManager& clang::ento::StoreManager::MRMgr
protected

MRMgr - Manages region objects associated with this StoreManager.

Definition at line 45 of file Store.h.

Referenced by CastRetrievedVal(), evalDerivedToBase(), GetElementZeroRegion(), getLValueElement(), getRegionManager(), and MakeElementRegion().

◆ StateMgr

ProgramStateManager& clang::ento::StoreManager::StateMgr
protected

Definition at line 42 of file Store.h.

Referenced by castRegion().

◆ svalBuilder

SValBuilder& clang::ento::StoreManager::svalBuilder
protected

The documentation for this class was generated from the following files: