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/Support/Allocator.h"
40 class CallEventManager;
42 typedef std::unique_ptr<ConstraintManager>(*ConstraintManagerCreator)(
44 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;
229 SVal V,
bool Invalidate =
true)
const;
234 bool notifyChanges =
true)
const;
337 const SVal *end)
const;
339 template <
typename CB> CB
377 void *
const*
FindGDM(
void *K)
const;
382 template <
typename T>
395 template <
typename T>
405 template <
typename T>
427 void print(raw_ostream &Out,
const char *nl =
"\n",
428 const char *sep =
"")
const;
429 void printDOT(raw_ostream &Out)
const;
430 void printTaint(raw_ostream &Out,
const char *nl =
"\n",
431 const char *sep =
"")
const;
444 const Expr *
E,
unsigned BlockCount,
446 bool ResultsInSymbolEscape,
464 std::unique_ptr<StoreManager> StoreMgr;
465 std::unique_ptr<ConstraintManager> ConstraintMgr;
467 ProgramState::GenericDataMap::Factory GDMFactory;
468 TaintedSubRegions::Factory TSRFactory;
470 typedef llvm::DenseMap<void*,std::pair<void*,void (*)(void*)> > GDMContextsTy;
471 GDMContextsTy GDMContexts;
475 llvm::FoldingSet<ProgramState> StateSet;
478 std::unique_ptr<SValBuilder> svalBuilder;
481 std::unique_ptr<CallEventManager> CallEventMgr;
484 llvm::BumpPtrAllocator &Alloc;
487 std::vector<ProgramState *> freeStates;
493 llvm::BumpPtrAllocator& alloc,
504 return svalBuilder->getBasicValueFactory();
512 return svalBuilder->getSymbolManager();
515 return svalBuilder->getSymbolManager();
521 return svalBuilder->getRegionManager();
524 return svalBuilder->getRegionManager();
540 return StoreMgr->ArrayToPointer(Array, ElementTy);
550 StoreMgr->iterBindings(state->getStore(), F);
558 return S1->Env == S2->Env;
562 return S1->store == S2->store;
584 template <
typename T>
600 template <
typename T>
608 template <
typename T>
617 template <
typename T>
623 void *(*CreateContext)(llvm::BumpPtrAllocator&),
624 void (*DeleteContext)(
void*));
626 template <
typename T>
636 ConstraintMgr->EndPath(St);
656 bool Assumption)
const {
664 inline std::pair<ProgramStateRef , ProgramStateRef >
667 return std::make_pair(
this,
this);
675 bool Assumption)
const {
679 assert(Val.
getAs<
NonLoc>() &&
"Only NonLocs are supported!");
685 inline std::pair<ProgramStateRef, ProgramStateRef>
687 const llvm::APSInt &From,
688 const llvm::APSInt &To)
const {
690 return std::make_pair(
this,
this);
692 assert(Val.
getAs<
NonLoc>() &&
"Only NonLocs are supported!");
711 return getStateManager().StoreMgr->getLValueCompoundLiteral(literal, LC);
725 for (
const auto *
I : D->
chain()) {
734 return getStateManager().StoreMgr->getLValueElement(ElementType, *N, Base);
747 if (
const Expr *Ex = dyn_cast<Expr>(S)) {
779 template <
typename T>
795 template <
typename T>
818 template <
typename CB>
825 template <
typename CB>
832 template <
typename CB>
852 : 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.
ProgramStateRef assumeInclusiveRange(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...
ProgramStateRef bindDefault(SVal loc, SVal V, const LocationContext *LCtx) const
Stmt - This represents one statement.
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
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 visits the reachable symbols using a custom SymbolVisitor.
bool haveEqualEnvironments(ProgramStateRef S1, ProgramStateRef S2)
ProgramStateRef bindLoc(Loc location, SVal V, const LocationContext *LCtx, bool notifyChanges=true) const
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
ProgramStateRef addPartialTaint(SymbolRef ParentSym, const SubRegion *SubRegion, TaintTagType Kind=TaintTagGeneric) const
Create a new state in a which a sub-region of a given symbol is tainted.
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)
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)
llvm::ImmutableMap< const SubRegion *, TaintTagType > TaintedSubRegions
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()
SubRegion - A region that subsets another larger region.
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.
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 &)