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);
130 GenericDataMap
getGDM()
const {
return GDM; }
132 void setGDM(GenericDataMap gdm) { GDM = gdm; }
139 ID.AddPointer(V->store);
184 bool assumption)
const;
191 LLVM_NODISCARD std::pair<ProgramStateRef, ProgramStateRef>
205 const llvm::APSInt &From,
206 const llvm::APSInt &To,
207 bool assumption)
const;
214 LLVM_NODISCARD std::pair<ProgramStateRef, ProgramStateRef>
216 const llvm::APSInt &To)
const;
240 bool Invalidate =
true)
const;
244 bool notifyChanges =
true)
const;
307 bool IsVirtual)
const;
360 bool scanReachableSymbols(
const SVal *I,
const SVal *E,
365 bool scanReachableSymbols(
const MemRegion *
const *I,
369 template <
typename CB> CB scanReachableSymbols(
SVal val)
const;
370 template <
typename CB> CB scanReachableSymbols(
const SVal *beg,
371 const SVal *end)
const;
373 template <
typename CB> CB
374 scanReachableSymbols(
const MemRegion *
const *beg,
413 void *
const* FindGDM(
void *K)
const;
415 template <
typename T>
419 template <
typename T>
432 template <
typename T>
435 template <
typename T>
439 template <
typename T>
446 template <
typename T>
450 template <
typename T>
455 template <
typename T>
468 void print(raw_ostream &Out,
const char *nl =
"\n",
const char *sep =
"",
470 void printDOT(raw_ostream &Out,
472 void printTaint(raw_ostream &Out,
const char *nl =
"\n",
473 const char *sep =
"")
const;
476 void dumpTaint()
const;
486 const Expr *E,
unsigned BlockCount,
488 bool ResultsInSymbolEscape,
498 class ProgramStateManager {
506 std::unique_ptr<StoreManager> StoreMgr;
507 std::unique_ptr<ConstraintManager> ConstraintMgr;
512 typedef llvm::DenseMap<void*,std::pair<void*,void (*)(void*)> > GDMContextsTy;
513 GDMContextsTy GDMContexts;
517 llvm::FoldingSet<ProgramState> StateSet;
520 std::unique_ptr<SValBuilder> svalBuilder;
523 std::unique_ptr<CallEventManager> CallEventMgr;
526 llvm::BumpPtrAllocator &Alloc;
529 std::vector<ProgramState *> freeStates;
535 llvm::BumpPtrAllocator& alloc,
538 ~ProgramStateManager();
546 return svalBuilder->getBasicValueFactory();
554 return svalBuilder->getSymbolManager();
557 return svalBuilder->getSymbolManager();
563 return svalBuilder->getRegionManager();
566 return svalBuilder->getRegionManager();
582 return StoreMgr->ArrayToPointer(Array, ElementTy);
592 StoreMgr->iterBindings(state->getStore(), F);
600 return S1->Env == S2->Env;
604 return S1->store == S2->store;
626 template <
typename T>
642 template <
typename T>
650 template <
typename T>
659 template <
typename T>
664 void *FindGDMContext(
void *index,
665 void *(*CreateContext)(llvm::BumpPtrAllocator&),
666 void (*DeleteContext)(
void*));
668 template <
typename T>
678 ConstraintMgr->EndPath(St);
688 return stateMgr->getConstraintManager();
694 return getStateManager().getRegionManager().getVarRegion(D, LC);
698 bool Assumption)
const {
702 return getStateManager().ConstraintMgr
706 inline std::pair<ProgramStateRef , ProgramStateRef >
709 return std::make_pair(
this,
this);
711 return getStateManager().ConstraintMgr
717 bool Assumption)
const {
721 assert(Val.
getAs<
NonLoc>() &&
"Only NonLocs are supported!");
723 return getStateManager().ConstraintMgr->assumeInclusiveRange(
727 inline std::pair<ProgramStateRef, ProgramStateRef>
729 const llvm::APSInt &From,
730 const llvm::APSInt &To)
const {
732 return std::make_pair(
this,
this);
734 assert(Val.
getAs<
NonLoc>() &&
"Only NonLocs are supported!");
736 return getStateManager().ConstraintMgr->assumeInclusiveRangeDual(
742 return bindLoc(*L, V, LCtx);
750 getStateManager().getRegionManager().getCXXBaseObjectRegion(
756 bool IsVirtual)
const {
758 getStateManager().getRegionManager().getCXXBaseObjectRegion(
759 BaseClass, Super, IsVirtual));
764 return getStateManager().StoreMgr->getLValueVar(VD, LC);
769 return getStateManager().StoreMgr->getLValueCompoundLiteral(literal, LC);
773 return getStateManager().StoreMgr->getLValueIvar(D, Base);
777 return getStateManager().StoreMgr->getLValueField(D, Base);
783 for (
const auto *I : D->
chain()) {
792 return getStateManager().StoreMgr->getLValueElement(ElementType, *N, Base);
799 *getStateManager().svalBuilder);
803 ProgramState::getSValAsScalarOrLoc(
const Stmt *S,
805 if (
const Expr *Ex = dyn_cast<Expr>(S)) {
807 if (Ex->isGLValue() || Loc::isLocType(T) ||
809 return getSVal(S, LCtx);
816 return getStateManager().StoreMgr->getBinding(getStore(), LV, T);
820 return getStateManager().StoreMgr->getBinding(getStore(),
826 return getStateManager().getBasicVals();
830 return getStateManager().getSymbolManager();
835 return getStateManager().add<T>(
this, K, get_context<T>());
838 template <
typename T>
840 return getStateManager().get_context<T>();
845 return getStateManager().remove<T>(
this, K, get_context<T>());
851 return getStateManager().remove<T>(
this, K,
C);
854 template <
typename T>
856 return getStateManager().remove<T>(
this);
861 return getStateManager().set<T>(
this, D);
867 return getStateManager().set<T>(
this, K, E, get_context<T>());
874 return getStateManager().set<T>(
this, K, E,
C);
877 template <
typename CB>
878 CB ProgramState::scanReachableSymbols(
SVal val)
const {
880 scanReachableSymbols(val, cb);
884 template <
typename CB>
885 CB ProgramState::scanReachableSymbols(
const SVal *beg,
const SVal *end)
const {
887 scanReachableSymbols(beg, end, cb);
891 template <
typename CB>
892 CB ProgramState::scanReachableSymbols(
const MemRegion *
const *beg,
895 scanReachableSymbols(beg, end, cb);
906 VisitedItems visited;
911 : 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()
SubEngine * getOwningEngine()
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:
Expr - 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()
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.
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)
static llvm::ImmutableListFactory< const FieldRegion * > Factory
void setGDM(GenericDataMap gdm)
QualType getType() const
Retrieves the type of the base class.