13#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATE_H
14#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATE_H
23#include "llvm/ADT/FoldingSet.h"
24#include "llvm/ADT/ImmutableMap.h"
25#include "llvm/Support/Allocator.h"
40class CallEventManager;
73 typedef llvm::ImmutableSet<llvm::APSInt*>
IntSetTy;
115 bool PosteriorlyOverconstrained =
false;
120 bool isPosteriorlyOverconstrained()
const {
121 return PosteriorlyOverconstrained;
131 void setStore(
const StoreRef &storeRef);
144 int64_t
getID()
const;
175 ID.AddPointer(
V->store);
177 ID.AddBoolean(
V->PosteriorlyOverconstrained);
221 bool assumption)
const;
228 [[nodiscard]] std::pair<ProgramStateRef, ProgramStateRef>
231 [[nodiscard]] std::pair<ProgramStateRef, ProgramStateRef>
246 const llvm::APSInt &From,
247 const llvm::APSInt &To,
248 bool assumption)
const;
255 [[nodiscard]] std::pair<ProgramStateRef, ProgramStateRef>
257 const llvm::APSInt &To)
const;
271 LLVM_ATTRIBUTE_RETURNS_NONNULL
282 bool Invalidate =
true)
const;
286 bool notifyChanges =
true)
const;
356 bool IsVirtual)
const;
415 template <
typename CB> CB
422 void *
const*
FindGDM(
void *K)
const;
424 template <
typename T>
428 template <
typename T>
441 template <
typename T>
444 template <
typename T>
448 template <
typename T>
455 template <
typename T>
459 template <
typename T>
464 template <
typename T>
478 const char *NL =
"\n",
unsigned int Space = 0,
479 bool IsDot =
false)
const;
482 unsigned int Space = 0)
const;
505 std::unique_ptr<StoreManager> StoreMgr;
506 std::unique_ptr<ConstraintManager> ConstraintMgr;
508 ProgramState::GenericDataMap::Factory GDMFactory;
510 typedef llvm::DenseMap<
void*,std::pair<
void*,void (*)(
void*)> > GDMContextsTy;
511 GDMContextsTy GDMContexts;
515 llvm::FoldingSet<ProgramState> StateSet;
518 std::unique_ptr<SValBuilder> svalBuilder;
521 std::unique_ptr<CallEventManager> CallEventMgr;
524 llvm::BumpPtrAllocator &Alloc;
527 std::vector<ProgramState *> freeStates;
533 llvm::BumpPtrAllocator& alloc,
544 return svalBuilder->getBasicValueFactory();
556 return svalBuilder->getSymbolManager();
559 return svalBuilder->getSymbolManager();
565 return svalBuilder->getRegionManager();
568 return svalBuilder->getRegionManager();
585 return StoreMgr->ArrayToPointer(Array, ElementTy);
595 StoreMgr->iterBindings(state->getStore(), F);
603 return ConstraintMgr->haveEqualConstraints(S1, S2);
607 return S1->Env == S2->Env;
611 return S1->store == S2->store;
633 template <
typename T>
649 template <
typename T>
657 template <
typename T>
666 template <
typename T>
672 void *(*CreateContext)(llvm::BumpPtrAllocator&),
673 void (*DeleteContext)(
void*));
675 template <
typename T>
701 bool Assumption)
const {
709inline std::pair<ProgramStateRef , ProgramStateRef >
712 return std::make_pair(
this,
this);
720 bool Assumption)
const {
724 assert(isa<NonLoc>(Val) &&
"Only NonLocs are supported!");
730inline std::pair<ProgramStateRef, ProgramStateRef>
732 const llvm::APSInt &From,
733 const llvm::APSInt &To)
const {
735 return std::make_pair(
this,
this);
737 assert(isa<NonLoc>(Val) &&
"Only NonLocs are supported!");
744 if (std::optional<Loc> L = LV.
getAs<
Loc>())
759 bool IsVirtual)
const {
762 BaseClass, Super, IsVirtual));
772 return getStateManager().StoreMgr->getLValueCompoundLiteral(literal, LC);
794 if (
const Expr *Ex = dyn_cast<Expr>(S)) {
866template <
typename CB>
873template <
typename CB>
875 llvm::iterator_range<region_iterator> Reachable)
const {
886 typedef llvm::DenseSet<const void*> VisitedItems;
888 VisitedItems visited;
893 : state(
std::move(st)), visitor(
v) {}
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a base class of a C++ class.
bool isVirtual() const
Determines whether the base class is a virtual base class (or not).
QualType getType() const
Retrieves the type of the base class.
Represents a C++ struct/union/class.
CompoundLiteralExpr - [C99 6.5.2.5].
This represents one expression.
Represents a member of a struct/union/class.
Represents a field injected from an anonymous union/struct into the parent scope.
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
ObjCIvarDecl - Represents an ObjC instance variable.
A (possibly-)qualified type.
It represents a stack frame of the call stack (based on CallEvent).
Stmt - This represents one statement.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Represents a variable declaration or definition.
Manages the lifetime of CallEvent objects.
Represents an abstract call to a function or method along a particular path.
An entry in the environment consists of a Stmt and an LocationContext.
An immutable map from EnvironemntEntries to SVals.
static bool isLocType(QualType T)
const VarRegion * getVarRegion(const VarDecl *VD, const LocationContext *LC)
getVarRegion - Retrieve or create the memory region associated with a specified VarDecl and LocationC...
MemRegion - The root abstract class for all memory regions.
This is the simplest builder which generates nodes in the ExplodedGraph.
SValBuilder & getSValBuilder()
ProgramStateRef remove(ProgramStateRef st)
const MemRegionManager & getRegionManager() const
ProgramStateRef removeDeadBindingsFromEnvironmentAndStore(ProgramStateRef St, const StackFrameContext *LCtx, SymbolReaper &SymReaper)
bool haveEqualStores(ProgramStateRef S1, ProgramStateRef S2) const
ExprEngine & getOwningEngine()
const ASTContext & getContext() const
ProgramStateRef removeGDM(ProgramStateRef state, void *Key)
void * FindGDMContext(void *index, void *(*CreateContext)(llvm::BumpPtrAllocator &), void(*DeleteContext)(void *))
CallEventManager & getCallEventManager()
bool haveEqualEnvironments(ProgramStateRef S1, ProgramStateRef S2) const
const SymbolManager & getSymbolManager() const
const SValBuilder & getSValBuilder() const
friend void ProgramStateRelease(const ProgramState *state)
Decrement the number of times this state is referenced.
ProgramStateRef set(ProgramStateRef st, typename ProgramStateTrait< T >::data_type D)
ASTContext & getContext()
ProgramStateRef getPersistentStateWithGDM(ProgramStateRef FromState, ProgramStateRef GDMState)
MemRegionManager & getRegionManager()
bool haveEqualConstraints(ProgramStateRef S1, ProgramStateRef S2) const
ProgramStateRef remove(ProgramStateRef st, typename ProgramStateTrait< T >::key_type K, typename ProgramStateTrait< T >::context_type C)
ProgramStateRef addGDM(ProgramStateRef St, void *Key, void *Data)
ProgramStateRef set(ProgramStateRef st, typename ProgramStateTrait< T >::key_type K, typename ProgramStateTrait< T >::value_type V, typename ProgramStateTrait< T >::context_type C)
ProgramStateRef add(ProgramStateRef st, typename ProgramStateTrait< T >::key_type K, typename ProgramStateTrait< T >::context_type C)
ProgramStateRef getPersistentState(ProgramState &Impl)
void iterBindings(ProgramStateRef state, StoreManager::BindingsHandler &F)
SVal ArrayToPointer(Loc Array, QualType ElementTy)
ProgramStateRef getInitialState(const LocationContext *InitLoc)
llvm::BumpPtrAllocator & getAllocator()
BasicValueFactory & getBasicVals()
StoreManager & getStoreManager()
ProgramStateTrait< T >::context_type get_context()
SymbolManager & getSymbolManager()
ConstraintManager & getConstraintManager()
ProgramState - This class encapsulates:
bool scanReachableSymbols(SVal val, SymbolVisitor &visitor) const
Visits the symbols reachable from the given SVal using the provided SymbolVisitor.
ProgramStateTrait< T >::data_type get() const
Loc getLValue(const CXXBaseSpecifier &BaseSpec, const SubRegion *Super) const
Get the lvalue for a base class object reference.
friend void ProgramStateRetain(const ProgramState *state)
Increments the number of times this state is referenced.
ProgramStateRef bindDefaultZero(SVal loc, const LocationContext *LCtx) const
Performs C++ zero-initialization procedure on the region of memory represented by loc.
llvm::ImmutableSet< llvm::APSInt * > IntSetTy
llvm::ImmutableMap< void *, void * > GenericDataMap
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.
void printJson(raw_ostream &Out, const LocationContext *LCtx=nullptr, const char *NL="\n", unsigned int Space=0, bool IsDot=false) const
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...
bool contains(typename ProgramStateTrait< T >::key_type key) const
ProgramStateRef bindDefaultInitial(SVal loc, SVal V, const LocationContext *LCtx) const
Initializes the region of memory represented by loc with an initial value.
ConstraintManager & getConstraintManager() const
Return the ConstraintManager.
ProgramStateRef add(typename ProgramStateTrait< T >::key_type K) const
SVal getSValAsScalarOrLoc(const Stmt *Ex, const LocationContext *LCtx) const
void Profile(llvm::FoldingSetNodeID &ID) const
Profile - Used to profile the contents of this object for inclusion in a FoldingSet.
SVal getSelfSVal(const LocationContext *LC) const
Return the value of 'self' if available in the given context.
SVal getRawSVal(Loc LV, QualType T=QualType()) const
Returns the "raw" SVal bound to LV before any value simplfication.
ConditionTruthVal isNull(SVal V) const
Check if the given SVal is constrained to zero or is a zero constant.
ProgramStateManager & getStateManager() const
Return the ProgramStateManager associated with this state.
ProgramStateRef killBinding(Loc LV) const
GenericDataMap getGDM() const
getGDM - Return the generic data map associated with this state.
const Environment & getEnvironment() const
getEnvironment - Return the environment associated with this state.
friend void ProgramStateRelease(const ProgramState *state)
Decrement the number of times this state is referenced.
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...
Store getStore() const
Return the store associated with this state.
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.
ConditionTruthVal areEqual(SVal Lhs, SVal Rhs) const
void printDOT(raw_ostream &Out, const LocationContext *LCtx=nullptr, unsigned int Space=0) const
ConditionTruthVal isNonNull(SVal V) const
Check if the given SVal is not constrained to zero and is not a zero constant.
ProgramStateRef set(typename ProgramStateTrait< T >::data_type D) const
ProgramStateRef assumeInBound(DefinedOrUnknownSVal idx, DefinedOrUnknownSVal upperBound, bool assumption, QualType IndexType=QualType()) const
ProgramStateRef enterStackFrame(const CallEvent &Call, const StackFrameContext *CalleeCtx) const
enterStackFrame - Returns the state for entry to the given stack frame, preserving the current state.
LLVM_ATTRIBUTE_RETURNS_NONNULL const VarRegion * getRegion(const VarDecl *D, const LocationContext *LC) const
Utility method for getting regions.
SVal getSVal(const Stmt *S, const LocationContext *LCtx) const
Returns the SVal bound to the statement 'S' in the state's environment.
ProgramStateTrait< T >::lookup_type get(typename ProgramStateTrait< T >::key_type key) const
ProgramStateTrait< T >::context_type get_context() const
ProgramStateRef invalidateRegions(ArrayRef< SVal > Values, const Expr *E, unsigned BlockCount, const LocationContext *LCtx, bool CausesPointerEscape, InvalidatedSymbols *IS=nullptr, const CallEvent *Call=nullptr, RegionAndSymbolInvalidationTraits *ITraits=nullptr) const
ProgramStateRef bindLoc(Loc location, SVal V, const LocationContext *LCtx, bool notifyChanges=true) const
static void Profile(llvm::FoldingSetNodeID &ID, const ProgramState *V)
Profile - Profile the contents of a ProgramState object for use in a FoldingSet.
BasicValueFactory & getBasicVals() const
std::pair< ProgramStateRef, ProgramStateRef > assumeInBoundDual(DefinedOrUnknownSVal idx, DefinedOrUnknownSVal upperBound, QualType IndexType=QualType()) const
ProgramStateRef remove() const
void setGDM(GenericDataMap gdm)
AnalysisManager & getAnalysisManager() const
void *const * FindGDM(void *K) const
SymbolManager & getSymbolManager() const
Information about invalidation for a particular region/symbol.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
std::optional< T > getAs() const
Convert to the specified SVal type, returning std::nullopt if this SVal is not of the desired type.
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
A utility class that visits the reachable symbols using a custom SymbolVisitor.
ScanReachableSymbols(ProgramStateRef st, SymbolVisitor &v)
bool scan(nonloc::LazyCompoundVal val)
SubRegion - A region that subsets another larger region.
A class responsible for cleaning up unused symbols.
The simplest example of a concrete compound value is nonloc::CompoundVal, which represents a concrete...
While nonloc::CompoundVal covers a few simple use cases, nonloc::LazyCompoundVal is a more performant...
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
std::unique_ptr< ConstraintManager >(* ConstraintManagerCreator)(ProgramStateManager &, ExprEngine *)
std::unique_ptr< StoreManager >(* StoreManagerCreator)(ProgramStateManager &)
llvm::DenseSet< SymbolRef > InvalidatedSymbols
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
Diagnostic wrappers for TextAPI types for error reporting.
static void * MakeVoidPtr(data_type D)
static data_type MakeData(void *const *P)