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
285 bool Invalidate =
true)
const;
289 bool notifyChanges =
true)
const;
360 bool IsVirtual)
const;
419 template <
typename CB> CB
426 void *
const *
FindGDM(
const void *K)
const;
428 template <
typename T>
432 template <
typename T>
445 template <
typename T>
448 template <
typename T>
452 template <
typename T>
459 template <
typename T>
463 template <
typename T>
468 template <
typename T>
482 const char *NL =
"\n",
unsigned int Space = 0,
483 bool IsDot =
false)
const;
486 unsigned int Space = 0)
const;
494 SVal desugarReference(
SVal Val)
const;
510 std::unique_ptr<StoreManager> StoreMgr;
511 std::unique_ptr<ConstraintManager> ConstraintMgr;
513 ProgramState::GenericDataMap::Factory GDMFactory;
515 typedef llvm::DenseMap<
const void *, std::pair<
void *, void (*)(
void *)>>
517 GDMContextsTy GDMContexts;
521 llvm::FoldingSet<ProgramState> StateSet;
524 std::unique_ptr<SValBuilder> svalBuilder;
527 std::unique_ptr<CallEventManager> CallEventMgr;
530 llvm::BumpPtrAllocator &Alloc;
533 std::vector<ProgramState *> freeStates;
539 llvm::BumpPtrAllocator& alloc,
550 return svalBuilder->getBasicValueFactory();
562 return svalBuilder->getSymbolManager();
565 return svalBuilder->getSymbolManager();
571 return svalBuilder->getRegionManager();
574 return svalBuilder->getRegionManager();
583 return *ConstraintMgr;
595 return StoreMgr->ArrayToPointer(Array, ElementTy);
605 StoreMgr->iterBindings(state->getStore(), F);
613 return ConstraintMgr->haveEqualConstraints(S1, S2);
617 return S1->Env == S2->Env;
621 return S1->store == S2->store;
643 template <
typename T>
659 template <
typename T>
667 template <
typename T>
676 template <
typename T>
682 void *(*CreateContext)(llvm::BumpPtrAllocator &),
683 void (*DeleteContext)(
void *));
685 template <
typename T>
701 return stateMgr->getConstraintManager();
711 bool Assumption)
const {
712 if (
Cond.isUnknown())
719inline std::pair<ProgramStateRef , ProgramStateRef >
721 if (
Cond.isUnknown())
722 return std::make_pair(
this,
this);
730 bool Assumption)
const {
734 assert(
isa<NonLoc>(Val) &&
"Only NonLocs are supported!");
740inline std::pair<ProgramStateRef, ProgramStateRef>
742 const llvm::APSInt &From,
743 const llvm::APSInt &To)
const {
745 return std::make_pair(
this,
this);
747 assert(
isa<NonLoc>(Val) &&
"Only NonLocs are supported!");
754 if (std::optional<Loc> L = LV.
getAs<
Loc>())
769 bool IsVirtual)
const {
772 BaseClass, Super, IsVirtual));
782 return getStateManager().StoreMgr->getLValueCompoundLiteral(literal, LC);
804 if (
const Expr *Ex = dyn_cast<Expr>(S)) {
807 T->isIntegralOrEnumerationType())
876template <
typename CB>
883template <
typename CB>
885 llvm::iterator_range<region_iterator> Reachable)
const {
896 typedef llvm::DenseSet<const void*> VisitedItems;
898 VisitedItems visited;
903 : 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...
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.
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
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)
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
ProgramStateRef getInitialState(const LocationContext *InitLoc)
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.
ProgramStateRef bindDefaultZero(SVal loc, const LocationContext *LCtx) const
Performs C++ zero-initialization procedure on the region of memory represented by loc.
friend class ProgramStateManager
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.
llvm::ImmutableMap< const void *, void * > GenericDataMap
friend class ExplodedGraph
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 simplification.
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
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.
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.
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
const MemRegion ** region_iterator
ProgramStateTrait< T >::context_type get_context() const
ProgramStateRef invalidateRegions(ArrayRef< const MemRegion * > Regions, ConstCFGElementRef Elem, 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.
ProgramStateRef bindLoc(Loc location, SVal V, const LocationContext *LCtx, bool notifyChanges=true) 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
ProgramStateRef invalidateRegions(ArrayRef< SVal > Values, ConstCFGElementRef Elem, unsigned BlockCount, const LocationContext *LCtx, bool CausesPointerEscape, InvalidatedSymbols *IS=nullptr, const CallEvent *Call=nullptr, RegionAndSymbolInvalidationTraits *ITraits=nullptr) const
void *const * FindGDM(const void *K) const
ProgramStateRef remove() const
void setGDM(GenericDataMap gdm)
AnalysisManager & getAnalysisManager() const
friend class ExplodedNode
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)