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"
41 class CallEventManager;
43 typedef std::unique_ptr<ConstraintManager>(*ConstraintManagerCreator)(
45 typedef std::unique_ptr<StoreManager>(*StoreManagerCreator)(
96 void setStore(
const StoreRef &storeRef);
136 ID.AddPointer(V->store);
187 std::pair<ProgramStateRef, ProgramStateRef>
202 const llvm::APSInt &From,
203 const llvm::APSInt &To,
204 bool assumption)
const;
211 std::pair<ProgramStateRef, ProgramStateRef>
213 const llvm::APSInt &To)
const;
230 SVal V,
bool Invalidate =
true)
const;
234 bool notifyChanges =
true)
const;
339 template <
typename CB> CB
366 void *
const*
FindGDM(
void *K)
const;
371 template <
typename T>
384 template <
typename T>
394 template <
typename T>
416 void print(raw_ostream &Out,
const char *nl =
"\n",
417 const char *sep =
"")
const;
418 void printDOT(raw_ostream &Out)
const;
419 void printTaint(raw_ostream &Out,
const char *nl =
"\n",
420 const char *sep =
"")
const;
433 const Expr *
E,
unsigned BlockCount,
435 bool ResultsInSymbolEscape,
453 std::unique_ptr<StoreManager> StoreMgr;
454 std::unique_ptr<ConstraintManager> ConstraintMgr;
456 ProgramState::GenericDataMap::Factory GDMFactory;
458 typedef llvm::DenseMap<void*,std::pair<void*,void (*)(void*)> > GDMContextsTy;
459 GDMContextsTy GDMContexts;
463 llvm::FoldingSet<ProgramState> StateSet;
466 std::unique_ptr<SValBuilder> svalBuilder;
469 std::unique_ptr<CallEventManager> CallEventMgr;
472 llvm::BumpPtrAllocator &Alloc;
475 std::vector<ProgramState *> freeStates;
481 llvm::BumpPtrAllocator& alloc,
492 return svalBuilder->getBasicValueFactory();
500 return svalBuilder->getSymbolManager();
503 return svalBuilder->getSymbolManager();
509 return svalBuilder->getRegionManager();
512 return svalBuilder->getRegionManager();
528 return StoreMgr->ArrayToPointer(Array, ElementTy);
538 StoreMgr->iterBindings(state->getStore(), F);
546 return S1->Env == S2->Env;
550 return S1->store == S2->store;
572 template <
typename T>
588 template <
typename T>
596 template <
typename T>
605 template <
typename T>
611 void *(*CreateContext)(llvm::BumpPtrAllocator&),
612 void (*DeleteContext)(
void*));
614 template <
typename T>
624 ConstraintMgr->EndPath(St);
644 bool Assumption)
const {
652 inline std::pair<ProgramStateRef , ProgramStateRef >
655 return std::make_pair(
this,
this);
663 const llvm::APSInt &From,
664 const llvm::APSInt &To,
665 bool Assumption)
const {
669 assert(Val.
getAs<
NonLoc>() &&
"Only NonLocs are supported!");
675 inline std::pair<ProgramStateRef, ProgramStateRef>
677 const llvm::APSInt &From,
678 const llvm::APSInt &To)
const {
680 return std::make_pair(
this,
this);
682 assert(Val.
getAs<
NonLoc>() &&
"Only NonLocs are supported!");
685 ->assumeWithinInclusiveRangeDual(
this, Val.
castAs<
NonLoc>(), From, To);
701 return getStateManager().StoreMgr->getLValueCompoundLiteral(literal, LC);
715 for (
const auto *
I : D->
chain()) {
724 return getStateManager().StoreMgr->getLValueElement(ElementType, *N, Base);
737 if (
const Expr *Ex = dyn_cast<Expr>(S)) {
769 template <
typename T>
785 template <
typename T>
808 template <
typename CB>
815 template <
typename CB>
822 template <
typename CB>
841 : state(std::move(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
enterStackFrame - Returns the state for entry to the given stack frame, preserving the current state...
A (possibly-)qualified type.
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.
Manages the lifetime of CallEvent objects.
Store getStore() const
Return the store associated with this state.
llvm::ImmutableSet< llvm::APSInt * > IntSetTy
const MemRegionManager & getRegionManager() const
ProgramStateRef assumeWithinInclusiveRange(DefinedOrUnknownSVal Val, const llvm::APSInt &From, const llvm::APSInt &To, bool assumption) const
Assumes that the value of Val is bounded with [From; To] (if assumption is "true") or it is fully out...
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
ProgramStateRef add(typename ProgramStateTrait< T >::key_type K) const
A Utility class that allows to visit the reachable symbols using a custom SymbolVisitor.
bool haveEqualEnvironments(ProgramStateRef S1, ProgramStateRef S2)
VarDecl - An instance of this class is created to represent a variable declaration or definition...
CompoundLiteralExpr - [C99 6.5.2.5].
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.
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.
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
MemRegionManager & getRegionManager()
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
SubEngine * getOwningEngine()
SVal getSVal(const EnvironmentEntry &E, SValBuilder &svalBuilder) const
Fetches the current binding of the expression in the Environment.
GenericDataMap getGDM() const
getGDM - Return the generic data map associated with this state.
SValBuilder & getSValBuilder()
void EndPath(ProgramStateRef St)
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
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)
detail::InMemoryDirectory::const_iterator I
SVal getSValAsScalarOrLoc(const Stmt *Ex, const LocationContext *LCtx) const
llvm::ImmutableMap< void *, void * > GenericDataMap
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.
ProgramState - This class encapsulates:
Expr - This represents one expression.
ArrayRef< NamedDecl * > chain() const
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
Create a new state by binding the value 'V' to the statement 'S' in the state's environment.
ProgramStateRef removeGDM(ProgramStateRef state, void *Key)
void Profile(llvm::FoldingSetNodeID &ID) const
Profile - Used to profile the contents of this object for inclusion in a FoldingSet.
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)
Profile - Profile the contents of an Environment object for use in a FoldingSet.
ProgramStateRef assume(DefinedOrUnknownSVal cond, bool assumption) const
Assumes that the value of cond is zero (if assumption is "false") or non-zero (if assumption is "true...
CallEventManager & getCallEventManager()
ProgramStateRef assumeInBound(DefinedOrUnknownSVal idx, DefinedOrUnknownSVal upperBound, bool assumption, QualType IndexType=QualType()) const
An entry in the environment consists of a Stmt and an LocationContext.
bool contains(typename ProgramStateTrait< T >::key_type key) const
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
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
getEnvironment - Return the environment associated with this state.
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)
const VarRegion * getVarRegion(const VarDecl *D, const LocationContext *LC)
getVarRegion - Retrieve or create the memory region associated with a specified VarDecl and LocationC...
IndirectFieldDecl - An instance of this class is created to represent a field injected from an anonym...
detail::InMemoryDirectory::const_iterator E
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
ObjCIvarDecl - Represents an ObjC instance variable.
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)
Profile - Profile the contents of a ProgramState object for use in a FoldingSet.
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 &)