14 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATE_H 15 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATE_H 25 #include "llvm/ADT/FoldingSet.h" 26 #include "llvm/ADT/ImmutableMap.h" 27 #include "llvm/Support/Allocator.h" 39 class AnalysisManager;
41 class CallEventManager;
43 typedef std::unique_ptr<ConstraintManager>(*ConstraintManagerCreator)(
45 typedef std::unique_ptr<StoreManager>(*StoreManagerCreator)(
46 ProgramStateManager &);
57 static inline void *
MakeVoidPtr(data_type D) {
return (
void*) D; }
59 return P ? (data_type) *P : (data_type) 0;
77 typedef llvm::ImmutableSet<llvm::APSInt*>
IntSetTy;
83 friend class ProgramStateManager;
87 ProgramStateManager *stateMgr;
97 void setStore(
const StoreRef &storeRef);
110 int64_t
getID()
const;
132 GenericDataMap
getGDM()
const {
return GDM; }
134 void setGDM(GenericDataMap gdm) { GDM = gdm; }
141 ID.AddPointer(V->store);
186 bool assumption)
const;
193 LLVM_NODISCARD std::pair<ProgramStateRef, ProgramStateRef>
207 const llvm::APSInt &From,
208 const llvm::APSInt &To,
209 bool assumption)
const;
216 LLVM_NODISCARD std::pair<ProgramStateRef, ProgramStateRef>
218 const llvm::APSInt &To)
const;
242 bool Invalidate =
true)
const;
246 bool notifyChanges =
true)
const;
309 bool IsVirtual)
const;
364 bool scanReachableSymbols(llvm::iterator_range<region_iterator> Reachable,
367 template <
typename CB> CB scanReachableSymbols(
SVal val)
const;
368 template <
typename CB> CB
369 scanReachableSymbols(llvm::iterator_range<region_iterator> Reachable)
const;
407 void *
const* FindGDM(
void *K)
const;
409 template <
typename T>
413 template <
typename T>
426 template <
typename T>
429 template <
typename T>
433 template <
typename T>
440 template <
typename T>
444 template <
typename T>
449 template <
typename T>
462 void print(raw_ostream &Out,
const char *nl =
"\n",
const char *sep =
"",
464 void printDOT(raw_ostream &Out,
466 void printTaint(raw_ostream &Out,
const char *nl =
"\n")
const;
469 void dumpTaint()
const;
479 const Expr *E,
unsigned BlockCount,
481 bool ResultsInSymbolEscape,
491 class ProgramStateManager {
499 std::unique_ptr<StoreManager> StoreMgr;
500 std::unique_ptr<ConstraintManager> ConstraintMgr;
502 ProgramState::GenericDataMap::Factory GDMFactory;
503 TaintedSubRegions::Factory TSRFactory;
505 typedef llvm::DenseMap<void*,std::pair<void*,void (*)(void*)> > GDMContextsTy;
506 GDMContextsTy GDMContexts;
510 llvm::FoldingSet<ProgramState> StateSet;
513 std::unique_ptr<SValBuilder> svalBuilder;
516 std::unique_ptr<CallEventManager> CallEventMgr;
519 llvm::BumpPtrAllocator &Alloc;
522 std::vector<ProgramState *> freeStates;
528 llvm::BumpPtrAllocator& alloc,
531 ~ProgramStateManager();
539 return svalBuilder->getBasicValueFactory();
547 return svalBuilder->getSymbolManager();
550 return svalBuilder->getSymbolManager();
556 return svalBuilder->getRegionManager();
559 return svalBuilder->getRegionManager();
575 return StoreMgr->ArrayToPointer(Array, ElementTy);
585 StoreMgr->iterBindings(state->getStore(), F);
593 return S1->Env == S2->Env;
597 return S1->store == S2->store;
619 template <
typename T>
635 template <
typename T>
643 template <
typename T>
652 template <
typename T>
657 void *FindGDMContext(
void *index,
658 void *(*CreateContext)(llvm::BumpPtrAllocator&),
659 void (*DeleteContext)(
void*));
661 template <
typename T>
671 ConstraintMgr->EndPath(St);
681 return stateMgr->getConstraintManager();
687 return getStateManager().getRegionManager().getVarRegion(D, LC);
691 bool Assumption)
const {
695 return getStateManager().ConstraintMgr
699 inline std::pair<ProgramStateRef , ProgramStateRef >
702 return std::make_pair(
this,
this);
704 return getStateManager().ConstraintMgr
710 bool Assumption)
const {
714 assert(Val.
getAs<
NonLoc>() &&
"Only NonLocs are supported!");
716 return getStateManager().ConstraintMgr->assumeInclusiveRange(
720 inline std::pair<ProgramStateRef, ProgramStateRef>
722 const llvm::APSInt &From,
723 const llvm::APSInt &To)
const {
725 return std::make_pair(
this,
this);
727 assert(Val.
getAs<
NonLoc>() &&
"Only NonLocs are supported!");
729 return getStateManager().ConstraintMgr->assumeInclusiveRangeDual(
735 return bindLoc(*L, V, LCtx);
743 getStateManager().getRegionManager().getCXXBaseObjectRegion(
749 bool IsVirtual)
const {
751 getStateManager().getRegionManager().getCXXBaseObjectRegion(
752 BaseClass, Super, IsVirtual));
757 return getStateManager().StoreMgr->getLValueVar(VD, LC);
762 return getStateManager().StoreMgr->getLValueCompoundLiteral(literal, LC);
766 return getStateManager().StoreMgr->getLValueIvar(D, Base);
770 return getStateManager().StoreMgr->getLValueField(D, Base);
776 for (
const auto *I : D->
chain()) {
785 return getStateManager().StoreMgr->getLValueElement(ElementType, *N, Base);
792 *getStateManager().svalBuilder);
796 ProgramState::getSValAsScalarOrLoc(
const Stmt *S,
798 if (
const Expr *Ex = dyn_cast<Expr>(S)) {
800 if (Ex->isGLValue() || Loc::isLocType(T) ||
802 return getSVal(S, LCtx);
809 return getStateManager().StoreMgr->getBinding(getStore(), LV, T);
813 return getStateManager().StoreMgr->getBinding(getStore(),
819 return getStateManager().getBasicVals();
823 return getStateManager().getSymbolManager();
828 return getStateManager().add<T>(
this, K, get_context<T>());
831 template <
typename T>
833 return getStateManager().get_context<T>();
838 return getStateManager().remove<T>(
this, K, get_context<T>());
844 return getStateManager().remove<T>(
this, K,
C);
847 template <
typename T>
849 return getStateManager().remove<T>(
this);
854 return getStateManager().set<T>(
this, D);
860 return getStateManager().set<T>(
this, K, E, get_context<T>());
867 return getStateManager().set<T>(
this, K, E,
C);
870 template <
typename CB>
871 CB ProgramState::scanReachableSymbols(
SVal val)
const {
873 scanReachableSymbols(val, cb);
877 template <
typename CB>
878 CB ProgramState::scanReachableSymbols(
879 llvm::iterator_range<region_iterator> Reachable)
const {
881 scanReachableSymbols(Reachable, cb);
892 VisitedItems visited;
897 : 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.
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Stmt - This represents one statement.
Information about invalidation for a particular region/symbol.
BasicValueFactory & getBasicVals()
bool haveEqualStores(ProgramStateRef S1, ProgramStateRef S2)
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.
bool haveEqualEnvironments(ProgramStateRef S1, ProgramStateRef S2)
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
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.
std::unique_ptr< StoreManager >(* StoreManagerCreator)(ProgramStateManager &)
MemRegionManager & getRegionManager()
SValBuilder & getSValBuilder()
void EndPath(ProgramStateRef St)
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::DOTGraphTraits< ExplodedGraph * > DefaultDOTGraphTraits const ExplodedNode const ExplodedNode *Out<< "\l\|";Out<< "StateID: ST"<< State-> getID()<< "
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()
static const TaintTagType TaintTagGeneric
A class responsible for cleaning up unused symbols.
ScanReachableSymbols(ProgramStateRef st, SymbolVisitor &v)
llvm::ImmutableMap< const SubRegion *, TaintTagType > TaintedSubRegions
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.
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.
unsigned TaintTagType
The type of taint, which helps to differentiate between different types of taint. ...
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.