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>
204 const llvm::APSInt &From,
205 const llvm::APSInt &To,
206 bool assumption)
const;
213 LLVM_NODISCARD std::pair<ProgramStateRef, ProgramStateRef>
215 const llvm::APSInt &To)
const;
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();
511 return svalBuilder->getSymbolManager();
514 return svalBuilder->getSymbolManager();
520 return svalBuilder->getRegionManager();
523 return svalBuilder->getRegionManager();
539 return StoreMgr->ArrayToPointer(Array, ElementTy);
549 StoreMgr->iterBindings(state->getStore(), F);
557 return ConstraintMgr->haveEqualConstraints(S1, S2);
561 return S1->Env == S2->Env;
565 return S1->store == S2->store;
587 template <
typename T>
603 template <
typename T>
611 template <
typename T>
620 template <
typename T>
625 void *FindGDMContext(
void *index,
626 void *(*CreateContext)(llvm::BumpPtrAllocator&),
627 void (*DeleteContext)(
void*));
629 template <
typename T>
645 return stateMgr->getConstraintManager();
651 return getStateManager().getRegionManager().getVarRegion(D, LC);
655 bool Assumption)
const {
659 return getStateManager().ConstraintMgr
663 inline std::pair<ProgramStateRef , ProgramStateRef >
666 return std::make_pair(
this,
this);
668 return getStateManager().ConstraintMgr
674 bool Assumption)
const {
678 assert(Val.
getAs<
NonLoc>() &&
"Only NonLocs are supported!");
680 return getStateManager().ConstraintMgr->assumeInclusiveRange(
684 inline std::pair<ProgramStateRef, ProgramStateRef>
686 const llvm::APSInt &From,
687 const llvm::APSInt &To)
const {
689 return std::make_pair(
this,
this);
691 assert(Val.
getAs<
NonLoc>() &&
"Only NonLocs are supported!");
693 return getStateManager().ConstraintMgr->assumeInclusiveRangeDual(
699 return bindLoc(*L, V, LCtx);
707 getStateManager().getRegionManager().getCXXBaseObjectRegion(
713 bool IsVirtual)
const {
715 getStateManager().getRegionManager().getCXXBaseObjectRegion(
716 BaseClass, Super, IsVirtual));
721 return getStateManager().StoreMgr->getLValueVar(VD, LC);
726 return getStateManager().StoreMgr->getLValueCompoundLiteral(literal, LC);
730 return getStateManager().StoreMgr->getLValueIvar(D, Base);
734 return getStateManager().StoreMgr->getLValueField(D, Base);
740 for (
const auto *I : D->
chain()) {
749 return getStateManager().StoreMgr->getLValueElement(ElementType, *N, Base);
756 *getStateManager().svalBuilder);
760 ProgramState::getSValAsScalarOrLoc(
const Stmt *S,
762 if (
const Expr *Ex = dyn_cast<Expr>(S)) {
764 if (Ex->isGLValue() || Loc::isLocType(T) ||
766 return getSVal(S, LCtx);
773 return getStateManager().StoreMgr->getBinding(getStore(), LV, T);
777 return getStateManager().StoreMgr->getBinding(getStore(),
783 return getStateManager().getBasicVals();
787 return getStateManager().getSymbolManager();
792 return getStateManager().add<T>(
this, K, get_context<T>());
795 template <
typename T>
797 return getStateManager().get_context<T>();
802 return getStateManager().remove<T>(
this, K, get_context<T>());
808 return getStateManager().remove<T>(
this, K,
C);
811 template <
typename T>
813 return getStateManager().remove<T>(
this);
818 return getStateManager().set<T>(
this, D);
824 return getStateManager().set<T>(
this, K, E, get_context<T>());
831 return getStateManager().set<T>(
this, K, E,
C);
834 template <
typename CB>
835 CB ProgramState::scanReachableSymbols(
SVal val)
const {
837 scanReachableSymbols(val, cb);
841 template <
typename CB>
842 CB ProgramState::scanReachableSymbols(
843 llvm::iterator_range<region_iterator> Reachable)
const {
845 scanReachableSymbols(Reachable, cb);
856 VisitedItems visited;
861 : 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.
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...
llvm::DOTGraphTraits< ExplodedGraph * > DefaultDOTGraphTraits const ExplodedNode const ExplodedNode *Out<< "\l";Indent(Out, Space, IsDot)<< "],\l";bool SameAsAllPredecessors=std::all_of(N->pred_begin(), N->pred_end(), [&](const ExplodedNode *P) { return P->getState()==State;});if(!SameAsAllPredecessors) { State-> printDOT(Out, N->getLocationContext(), Space)
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 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.