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"
113 bool PosteriorlyOverconstrained =
false;
123 bool isPosteriorlyOverconstrained()
const {
124 return PosteriorlyOverconstrained;
135 void setStore(
const StoreRef &storeRef);
148 int64_t
getID()
const;
178 ID.AddPointer(
V->store);
180 ID.AddBoolean(
V->PosteriorlyOverconstrained);
185 void Profile(llvm::FoldingSetNodeID& ID)
const {
224 bool assumption)
const;
231 [[nodiscard]] std::pair<ProgramStateRef, ProgramStateRef>
234 [[nodiscard]] std::pair<ProgramStateRef, ProgramStateRef>
249 const llvm::APSInt &From,
250 const llvm::APSInt &To,
251 bool assumption)
const;
258 [[nodiscard]] std::pair<ProgramStateRef, ProgramStateRef>
260 const llvm::APSInt &To)
const;
274 LLVM_ATTRIBUTE_RETURNS_NONNULL
284 SVal V,
bool Invalidate =
true)
const;
288 bool notifyChanges =
true)
const;
332 unsigned BlockCount,
const StackFrame *SF,
bool CausesPointerEscape,
356 bool IsVirtual)
const;
414 template <
typename CB> CB
421 void *
const *
FindGDM(
const void *K)
const;
423 template <
typename T>
427 template <
typename T>
440 template <
typename T>
443 template <
typename T>
447 template <
typename T>
454 template <
typename T>
458 template <
typename T>
463 template <
typename T>
477 const char *NL =
"\n",
unsigned int Space = 0,
478 bool IsDot =
false)
const;
481 unsigned int Space = 0)
const;
489 SVal desugarReference(
SVal Val)
const;
505 std::unique_ptr<StoreManager> StoreMgr;
506 std::unique_ptr<ConstraintManager> ConstraintMgr;
508 ProgramState::GenericDataMap::Factory GDMFactory;
510 typedef llvm::DenseMap<
const void *, std::pair<
void *, void (*)(
void *)>>
512 GDMContextsTy GDMContexts;
516 llvm::FoldingSet<ProgramState> StateSet;
519 std::unique_ptr<SValBuilder> svalBuilder;
522 std::unique_ptr<CallEventManager> CallEventMgr;
525 llvm::BumpPtrAllocator &Alloc;
528 std::vector<ProgramState *> freeStates;
534 llvm::BumpPtrAllocator& alloc,
545 return svalBuilder->getBasicValueFactory();
557 return svalBuilder->getSymbolManager();
560 return svalBuilder->getSymbolManager();
566 return svalBuilder->getRegionManager();
569 return svalBuilder->getRegionManager();
578 return *ConstraintMgr;
588 return StoreMgr->ArrayToPointer(
Array, ElementTy);
598 StoreMgr->iterBindings(state->getStore(), F);
606 return ConstraintMgr->haveEqualConstraints(S1, S2);
610 return S1->Env == S2->Env;
614 return S1->store == S2->store;
636 template <
typename T>
652 template <
typename T>
660 template <
typename T>
669 template <
typename T>
675 void *(*CreateContext)(llvm::BumpPtrAllocator &),
676 void (*DeleteContext)(
void *));
678 template <
typename T>
694 return stateMgr->getConstraintManager();
703 bool Assumption)
const {
704 if (
Cond.isUnknown())
711inline std::pair<ProgramStateRef , ProgramStateRef >
713 if (
Cond.isUnknown())
714 return std::make_pair(
this,
this);
722 bool Assumption)
const {
726 assert(
isa<NonLoc>(Val) &&
"Only NonLocs are supported!");
732inline std::pair<ProgramStateRef, ProgramStateRef>
734 const llvm::APSInt &From,
735 const llvm::APSInt &To)
const {
737 return std::make_pair(
this,
this);
739 assert(
isa<NonLoc>(Val) &&
"Only NonLocs are supported!");
747 if (std::optional<Loc> L = LV.
getAs<
Loc>())
762 bool IsVirtual)
const {
765 BaseClass, Super, IsVirtual));
775 return getStateManager().StoreMgr->getLValueCompoundLiteral(literal, SF);
862template <
typename CB>
869template <
typename CB>
871 llvm::iterator_range<region_iterator> Reachable)
const {
882 typedef llvm::DenseSet<const void*> VisitedItems;
884 VisitedItems visited;
889 : 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.
ObjCIvarDecl - Represents an ObjC instance variable.
A (possibly-)qualified type.
It represents a stack frame of the call stack.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
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 StackFrame.
An immutable map from EnvironmentEntries to SVals.
static bool isLocType(QualType T)
const VarRegion * getVarRegion(const VarDecl *VD, const StackFrame *SF)
getVarRegion - Retrieve or create the memory region associated with a specified VarDecl and StackFram...
MemRegion - The root abstract class for all memory regions.
SValBuilder & getSValBuilder()
ProgramStateRef remove(ProgramStateRef st)
const MemRegionManager & getRegionManager() const
bool haveEqualStores(ProgramStateRef S1, ProgramStateRef S2) const
ExprEngine & getOwningEngine()
const ASTContext & getContext() const
ProgramStateRef getInitialState(const StackFrame *InitSF)
const StoreManager & getStoreManager() const
void * FindGDMContext(const 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 class ProgramState
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)
ProgramStateRef removeDeadBindingsFromEnvironmentAndStore(ProgramStateRef St, const StackFrame *SF, SymbolReaper &SymReaper)
ASTContext & getContext()
ProgramStateRef getPersistentStateWithGDM(ProgramStateRef FromState, ProgramStateRef GDMState)
ProgramStateRef removeGDM(ProgramStateRef state, const void *Key)
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, const 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)
const ConstraintManager & getConstraintManager() const
llvm::BumpPtrAllocator & getAllocator()
BasicValueFactory & getBasicVals()
StoreManager & getStoreManager()
ProgramStateTrait< T >::context_type get_context()
SymbolManager & getSymbolManager()
ProgramStateManager(ASTContext &Ctx, StoreManagerCreator CreateStoreManager, ConstraintManagerCreator CreateConstraintManager, llvm::BumpPtrAllocator &alloc, ExprEngine *expreng)
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.
friend class ProgramStateManager
llvm::ImmutableMap< const void *, void * > GenericDataMap
friend class ExplodedGraph
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 StackFrame *SF) const
Initializes the region of memory represented by loc with an initial value.
ConstraintManager & getConstraintManager() const
Return the ConstraintManager.
LLVM_ATTRIBUTE_RETURNS_NONNULL const VarRegion * getRegion(const VarDecl *D, const StackFrame *SF) const
Utility method for getting regions.
ProgramStateRef invalidateRegions(ArrayRef< SVal > Values, ConstCFGElementRef Elem, unsigned BlockCount, const StackFrame *SF, bool CausesPointerEscape, InvalidatedSymbols *IS=nullptr, const CallEvent *Call=nullptr, RegionAndSymbolInvalidationTraits *ITraits=nullptr) const
ProgramStateRef add(typename ProgramStateTrait< T >::key_type K) const
void Profile(llvm::FoldingSetNodeID &ID) const
Profile - Used to profile the contents of this object for inclusion in a FoldingSet.
SVal getRawSVal(Loc LV, QualType T=QualType()) const
Returns the "raw" SVal bound to LV before any value simplification.
ConditionTruthVal isNull(SVal V) const
Check if the given SVal is constrained to zero or is a zero constant.
ProgramStateRef bindLoc(Loc location, SVal V, const StackFrame *SF, bool notifyChanges=true) const
ProgramStateManager & getStateManager() const
Return the ProgramStateManager associated with this state.
ProgramStateRef killBinding(Loc LV) const
ProgramState(ProgramStateManager *mgr, const Environment &env, StoreRef st, GenericDataMap gdm)
This ctor is used when creating the first ProgramState object.
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.
ProgramStateRef BindExpr(const Expr *E, const StackFrame *SF, SVal V, bool Invalidate=true) const
Create a new state by binding the value V to the expression E in the state's environment.
friend void ProgramStateRelease(const ProgramState *state)
Decrement the number of times this state is referenced.
ProgramStateRef bindDefaultZero(SVal loc, const StackFrame *SF) const
Performs C++ zero-initialization procedure on the region of memory represented by loc.
SVal getSVal(const Expr *E, const StackFrame *SF) const
Returns the SVal bound to the expression E in the state's environment.
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.
ConditionTruthVal areEqual(SVal Lhs, SVal Rhs) 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
ProgramStateTrait< T >::lookup_type get(typename ProgramStateTrait< T >::key_type key) const
SVal getSValAsScalarOrLoc(const Expr *E, const StackFrame *SF) const
ProgramStateRef invalidateRegions(ArrayRef< const MemRegion * > Regions, ConstCFGElementRef Elem, unsigned BlockCount, const StackFrame *SF, 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.
const MemRegion ** region_iterator
ProgramStateTrait< T >::context_type get_context() const
void printDOT(raw_ostream &Out, const StackFrame *SF=nullptr, unsigned int Space=0) const
SVal getSelfSVal(const StackFrame *SF) const
Return the value of 'self' if available in the given context.
void printJson(raw_ostream &Out, const StackFrame *SF=nullptr, const char *NL="\n", unsigned int Space=0, bool IsDot=false) const
friend class ConstraintManager
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
void *const * FindGDM(const void *K) const
ProgramStateRef remove() const
void setGDM(GenericDataMap gdm)
AnalysisManager & getAnalysisManager() const
friend class ExplodedNode
ProgramStateRef enterStackFrame(const CallEvent &Call, const StackFrame *CalleeSF) const
enterStackFrame - Returns the state for entry to the given stack frame, preserving the current state.
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.
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.
llvm::DenseSet< SymbolRef > InvalidatedSymbols
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
std::unique_ptr< ConstraintManager >(* ConstraintManagerCreator)(ProgramStateManager &, ExprEngine *)
std::unique_ptr< StoreManager >(* StoreManagerCreator)(ProgramStateManager &)
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.
bool isa(CodeGen::Address addr)
CFGBlock::ConstCFGElementRef ConstCFGElementRef
Diagnostic wrappers for TextAPI types for error reporting.
static void * MakeVoidPtr(data_type D)
static data_type MakeData(void *const *P)