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" 40 class CallEventManager;
42 typedef std::unique_ptr<ConstraintManager>(*ConstraintManagerCreator)(
44 typedef std::unique_ptr<StoreManager>(*StoreManagerCreator)(
45 ProgramStateManager &);
56 static inline void *
MakeVoidPtr(data_type D) {
return (
void*) D; }
58 return P ? (data_type) *P : (data_type) 0;
82 friend class ProgramStateManager;
86 ProgramStateManager *stateMgr;
96 void setStore(
const StoreRef &storeRef);
127 GenericDataMap
getGDM()
const {
return GDM; }
129 void setGDM(GenericDataMap gdm) { GDM = gdm; }
136 ID.AddPointer(V->store);
187 std::pair<ProgramStateRef, ProgramStateRef>
202 const llvm::APSInt &From,
203 const llvm::APSInt &To,
204 bool assumption)
const;
211 std::pair<ProgramStateRef, ProgramStateRef>
213 const llvm::APSInt &To)
const;
229 SVal V,
bool Invalidate =
true)
const;
234 bool notifyChanges =
true)
const;
330 bool scanReachableSymbols(
const SVal *I,
const SVal *E,
335 bool scanReachableSymbols(
const MemRegion *
const *I,
339 template <
typename CB> CB scanReachableSymbols(
SVal val)
const;
340 template <
typename CB> CB scanReachableSymbols(
const SVal *beg,
341 const SVal *end)
const;
343 template <
typename CB> CB
344 scanReachableSymbols(
const MemRegion *
const *beg,
381 void *
const* FindGDM(
void *K)
const;
386 template <
typename T>
399 template <
typename T>
409 template <
typename T>
431 void print(raw_ostream &Out,
const char *nl =
"\n",
432 const char *sep =
"")
const;
433 void printDOT(raw_ostream &Out)
const;
434 void printTaint(raw_ostream &Out,
const char *nl =
"\n",
435 const char *sep =
"")
const;
438 void dumpTaint()
const;
448 const Expr *E,
unsigned BlockCount,
450 bool ResultsInSymbolEscape,
460 class ProgramStateManager {
468 std::unique_ptr<StoreManager> StoreMgr;
469 std::unique_ptr<ConstraintManager> ConstraintMgr;
471 ProgramState::GenericDataMap::Factory GDMFactory;
472 TaintedSubRegions::Factory TSRFactory;
474 typedef llvm::DenseMap<void*,std::pair<void*,void (*)(void*)> > GDMContextsTy;
475 GDMContextsTy GDMContexts;
479 llvm::FoldingSet<ProgramState> StateSet;
482 std::unique_ptr<SValBuilder> svalBuilder;
485 std::unique_ptr<CallEventManager> CallEventMgr;
488 llvm::BumpPtrAllocator &Alloc;
491 std::vector<ProgramState *> freeStates;
497 llvm::BumpPtrAllocator& alloc,
500 ~ProgramStateManager();
508 return svalBuilder->getBasicValueFactory();
516 return svalBuilder->getSymbolManager();
519 return svalBuilder->getSymbolManager();
525 return svalBuilder->getRegionManager();
528 return svalBuilder->getRegionManager();
544 return StoreMgr->ArrayToPointer(Array, ElementTy);
554 StoreMgr->iterBindings(state->getStore(), F);
562 return S1->Env == S2->Env;
566 return S1->store == S2->store;
588 template <
typename T>
604 template <
typename T>
612 template <
typename T>
621 template <
typename T>
626 void *FindGDMContext(
void *index,
627 void *(*CreateContext)(llvm::BumpPtrAllocator&),
628 void (*DeleteContext)(
void*));
630 template <
typename T>
640 ConstraintMgr->EndPath(St);
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>
691 const llvm::APSInt &From,
692 const llvm::APSInt &To)
const {
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);
710 return getStateManager().StoreMgr->getLValueVar(VD, LC);
715 return getStateManager().StoreMgr->getLValueCompoundLiteral(literal, LC);
719 return getStateManager().StoreMgr->getLValueIvar(D, Base);
723 return getStateManager().StoreMgr->getLValueField(D, Base);
729 for (
const auto *I : D->
chain()) {
738 return getStateManager().StoreMgr->getLValueElement(ElementType, *N, Base);
745 *getStateManager().svalBuilder);
749 ProgramState::getSValAsScalarOrLoc(
const Stmt *S,
751 if (
const Expr *Ex = dyn_cast<Expr>(S)) {
753 if (Ex->isGLValue() || Loc::isLocType(T) ||
755 return getSVal(S, LCtx);
762 return getStateManager().StoreMgr->getBinding(getStore(), LV, T);
766 return getStateManager().StoreMgr->getBinding(getStore(),
772 return getStateManager().getBasicVals();
776 return getStateManager().getSymbolManager();
781 return getStateManager().add<
T>(
this, K, get_context<T>());
784 template <
typename T>
786 return getStateManager().get_context<
T>();
791 return getStateManager().remove<
T>(
this, K, get_context<T>());
797 return getStateManager().remove<
T>(
this, K,
C);
800 template <
typename T>
802 return getStateManager().remove<
T>(
this);
807 return getStateManager().set<
T>(
this, D);
813 return getStateManager().set<
T>(
this, K, E, get_context<T>());
820 return getStateManager().set<
T>(
this, K, E,
C);
823 template <
typename CB>
824 CB ProgramState::scanReachableSymbols(
SVal val)
const {
826 scanReachableSymbols(val, cb);
830 template <
typename CB>
831 CB ProgramState::scanReachableSymbols(
const SVal *beg,
const SVal *end)
const {
833 scanReachableSymbols(beg, end, cb);
837 template <
typename CB>
838 CB ProgramState::scanReachableSymbols(
const MemRegion *
const *beg,
841 scanReachableSymbols(beg, end, cb);
852 VisitedItems visited;
857 : 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
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
A utility class that visits the reachable symbols using a custom SymbolVisitor.
bool haveEqualEnvironments(ProgramStateRef S1, ProgramStateRef S2)
VarDecl - An instance of this class is created to represent a variable declaration or definition...
CompoundLiteralExpr - [C99 6.5.2.5].
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 ...
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
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)
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.
unsigned TaintTagType
The type of taint, which helps to differentiate between different types of taint. ...
ProgramState - This class encapsulates:
Expr - This represents one expression.
const FunctionProtoType * T
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)
IndirectFieldDecl - An instance of this class is created to represent a field injected from an anonym...
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.
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)