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/ADT/STLExtras.h"
26#include "llvm/Support/Allocator.h"
114 bool PosteriorlyOverconstrained =
false;
124 bool isPosteriorlyOverconstrained()
const {
125 return PosteriorlyOverconstrained;
129 mutable unsigned refCount;
136 void setStore(
const StoreRef &storeRef);
180 ID.AddPointer(
V->store);
182 ID.AddBoolean(
V->PosteriorlyOverconstrained);
187 void Profile(llvm::FoldingSetNodeID& ID)
const {
226 bool assumption)
const;
233 [[nodiscard]] std::pair<ProgramStateRef, ProgramStateRef>
236 [[nodiscard]] std::pair<ProgramStateRef, ProgramStateRef>
251 const llvm::APSInt &From,
252 const llvm::APSInt &To,
253 bool assumption)
const;
260 [[nodiscard]] std::pair<ProgramStateRef, ProgramStateRef>
262 const llvm::APSInt &To)
const;
276 LLVM_ATTRIBUTE_RETURNS_NONNULL
286 SVal V,
bool Invalidate =
true)
const;
290 bool notifyChanges =
true)
const;
334 unsigned BlockCount,
const StackFrame *SF,
bool CausesPointerEscape,
358 bool IsVirtual)
const;
416 template <
typename CB> CB
423 void *
const *
FindGDM(
const void *K)
const;
425 template <
typename T>
429 template <
typename T>
442 template <
typename T>
445 template <
typename T>
449 template <
typename T>
456 template <
typename T>
460 template <
typename T>
465 template <
typename T>
479 const char *NL =
"\n",
unsigned int Space = 0,
480 bool IsDot =
false)
const;
483 unsigned int Space = 0)
const;
490 void retain()
const { ++refCount; }
491 void release()
const;
493 SVal desugarReference(
SVal Val)
const;
509 std::unique_ptr<StoreManager> StoreMgr;
511 ProgramState::GenericDataMap::Factory GDMFactory;
515 class GDMContextsTy {
517 using GDMKey =
void *;
518 using ConstGDMKey =
const void *;
519 using DeleterTy = void (*)(GDMKey);
520 using ContextAndDeleter = std::pair<GDMKey, DeleterTy>;
522 GDMContextsTy() =
default;
523 GDMContextsTy(
const GDMContextsTy &) =
delete;
524 GDMContextsTy &operator=(
const GDMContextsTy &) =
delete;
527 for (
auto [Ctx, Deleter] : llvm::make_second_range(Contexts))
531 ContextAndDeleter &operator[](ConstGDMKey Key) {
return Contexts[Key]; }
534 llvm::DenseMap<ConstGDMKey, ContextAndDeleter> Contexts;
536 GDMContextsTy GDMContexts;
540 llvm::FoldingSet<ProgramState> StateSet;
543 std::unique_ptr<SValBuilder> svalBuilder;
546 std::unique_ptr<CallEventManager> CallEventMgr;
549 llvm::BumpPtrAllocator &Alloc;
552 std::vector<ProgramState *> freeStates;
557 std::unique_ptr<ConstraintManager> ConstraintMgr;
566 llvm::BumpPtrAllocator& alloc,
567 ExprEngine *expreng);
577 return svalBuilder->getBasicValueFactory();
589 return svalBuilder->getSymbolManager();
592 return svalBuilder->getSymbolManager();
598 return svalBuilder->getRegionManager();
601 return svalBuilder->getRegionManager();
610 return *ConstraintMgr;
620 return StoreMgr->ArrayToPointer(
Array, ElementTy);
630 StoreMgr->iterBindings(state->getStore(), F);
638 return ConstraintMgr->haveEqualConstraints(S1, S2);
642 return S1->Env == S2->Env;
646 return S1->store == S2->store;
668 template <
typename T>
684 template <
typename T>
692 template <
typename T>
701 template <
typename T>
707 void *(*CreateContext)(llvm::BumpPtrAllocator &),
708 void (*DeleteContext)(
void *));
710 template <
typename T>
725inline void ProgramState::release()
const {
726 assert(refCount > 0);
732 return stateMgr->getConstraintManager();
741 bool Assumption)
const {
749inline std::pair<ProgramStateRef , ProgramStateRef >
752 return std::make_pair(
this,
this);
760 bool Assumption)
const {
764 assert(
isa<NonLoc>(Val) &&
"Only NonLocs are supported!");
770inline std::pair<ProgramStateRef, ProgramStateRef>
772 const llvm::APSInt &From,
773 const llvm::APSInt &To)
const {
775 return std::make_pair(
this,
this);
777 assert(
isa<NonLoc>(Val) &&
"Only NonLocs are supported!");
785 if (std::optional<Loc> L = LV.
getAs<
Loc>())
800 bool IsVirtual)
const {
803 BaseClass, Super, IsVirtual));
813 return getStateManager().StoreMgr->getLValueCompoundLiteral(literal, SF);
900template <
typename CB>
907template <
typename CB>
909 llvm::iterator_range<region_iterator> Reachable)
const {
920 typedef llvm::DenseSet<const void*> VisitedItems;
922 VisitedItems visited;
927 : 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 ...
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
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)
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()
ProgramStateRef getPersistentState(ProgramState &&Impl)
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 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.
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.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
CFGBlock::ConstCFGElementRef ConstCFGElementRef
Diagnostic wrappers for TextAPI types for error reporting.
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t int64_t
static void * MakeVoidPtr(data_type D)
static data_type MakeData(void *const *P)