14 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATE_H
15 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATE_H
25 #include "llvm/ADT/FoldingSet.h"
26 #include "llvm/ADT/ImmutableMap.h"
27 #include "llvm/ADT/PointerIntPair.h"
28 #include "llvm/Support/Allocator.h"
40 class CallEventManager;
42 typedef std::unique_ptr<ConstraintManager>(*ConstraintManagerCreator)(
44 typedef std::unique_ptr<StoreManager>(*StoreManagerCreator)(
95 void setStore(
const StoreRef &storeRef);
135 ID.AddPointer(V->store);
186 std::pair<ProgramStateRef, ProgramStateRef>
208 SVal V,
bool Invalidate =
true)
const;
212 bool notifyChanges =
true)
const;
315 const SVal *end)
const;
317 template <
typename CB> CB
350 bool CanBeSubClassed =
true)
const {
358 void *
const*
FindGDM(
void *K)
const;
363 template <
typename T>
376 template <
typename T>
386 template <
typename T>
408 void print(raw_ostream &Out,
const char *nl =
"\n",
409 const char *sep =
"")
const;
410 void printDOT(raw_ostream &Out)
const;
411 void printTaint(raw_ostream &Out,
const char *nl =
"\n",
412 const char *sep =
"")
const;
425 const Expr *E,
unsigned BlockCount,
427 bool ResultsInSymbolEscape,
445 std::unique_ptr<StoreManager> StoreMgr;
446 std::unique_ptr<ConstraintManager> ConstraintMgr;
448 ProgramState::GenericDataMap::Factory GDMFactory;
450 typedef llvm::DenseMap<void*,std::pair<void*,void (*)(void*)> > GDMContextsTy;
451 GDMContextsTy GDMContexts;
455 llvm::FoldingSet<ProgramState> StateSet;
458 std::unique_ptr<SValBuilder> svalBuilder;
461 std::unique_ptr<CallEventManager> CallEventMgr;
464 llvm::BumpPtrAllocator &Alloc;
467 std::vector<ProgramState *> freeStates;
473 llvm::BumpPtrAllocator& alloc,
484 return svalBuilder->getBasicValueFactory();
492 return svalBuilder->getSymbolManager();
495 return svalBuilder->getSymbolManager();
501 return svalBuilder->getRegionManager();
504 return svalBuilder->getRegionManager();
520 return StoreMgr->ArrayToPointer(Array, ElementTy);
530 StoreMgr->iterBindings(state->getStore(), F);
538 return S1->Env == S2->Env;
542 return S1->store == S2->store;
564 template <
typename T>
580 template <
typename T>
588 template <
typename T>
597 template <
typename T>
603 void *(*CreateContext)(llvm::BumpPtrAllocator&),
604 void (*DeleteContext)(
void*));
606 template <
typename T>
616 ConstraintMgr->EndPath(St);
636 bool Assumption)
const {
644 inline std::pair<ProgramStateRef , ProgramStateRef >
647 return std::make_pair(
this,
this);
666 return getStateManager().StoreMgr->getLValueCompoundLiteral(literal, LC);
680 for (
const auto *I : D->
chain()) {
689 return getStateManager().StoreMgr->getLValueElement(ElementType, *N, Base);
702 if (
const Expr *Ex = dyn_cast<Expr>(S)) {
734 template <
typename T>
750 template <
typename T>
773 template <
typename CB>
780 template <
typename CB>
787 template <
typename CB>
807 : state(st), visitor(v) {}
ProgramStateRef addGDM(ProgramStateRef St, void *Key, void *Data)
ProgramStateManager & getStateManager() const
Return the ProgramStateManager associated with this state.
ProgramStateRef enterStackFrame(const CallEvent &Call, const StackFrameContext *CalleeCtx) const
MemRegion - The root abstract class for all memory regions.
Information about invalidation for a particular region/symbol.
BasicValueFactory & getBasicVals()
bool haveEqualStores(ProgramStateRef S1, ProgramStateRef S2)
SVal getRawSVal(Loc LV, QualType T=QualType()) const
Returns the "raw" SVal bound to LV before any value simplfication.
ProgramStateRef addTaint(const Stmt *S, const LocationContext *LCtx, TaintTagType Kind=TaintTagGeneric) const
Create a new state in which the statement is marked as tainted.
chain_range chain() const
Manages the lifetime of CallEvent objects.
llvm::ImmutableSet< llvm::APSInt * > IntSetTy
const MemRegionManager & getRegionManager() const
ProgramStateRef add(typename ProgramStateTrait< T >::key_type K) const
bool haveEqualEnvironments(ProgramStateRef S1, ProgramStateRef S2)
std::unique_ptr< ConstraintManager >(* ConstraintManagerCreator)(ProgramStateManager &, SubEngine *)
ProgramStateRef removeDeadBindings(ProgramStateRef St, const StackFrameContext *LCtx, SymbolReaper &SymReaper)
const SymbolManager & getSymbolManager() const
bool isTainted(const Stmt *S, const LocationContext *LCtx, TaintTagType Kind=TaintTagGeneric) const
Check if the statement is tainted in the current state.
Symbolic value. These values used to capture symbolic execution of the program.
ProgramStateRef add(ProgramStateRef st, typename ProgramStateTrait< T >::key_type K, typename ProgramStateTrait< T >::context_type C)
ProgramStateRef remove() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
friend void ProgramStateRelease(const ProgramState *state)
Decrement the number of times this state is referenced.
MemRegionManager & getRegionManager()
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
SubEngine * getOwningEngine()
SVal getSVal(const EnvironmentEntry &E, SValBuilder &svalBuilder) const
GenericDataMap getGDM() const
getGDM - Return the generic data map associated with this state.
SValBuilder & getSValBuilder()
void EndPath(ProgramStateRef St)
static bool isLocType(QualType T)
void *const * FindGDM(void *K) const
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
virtual SVal getLValueField(const FieldDecl *D, SVal Base)
ProgramStateRef setDynamicTypeInfo(const MemRegion *Reg, QualType NewTy, bool CanBeSubClassed=true) const
Set dynamic type information of the region; return the new state.
SVal getSValAsScalarOrLoc(const Stmt *Ex, const LocationContext *LCtx) const
llvm::ImmutableMap< void *, void * > GenericDataMap
ID
Defines the set of possible language-specific address spaces.
ProgramStateRef invalidateRegions(ArrayRef< const MemRegion * > Regions, const Expr *E, unsigned BlockCount, const LocationContext *LCtx, bool CausesPointerEscape, InvalidatedSymbols *IS=nullptr, const CallEvent *Call=nullptr, RegionAndSymbolInvalidationTraits *ITraits=nullptr) const
Returns the state with bindings for the given regions cleared from the store.
Stores the currently inferred strictest bound on the runtime type of a region in a given state along ...
ProgramStateRef setDynamicTypeInfo(const MemRegion *Reg, DynamicTypeInfo NewTy) const
Set dynamic type information of the region; return the new state.
SVal getSVal(const Stmt *S, const LocationContext *LCtx) const
Returns the SVal bound to the statement 'S' in the state's environment.
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
ProgramStateRef remove(ProgramStateRef st, typename ProgramStateTrait< T >::key_type K, typename ProgramStateTrait< T >::context_type C)
ProgramStateRef bindLoc(Loc location, SVal V, bool notifyChanges=true) const
StoreManager & getStoreManager()
ProgramStateRef BindExpr(const Stmt *S, const LocationContext *LCtx, SVal V, bool Invalidate=true) const
ProgramStateRef removeGDM(ProgramStateRef state, void *Key)
void Profile(llvm::FoldingSetNodeID &ID) const
bool scan(nonloc::LazyCompoundVal val)
llvm::BumpPtrAllocator & getAllocator()
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
ProgramStateRef getInitialState(const LocationContext *InitLoc)
ProgramStateRef set(typename ProgramStateTrait< T >::data_type D) const
static void Profile(llvm::FoldingSetNodeID &ID, const Environment *env)
ProgramStateRef assume(DefinedOrUnknownSVal cond, bool assumption) const
CallEventManager & getCallEventManager()
ProgramStateRef assumeInBound(DefinedOrUnknownSVal idx, DefinedOrUnknownSVal upperBound, bool assumption, QualType IndexType=QualType()) const
bool contains(typename ProgramStateTrait< T >::key_type key) const
ProgramStateTrait< T >::context_type get_context()
static const TaintTagType TaintTagGeneric
A class responsible for cleaning up unused symbols.
friend void ProgramStateRelease(const ProgramState *state)
Decrement the number of times this state is referenced.
const VarRegion * getRegion(const VarDecl *D, const LocationContext *LC) const
Utility method for getting regions.
ScanReachableSymbols(ProgramStateRef st, SymbolVisitor &v)
static void * MakeVoidPtr(data_type D)
ConditionTruthVal isNull(SVal V) const
Check if the given SVal is constrained to zero or is a zero constant.
void printDOT(raw_ostream &Out) const
ProgramStateRef getPersistentStateWithGDM(ProgramStateRef FromState, ProgramStateRef GDMState)
SymbolManager & getSymbolManager()
An immutable map from EnvironemntEntries to SVals.
const Environment & getEnvironment() const
SVal ArrayToPointer(Loc Array, QualType ElementTy)
friend void ProgramStateRetain(const ProgramState *state)
Increments the number of times this state is referenced.
static data_type MakeData(void *const *P)
static __inline__ uint32_t volatile uint32_t * p
const VarRegion * getVarRegion(const VarDecl *D, const LocationContext *LC)
DynamicTypeInfo getDynamicTypeInfo(const MemRegion *Reg) const
Get dynamic type information for a region.
ProgramStateRef killBinding(Loc LV) const
Represents an abstract call to a function or method along a particular path.
ASTContext & getContext()
ConstraintManager & getConstraintManager()
ProgramStateRef set(ProgramStateRef st, typename ProgramStateTrait< T >::data_type D)
ProgramState(ProgramStateManager *mgr, const Environment &env, StoreRef st, GenericDataMap gdm)
This ctor is used when creating the first ProgramState object.
ProgramStateRef bindDefault(SVal loc, SVal V) const
ProgramStateManager(ASTContext &Ctx, StoreManagerCreator CreateStoreManager, ConstraintManagerCreator CreateConstraintManager, llvm::BumpPtrAllocator &alloc, SubEngine *subeng)
void print(raw_ostream &Out, const char *nl="\n", const char *sep="") const
ConstraintManager & getConstraintManager() const
Return the ConstraintManager.
void * FindGDMContext(void *index, void *(*CreateContext)(llvm::BumpPtrAllocator &), void(*DeleteContext)(void *))
Loc getLValue(const VarDecl *D, const LocationContext *LC) const
Get the lvalue for a variable reference.
static void Profile(llvm::FoldingSetNodeID &ID, const ProgramState *V)
void iterBindings(ProgramStateRef state, StoreManager::BindingsHandler &F)
ProgramStateRef getPersistentState(ProgramState &Impl)
ProgramStateTrait< T >::context_type get_context() const
const ASTContext & getContext() const
BasicValueFactory & getBasicVals() const
void setGDM(GenericDataMap gdm)
ProgramStateRef set(ProgramStateRef st, typename ProgramStateTrait< T >::key_type K, typename ProgramStateTrait< T >::value_type V, typename ProgramStateTrait< T >::context_type C)
SymbolManager & getSymbolManager() const
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
void printTaint(raw_ostream &Out, const char *nl="\n", const char *sep="") const
bool scanReachableSymbols(SVal val, SymbolVisitor &visitor) const
Visits the symbols reachable from the given SVal using the provided SymbolVisitor.
std::unique_ptr< StoreManager >(* StoreManagerCreator)(ProgramStateManager &)