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" 37 class AnalysisManager;
39 class CallEventManager;
41 typedef std::unique_ptr<ConstraintManager>(*ConstraintManagerCreator)(
43 typedef std::unique_ptr<StoreManager>(*StoreManagerCreator)(
44 ProgramStateManager &);
54 static inline void *
MakeVoidPtr(data_type D) {
return (
void*) D; }
56 return P ? (data_type) *P : (data_type) 0;
74 typedef llvm::ImmutableSet<llvm::APSInt*>
IntSetTy;
80 friend class ProgramStateManager;
84 ProgramStateManager *stateMgr;
94 void setStore(
const StoreRef &storeRef);
107 int64_t getID()
const;
129 GenericDataMap
getGDM()
const {
return GDM; }
131 void setGDM(GenericDataMap gdm) { GDM = gdm; }
138 ID.AddPointer(V->store);
183 bool assumption)
const;
190 LLVM_NODISCARD std::pair<ProgramStateRef, ProgramStateRef>
206 bool assumption)
const;
213 LLVM_NODISCARD std::pair<ProgramStateRef, ProgramStateRef>
239 bool Invalidate =
true)
const;
243 bool notifyChanges =
true)
const;
306 bool IsVirtual)
const;
361 bool scanReachableSymbols(llvm::iterator_range<region_iterator> Reachable,
364 template <
typename CB> CB scanReachableSymbols(
SVal val)
const;
365 template <
typename CB> CB
366 scanReachableSymbols(llvm::iterator_range<region_iterator> Reachable)
const;
372 void *
const* FindGDM(
void *K)
const;
374 template <
typename T>
378 template <
typename T>
391 template <
typename T>
394 template <
typename T>
398 template <
typename T>
405 template <
typename T>
409 template <
typename T>
414 template <
typename T>
427 void printJson(raw_ostream &Out,
const LocationContext *LCtx =
nullptr,
428 const char *NL =
"\n",
unsigned int Space = 0,
429 bool IsDot =
false)
const;
432 unsigned int Space = 0)
const;
444 const Expr *E,
unsigned BlockCount,
446 bool ResultsInSymbolEscape,
456 class ProgramStateManager {
464 std::unique_ptr<StoreManager> StoreMgr;
465 std::unique_ptr<ConstraintManager> ConstraintMgr;
467 ProgramState::GenericDataMap::Factory GDMFactory;
469 typedef llvm::DenseMap<void*,std::pair<void*,void (*)(void*)> > GDMContextsTy;
470 GDMContextsTy GDMContexts;
474 llvm::FoldingSet<ProgramState> StateSet;
477 std::unique_ptr<SValBuilder> svalBuilder;
480 std::unique_ptr<CallEventManager> CallEventMgr;
483 llvm::BumpPtrAllocator &Alloc;
486 std::vector<ProgramState *> freeStates;
492 llvm::BumpPtrAllocator& alloc,
495 ~ProgramStateManager();
503 return svalBuilder->getBasicValueFactory();
515 return svalBuilder->getSymbolManager();
518 return svalBuilder->getSymbolManager();
524 return svalBuilder->getRegionManager();
527 return svalBuilder->getRegionManager();
544 return StoreMgr->ArrayToPointer(Array, ElementTy);
554 StoreMgr->iterBindings(state->getStore(), F);
562 return ConstraintMgr->haveEqualConstraints(S1, S2);
566 return S1->Env == S2->Env;
570 return S1->store == S2->store;
592 template <
typename T>
608 template <
typename T>
616 template <
typename T>
625 template <
typename T>
630 void *FindGDMContext(
void *index,
631 void *(*CreateContext)(llvm::BumpPtrAllocator&),
632 void (*DeleteContext)(
void*));
634 template <
typename T>
650 return stateMgr->getConstraintManager();
656 return getStateManager().getRegionManager().getVarRegion(D, LC);
660 bool Assumption)
const {
664 return getStateManager().ConstraintMgr
668 inline std::pair<ProgramStateRef , ProgramStateRef >
671 return std::make_pair(
this,
this);
673 return getStateManager().ConstraintMgr
679 bool Assumption)
const {
683 assert(Val.
getAs<
NonLoc>() &&
"Only NonLocs are supported!");
685 return getStateManager().ConstraintMgr->assumeInclusiveRange(
689 inline std::pair<ProgramStateRef, ProgramStateRef>
694 return std::make_pair(
this,
this);
696 assert(Val.
getAs<
NonLoc>() &&
"Only NonLocs are supported!");
698 return getStateManager().ConstraintMgr->assumeInclusiveRangeDual(
704 return bindLoc(*L, V, LCtx);
712 getStateManager().getRegionManager().getCXXBaseObjectRegion(
718 bool IsVirtual)
const {
720 getStateManager().getRegionManager().getCXXBaseObjectRegion(
721 BaseClass, Super, IsVirtual));
726 return getStateManager().StoreMgr->getLValueVar(VD, LC);
731 return getStateManager().StoreMgr->getLValueCompoundLiteral(literal, LC);
735 return getStateManager().StoreMgr->getLValueIvar(D, Base);
739 return getStateManager().StoreMgr->getLValueField(D, Base);
745 for (
const auto *I : D->
chain()) {
754 return getStateManager().StoreMgr->getLValueElement(ElementType, *N, Base);
761 *getStateManager().svalBuilder);
765 ProgramState::getSValAsScalarOrLoc(
const Stmt *S,
767 if (
const Expr *Ex = dyn_cast<Expr>(S)) {
769 if (Ex->isGLValue() || Loc::isLocType(T) ||
771 return getSVal(S, LCtx);
778 return getStateManager().StoreMgr->getBinding(getStore(), LV, T);
782 return getStateManager().StoreMgr->getBinding(getStore(),
788 return getStateManager().getBasicVals();
792 return getStateManager().getSymbolManager();
797 return getStateManager().add<T>(
this, K, get_context<T>());
800 template <
typename T>
802 return getStateManager().get_context<T>();
807 return getStateManager().remove<T>(
this, K, get_context<T>());
813 return getStateManager().remove<T>(
this, K,
C);
816 template <
typename T>
818 return getStateManager().remove<T>(
this);
823 return getStateManager().set<T>(
this, D);
829 return getStateManager().set<T>(
this, K, E, get_context<T>());
836 return getStateManager().set<T>(
this, K, E,
C);
839 template <
typename CB>
840 CB ProgramState::scanReachableSymbols(
SVal val)
const {
842 scanReachableSymbols(val, cb);
846 template <
typename CB>
847 CB ProgramState::scanReachableSymbols(
848 llvm::iterator_range<region_iterator> Reachable)
const {
850 scanReachableSymbols(Reachable, cb);
861 VisitedItems visited;
866 : state(
std::move(st)), visitor(v) {}
const Environment & getEnvironment() const
getEnvironment - Return the environment associated with this state.
A (possibly-)qualified type.
MemRegion - The root abstract class for all memory regions.
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Stmt - This represents one statement.
Information about invalidation for a particular region/symbol.
BasicValueFactory & getBasicVals()
bool contains(typename ProgramStateTrait< T >::key_type key) const
Manages the lifetime of CallEvent objects.
llvm::ImmutableSet< llvm::APSInt * > IntSetTy
bool isVirtual() const
Determines whether the base class is a virtual base class (or not).
A utility class that visits the reachable symbols using a custom SymbolVisitor.
Represents a variable declaration or definition.
CompoundLiteralExpr - [C99 6.5.2.5].
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
llvm::DOTGraphTraits< ExplodedGraph * > DefaultDOTGraphTraits const ExplodedNode const ExplodedNode *Out<< "\l";Indent(Out, Space, IsDot)<< "],\l";State-> printDOT(Out, N->getLocationContext(), Space)
Store getStore() const
Return the store associated with this state.
const SymbolManager & getSymbolManager() const
bool haveEqualEnvironments(ProgramStateRef S1, ProgramStateRef S2) const
ProgramStateRef add(ProgramStateRef st, typename ProgramStateTrait< T >::key_type K, typename ProgramStateTrait< T >::context_type C)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a member of a struct/union/class.
bool haveEqualStores(ProgramStateRef S1, ProgramStateRef S2) const
std::unique_ptr< StoreManager >(* StoreManagerCreator)(ProgramStateManager &)
MemRegionManager & getRegionManager()
SValBuilder & getSValBuilder()
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
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
ProgramStateManager & getStateManager() const
Return the ProgramStateManager associated with this state.
GenericDataMap getGDM() const
getGDM - Return the generic data map associated with this state.
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
ArrayRef< NamedDecl * > chain() const
virtual SVal getLValueField(const FieldDecl *D, SVal Base)
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
std::unique_ptr< ConstraintManager >(* ConstraintManagerCreator)(ProgramStateManager &, SubEngine *)
llvm::ImmutableMap< void *, void * > GenericDataMap
void Profile(llvm::FoldingSetNodeID &ID) const
Profile - Used to profile the contents of this object for inclusion in a FoldingSet.
ProgramState - This class encapsulates:
This represents one expression.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
StoreManager & getStoreManager()
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
llvm::BumpPtrAllocator & getAllocator()
static void Profile(llvm::FoldingSetNodeID &ID, const Environment *env)
Profile - Profile the contents of an Environment object for use in a FoldingSet.
CallEventManager & getCallEventManager()
An entry in the environment consists of a Stmt and an LocationContext.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
ProgramStateTrait< T >::context_type get_context()
A class responsible for cleaning up unused symbols.
ScanReachableSymbols(ProgramStateRef st, SymbolVisitor &v)
static void * MakeVoidPtr(data_type D)
SymbolManager & getSymbolManager()
An immutable map from EnvironemntEntries to SVals.
Dataflow Directional Tag Classes.
SVal ArrayToPointer(Loc Array, QualType ElementTy)
void ProgramStateRelease(const ProgramState *state)
Decrement the number of times this state is referenced.
static data_type MakeData(void *const *P)
Represents a field injected from an anonymous union/struct into the parent scope. ...
Represents an abstract call to a function or method along a particular path.
ASTContext & getContext()
ConstraintManager & getConstraintManager()
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
SubRegion - A region that subsets another larger region.
bool haveEqualConstraints(ProgramStateRef S1, ProgramStateRef S2) const
void ProgramStateRetain(const ProgramState *state)
Increments the number of times this state is referenced.
Represents a base class of a C++ class.
SubEngine & getOwningEngine()
Represents a C++ struct/union/class.
const SValBuilder & getSValBuilder() const
const MemRegionManager & getRegionManager() const
ObjCIvarDecl - Represents an ObjC instance variable.
const ASTContext & getContext() const
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)
void setGDM(GenericDataMap gdm)
QualType getType() const
Retrieves the type of the base class.