1 //== ProgramState.h - Path-sensitive "State" for tracking values -*- C++ -*--=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines SymbolRef, ExprBindKey, and ProgramState*.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_GR_VALUESTATE_H
15 #define LLVM_CLANG_GR_VALUESTATE_H
17 #include "clang/Basic/LLVM.h"
18 #include "clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h"
19 #include "clang/StaticAnalyzer/Core/PathSensitive/Environment.h"
20 #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
21 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
22 #include "llvm/ADT/PointerIntPair.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/ADT/ImmutableMap.h"
28 class BumpPtrAllocator;
36 class ProgramStateManager;
38 typedef ConstraintManager* (*ConstraintManagerCreator)(ProgramStateManager&,
40 typedef StoreManager* (*StoreManagerCreator)(ProgramStateManager&);
42 //===----------------------------------------------------------------------===//
43 // ProgramStateTrait - Traits used by the Generic Data Map of a ProgramState.
44 //===----------------------------------------------------------------------===//
46 template <typename T> struct ProgramStatePartialTrait;
48 template <typename T> struct ProgramStateTrait {
49 typedef typename T::data_type data_type;
50 static inline void *GDMIndex() { return &T::TagInt; }
51 static inline void *MakeVoidPtr(data_type D) { return (void*) D; }
52 static inline data_type MakeData(void *const* P) {
53 return P ? (data_type) *P : (data_type) 0;
57 class ProgramStateManager;
59 /// \class ProgramState
60 /// ProgramState - This class encapsulates:
62 /// 1. A mapping from expressions to values (Environment)
63 /// 2. A mapping from locations to values (Store)
64 /// 3. Constraints on symbolic values (GenericDataMap)
66 /// Together these represent the "abstract state" of a program.
68 /// ProgramState is intended to be used as a functional object; that is,
69 /// once it is created and made "persistent" in a FoldingSet, its
70 /// values will never change.
71 class ProgramState : public llvm::FoldingSetNode {
73 typedef llvm::ImmutableSet<llvm::APSInt*> IntSetTy;
74 typedef llvm::ImmutableMap<void*, void*> GenericDataMap;
77 void operator=(const ProgramState& R) const; // Do not implement.
79 friend class ProgramStateManager;
80 friend class ExplodedGraph;
81 friend class ExplodedNode;
83 ProgramStateManager *stateMgr;
84 Environment Env; // Maps a Stmt to its current SVal.
85 Store store; // Maps a location to its current value.
86 GenericDataMap GDM; // Custom data stored by a client of this class.
89 /// makeWithStore - Return a ProgramState with the same values as the current
90 /// state with the exception of using the specified Store.
91 const ProgramState *makeWithStore(const StoreRef &store) const;
93 void setStore(const StoreRef &storeRef);
97 /// This ctor is used when creating the first ProgramState object.
98 ProgramState(ProgramStateManager *mgr, const Environment& env,
99 StoreRef st, GenericDataMap gdm);
101 /// Copy ctor - We must explicitly define this or else the "Next" ptr
102 /// in FoldingSetNode will also get copied.
103 ProgramState(const ProgramState &RHS);
107 /// Return the ProgramStateManager associated with this state.
108 ProgramStateManager &getStateManager() const { return *stateMgr; }
110 /// Return true if this state is referenced by a persistent ExplodedNode.
111 bool referencedByExplodedNode() const { return refCount > 0; }
113 /// getEnvironment - Return the environment associated with this state.
114 /// The environment is the mapping from expressions to values.
115 const Environment& getEnvironment() const { return Env; }
117 /// Return the store associated with this state. The store
118 /// is a mapping from locations to values.
119 Store getStore() const { return store; }
122 /// getGDM - Return the generic data map associated with this state.
123 GenericDataMap getGDM() const { return GDM; }
125 void setGDM(GenericDataMap gdm) { GDM = gdm; }
127 /// Profile - Profile the contents of a ProgramState object for use in a
128 /// FoldingSet. Two ProgramState objects are considered equal if they
129 /// have the same Environment, Store, and GenericDataMap.
130 static void Profile(llvm::FoldingSetNodeID& ID, const ProgramState *V) {
132 ID.AddPointer(V->store);
136 /// Profile - Used to profile the contents of this object for inclusion
138 void Profile(llvm::FoldingSetNodeID& ID) const {
142 BasicValueFactory &getBasicVals() const;
143 SymbolManager &getSymbolManager() const;
145 //==---------------------------------------------------------------------==//
146 // Constraints on values.
147 //==---------------------------------------------------------------------==//
149 // Each ProgramState records constraints on symbolic values. These constraints
150 // are managed using the ConstraintManager associated with a ProgramStateManager.
151 // As constraints gradually accrue on symbolic values, added constraints
152 // may conflict and indicate that a state is infeasible (as no real values
153 // could satisfy all the constraints). This is the principal mechanism
154 // for modeling path-sensitivity in ExprEngine/ProgramState.
156 // Various "assume" methods form the interface for adding constraints to
157 // symbolic values. A call to 'assume' indicates an assumption being placed
158 // on one or symbolic values. 'assume' methods take the following inputs:
160 // (1) A ProgramState object representing the current state.
162 // (2) The assumed constraint (which is specific to a given "assume" method).
164 // (3) A binary value "Assumption" that indicates whether the constraint is
165 // assumed to be true or false.
167 // The output of "assume*" is a new ProgramState object with the added constraints.
168 // If no new state is feasible, NULL is returned.
171 const ProgramState *assume(DefinedOrUnknownSVal cond, bool assumption) const;
173 /// This method assumes both "true" and "false" for 'cond', and
174 /// returns both corresponding states. It's shorthand for doing
176 std::pair<const ProgramState*, const ProgramState*>
177 assume(DefinedOrUnknownSVal cond) const;
179 const ProgramState *assumeInBound(DefinedOrUnknownSVal idx,
180 DefinedOrUnknownSVal upperBound,
181 bool assumption) const;
183 /// Utility method for getting regions.
184 const VarRegion* getRegion(const VarDecl *D, const LocationContext *LC) const;
186 //==---------------------------------------------------------------------==//
187 // Binding and retrieving values to/from the environment and symbolic store.
188 //==---------------------------------------------------------------------==//
190 /// BindCompoundLiteral - Return the state that has the bindings currently
191 /// in this state plus the bindings for the CompoundLiteral.
192 const ProgramState *bindCompoundLiteral(const CompoundLiteralExpr *CL,
193 const LocationContext *LC,
196 /// Create a new state by binding the value 'V' to the statement 'S' in the
197 /// state's environment.
198 const ProgramState *BindExpr(const Stmt *S, SVal V, bool Invalidate = true) const;
200 /// Create a new state by binding the value 'V' and location 'locaton' to the
201 /// statement 'S' in the state's environment.
202 const ProgramState *bindExprAndLocation(const Stmt *S, SVal location, SVal V)
205 const ProgramState *bindDecl(const VarRegion *VR, SVal V) const;
207 const ProgramState *bindDeclWithNoInit(const VarRegion *VR) const;
209 const ProgramState *bindLoc(Loc location, SVal V) const;
211 const ProgramState *bindLoc(SVal location, SVal V) const;
213 const ProgramState *bindDefault(SVal loc, SVal V) const;
215 const ProgramState *unbindLoc(Loc LV) const;
217 /// invalidateRegions - Returns the state with bindings for the given regions
218 /// cleared from the store. The regions are provided as a continuous array
219 /// from Begin to End. Optionally invalidates global regions as well.
220 const ProgramState *invalidateRegions(ArrayRef<const MemRegion *> Regions,
221 const Expr *E, unsigned BlockCount,
222 StoreManager::InvalidatedSymbols *IS = 0,
223 bool invalidateGlobals = false) const;
225 /// enterStackFrame - Returns the state for entry to the given stack frame,
226 /// preserving the current state.
227 const ProgramState *enterStackFrame(const StackFrameContext *frame) const;
229 /// Get the lvalue for a variable reference.
230 Loc getLValue(const VarDecl *D, const LocationContext *LC) const;
232 /// Get the lvalue for a StringLiteral.
233 Loc getLValue(const StringLiteral *literal) const;
235 Loc getLValue(const CompoundLiteralExpr *literal,
236 const LocationContext *LC) const;
238 /// Get the lvalue for an ivar reference.
239 SVal getLValue(const ObjCIvarDecl *decl, SVal base) const;
241 /// Get the lvalue for a field reference.
242 SVal getLValue(const FieldDecl *decl, SVal Base) const;
244 /// Get the lvalue for an array index.
245 SVal getLValue(QualType ElementType, SVal Idx, SVal Base) const;
247 const llvm::APSInt *getSymVal(SymbolRef sym) const;
249 /// Returns the SVal bound to the statement 'S' in the state's environment.
250 SVal getSVal(const Stmt *S, bool useOnlyDirectBindings = false) const;
252 SVal getSValAsScalarOrLoc(const Stmt *Ex) const;
254 SVal getSVal(Loc LV, QualType T = QualType()) const;
256 /// Returns the "raw" SVal bound to LV before any value simplfication.
257 SVal getRawSVal(Loc LV, QualType T= QualType()) const;
259 SVal getSVal(const MemRegion* R) const;
261 SVal getSValAsScalarOrLoc(const MemRegion *R) const;
263 /// \brief Visits the symbols reachable from the given SVal using the provided
266 /// This is a convenience API. Consider using ScanReachableSymbols class
267 /// directly when making multiple scans on the same state with the same
268 /// visitor to avoid repeated initialization cost.
269 /// \sa ScanReachableSymbols
270 bool scanReachableSymbols(SVal val, SymbolVisitor& visitor) const;
272 /// \brief Visits the symbols reachable from the SVals in the given range
273 /// using the provided SymbolVisitor.
274 bool scanReachableSymbols(const SVal *I, const SVal *E,
275 SymbolVisitor &visitor) const;
277 /// \brief Visits the symbols reachable from the regions in the given
278 /// MemRegions range using the provided SymbolVisitor.
279 bool scanReachableSymbols(const MemRegion * const *I,
280 const MemRegion * const *E,
281 SymbolVisitor &visitor) const;
283 template <typename CB> CB scanReachableSymbols(SVal val) const;
284 template <typename CB> CB scanReachableSymbols(const SVal *beg,
285 const SVal *end) const;
287 template <typename CB> CB
288 scanReachableSymbols(const MemRegion * const *beg,
289 const MemRegion * const *end) const;
291 //==---------------------------------------------------------------------==//
292 // Accessing the Generic Data Map (GDM).
293 //==---------------------------------------------------------------------==//
295 void *const* FindGDM(void *K) const;
298 const ProgramState *add(typename ProgramStateTrait<T>::key_type K) const;
300 template <typename T>
301 typename ProgramStateTrait<T>::data_type
303 return ProgramStateTrait<T>::MakeData(FindGDM(ProgramStateTrait<T>::GDMIndex()));
307 typename ProgramStateTrait<T>::lookup_type
308 get(typename ProgramStateTrait<T>::key_type key) const {
309 void *const* d = FindGDM(ProgramStateTrait<T>::GDMIndex());
310 return ProgramStateTrait<T>::Lookup(ProgramStateTrait<T>::MakeData(d), key);
313 template <typename T>
314 typename ProgramStateTrait<T>::context_type get_context() const;
318 const ProgramState *remove(typename ProgramStateTrait<T>::key_type K) const;
321 const ProgramState *remove(typename ProgramStateTrait<T>::key_type K,
322 typename ProgramStateTrait<T>::context_type C) const;
323 template <typename T>
324 const ProgramState *remove() const;
327 const ProgramState *set(typename ProgramStateTrait<T>::data_type D) const;
330 const ProgramState *set(typename ProgramStateTrait<T>::key_type K,
331 typename ProgramStateTrait<T>::value_type E) const;
334 const ProgramState *set(typename ProgramStateTrait<T>::key_type K,
335 typename ProgramStateTrait<T>::value_type E,
336 typename ProgramStateTrait<T>::context_type C) const;
339 bool contains(typename ProgramStateTrait<T>::key_type key) const {
340 void *const* d = FindGDM(ProgramStateTrait<T>::GDMIndex());
341 return ProgramStateTrait<T>::Contains(ProgramStateTrait<T>::MakeData(d), key);
345 void print(raw_ostream &Out, CFG &C, const char *nl = "\n",
346 const char *sep = "") const;
348 void printStdErr(CFG &C) const;
350 void printDOT(raw_ostream &Out, CFG &C) const;
353 /// Increments the number of times this state is referenced by ExplodeNodes.
354 void incrementReferenceCount() { ++refCount; }
356 /// Decrement the number of times this state is referenced by ExplodeNodes.
357 void decrementReferenceCount() {
358 assert(refCount > 0);
363 invalidateRegionsImpl(ArrayRef<const MemRegion *> Regions,
364 const Expr *E, unsigned BlockCount,
365 StoreManager::InvalidatedSymbols &IS,
366 bool invalidateGlobals) const;
369 class ProgramStateSet {
370 typedef llvm::SmallPtrSet<const ProgramState*,5> ImplTy;
375 inline void Add(const ProgramState *St) {
379 typedef ImplTy::const_iterator iterator;
381 inline unsigned size() const { return Impl.size(); }
382 inline bool empty() const { return Impl.empty(); }
384 inline iterator begin() const { return Impl.begin(); }
385 inline iterator end() const { return Impl.end(); }
390 const ProgramState *St;
392 AutoPopulate(ProgramStateSet &s, const ProgramState *st)
393 : S(s), StartSize(S.size()), St(st) {}
396 if (StartSize == S.size())
402 //===----------------------------------------------------------------------===//
403 // ProgramStateManager - Factory object for ProgramStates.
404 //===----------------------------------------------------------------------===//
406 class ProgramStateManager {
407 friend class ProgramState;
409 /// Eng - The SubEngine that owns this state manager.
410 SubEngine *Eng; /* Can be null. */
412 EnvironmentManager EnvMgr;
413 llvm::OwningPtr<StoreManager> StoreMgr;
414 llvm::OwningPtr<ConstraintManager> ConstraintMgr;
416 ProgramState::GenericDataMap::Factory GDMFactory;
418 typedef llvm::DenseMap<void*,std::pair<void*,void (*)(void*)> > GDMContextsTy;
419 GDMContextsTy GDMContexts;
421 /// StateSet - FoldingSet containing all the states created for analyzing
422 /// a particular function. This is used to unique states.
423 llvm::FoldingSet<ProgramState> StateSet;
425 /// Object that manages the data for all created SVals.
426 llvm::OwningPtr<SValBuilder> svalBuilder;
428 /// A BumpPtrAllocator to allocate states.
429 llvm::BumpPtrAllocator &Alloc;
431 /// A vector of recently allocated ProgramStates that can potentially be
433 std::vector<ProgramState *> recentlyAllocatedStates;
435 /// A vector of ProgramStates that we can reuse.
436 std::vector<ProgramState *> freeStates;
439 ProgramStateManager(ASTContext &Ctx,
440 StoreManagerCreator CreateStoreManager,
441 ConstraintManagerCreator CreateConstraintManager,
442 llvm::BumpPtrAllocator& alloc,
447 svalBuilder(createSimpleSValBuilder(alloc, Ctx, *this)),
449 StoreMgr.reset((*CreateStoreManager)(*this));
450 ConstraintMgr.reset((*CreateConstraintManager)(*this, subeng));
453 ProgramStateManager(ASTContext &Ctx,
454 StoreManagerCreator CreateStoreManager,
455 ConstraintManager* ConstraintManagerPtr,
456 llvm::BumpPtrAllocator& alloc)
460 svalBuilder(createSimpleSValBuilder(alloc, Ctx, *this)),
462 StoreMgr.reset((*CreateStoreManager)(*this));
463 ConstraintMgr.reset(ConstraintManagerPtr);
466 ~ProgramStateManager();
468 const ProgramState *getInitialState(const LocationContext *InitLoc);
470 ASTContext &getContext() { return svalBuilder->getContext(); }
471 const ASTContext &getContext() const { return svalBuilder->getContext(); }
473 BasicValueFactory &getBasicVals() {
474 return svalBuilder->getBasicValueFactory();
476 const BasicValueFactory& getBasicVals() const {
477 return svalBuilder->getBasicValueFactory();
480 SValBuilder &getSValBuilder() {
484 SymbolManager &getSymbolManager() {
485 return svalBuilder->getSymbolManager();
487 const SymbolManager &getSymbolManager() const {
488 return svalBuilder->getSymbolManager();
491 llvm::BumpPtrAllocator& getAllocator() { return Alloc; }
493 MemRegionManager& getRegionManager() {
494 return svalBuilder->getRegionManager();
496 const MemRegionManager& getRegionManager() const {
497 return svalBuilder->getRegionManager();
500 StoreManager& getStoreManager() { return *StoreMgr; }
501 ConstraintManager& getConstraintManager() { return *ConstraintMgr; }
502 SubEngine* getOwningEngine() { return Eng; }
504 const ProgramState *removeDeadBindings(const ProgramState *St,
505 const StackFrameContext *LCtx,
506 SymbolReaper& SymReaper);
508 /// Marshal a new state for the callee in another translation unit.
509 /// 'state' is owned by the caller's engine.
510 const ProgramState *MarshalState(const ProgramState *state, const StackFrameContext *L);
514 SVal ArrayToPointer(Loc Array) {
515 return StoreMgr->ArrayToPointer(Array);
518 // Methods that manipulate the GDM.
519 const ProgramState *addGDM(const ProgramState *St, void *Key, void *Data);
520 const ProgramState *removeGDM(const ProgramState *state, void *Key);
522 // Methods that query & manipulate the Store.
524 void iterBindings(const ProgramState *state, StoreManager::BindingsHandler& F) {
525 StoreMgr->iterBindings(state->getStore(), F);
528 const ProgramState *getPersistentState(ProgramState &Impl);
529 const ProgramState *getPersistentStateWithGDM(const ProgramState *FromState,
530 const ProgramState *GDMState);
532 bool haveEqualEnvironments(const ProgramState * S1, const ProgramState * S2) {
533 return S1->Env == S2->Env;
536 bool haveEqualStores(const ProgramState * S1, const ProgramState * S2) {
537 return S1->store == S2->store;
540 /// Periodically called by ExprEngine to recycle ProgramStates that were
541 /// created but never used for creating an ExplodedNode.
542 void recycleUnusedStates();
544 //==---------------------------------------------------------------------==//
545 // Generic Data Map methods.
546 //==---------------------------------------------------------------------==//
548 // ProgramStateManager and ProgramState support a "generic data map" that allows
549 // different clients of ProgramState objects to embed arbitrary data within a
550 // ProgramState object. The generic data map is essentially an immutable map
551 // from a "tag" (that acts as the "key" for a client) and opaque values.
552 // Tags/keys and values are simply void* values. The typical way that clients
553 // generate unique tags are by taking the address of a static variable.
554 // Clients are responsible for ensuring that data values referred to by a
555 // the data pointer are immutable (and thus are essentially purely functional
558 // The templated methods below use the ProgramStateTrait<T> class
559 // to resolve keys into the GDM and to return data values to clients.
562 // Trait based GDM dispatch.
563 template <typename T>
564 const ProgramState *set(const ProgramState *st, typename ProgramStateTrait<T>::data_type D) {
565 return addGDM(st, ProgramStateTrait<T>::GDMIndex(),
566 ProgramStateTrait<T>::MakeVoidPtr(D));
570 const ProgramState *set(const ProgramState *st,
571 typename ProgramStateTrait<T>::key_type K,
572 typename ProgramStateTrait<T>::value_type V,
573 typename ProgramStateTrait<T>::context_type C) {
575 return addGDM(st, ProgramStateTrait<T>::GDMIndex(),
576 ProgramStateTrait<T>::MakeVoidPtr(ProgramStateTrait<T>::Set(st->get<T>(), K, V, C)));
579 template <typename T>
580 const ProgramState *add(const ProgramState *st,
581 typename ProgramStateTrait<T>::key_type K,
582 typename ProgramStateTrait<T>::context_type C) {
583 return addGDM(st, ProgramStateTrait<T>::GDMIndex(),
584 ProgramStateTrait<T>::MakeVoidPtr(ProgramStateTrait<T>::Add(st->get<T>(), K, C)));
587 template <typename T>
588 const ProgramState *remove(const ProgramState *st,
589 typename ProgramStateTrait<T>::key_type K,
590 typename ProgramStateTrait<T>::context_type C) {
592 return addGDM(st, ProgramStateTrait<T>::GDMIndex(),
593 ProgramStateTrait<T>::MakeVoidPtr(ProgramStateTrait<T>::Remove(st->get<T>(), K, C)));
596 template <typename T>
597 const ProgramState *remove(const ProgramState *st) {
598 return removeGDM(st, ProgramStateTrait<T>::GDMIndex());
601 void *FindGDMContext(void *index,
602 void *(*CreateContext)(llvm::BumpPtrAllocator&),
603 void (*DeleteContext)(void*));
605 template <typename T>
606 typename ProgramStateTrait<T>::context_type get_context() {
607 void *p = FindGDMContext(ProgramStateTrait<T>::GDMIndex(),
608 ProgramStateTrait<T>::CreateContext,
609 ProgramStateTrait<T>::DeleteContext);
611 return ProgramStateTrait<T>::MakeContext(p);
614 const llvm::APSInt* getSymVal(const ProgramState *St, SymbolRef sym) {
615 return ConstraintMgr->getSymVal(St, sym);
618 void EndPath(const ProgramState *St) {
619 ConstraintMgr->EndPath(St);
624 //===----------------------------------------------------------------------===//
625 // Out-of-line method definitions for ProgramState.
626 //===----------------------------------------------------------------------===//
628 inline const VarRegion* ProgramState::getRegion(const VarDecl *D,
629 const LocationContext *LC) const {
630 return getStateManager().getRegionManager().getVarRegion(D, LC);
633 inline const ProgramState *ProgramState::assume(DefinedOrUnknownSVal Cond,
634 bool Assumption) const {
635 if (Cond.isUnknown())
638 return getStateManager().ConstraintMgr->assume(this, cast<DefinedSVal>(Cond),
642 inline std::pair<const ProgramState*, const ProgramState*>
643 ProgramState::assume(DefinedOrUnknownSVal Cond) const {
644 if (Cond.isUnknown())
645 return std::make_pair(this, this);
647 return getStateManager().ConstraintMgr->assumeDual(this,
648 cast<DefinedSVal>(Cond));
651 inline const ProgramState *ProgramState::bindLoc(SVal LV, SVal V) const {
652 return !isa<Loc>(LV) ? this : bindLoc(cast<Loc>(LV), V);
655 inline Loc ProgramState::getLValue(const VarDecl *VD,
656 const LocationContext *LC) const {
657 return getStateManager().StoreMgr->getLValueVar(VD, LC);
660 inline Loc ProgramState::getLValue(const StringLiteral *literal) const {
661 return getStateManager().StoreMgr->getLValueString(literal);
664 inline Loc ProgramState::getLValue(const CompoundLiteralExpr *literal,
665 const LocationContext *LC) const {
666 return getStateManager().StoreMgr->getLValueCompoundLiteral(literal, LC);
669 inline SVal ProgramState::getLValue(const ObjCIvarDecl *D, SVal Base) const {
670 return getStateManager().StoreMgr->getLValueIvar(D, Base);
673 inline SVal ProgramState::getLValue(const FieldDecl *D, SVal Base) const {
674 return getStateManager().StoreMgr->getLValueField(D, Base);
677 inline SVal ProgramState::getLValue(QualType ElementType, SVal Idx, SVal Base) const{
678 if (NonLoc *N = dyn_cast<NonLoc>(&Idx))
679 return getStateManager().StoreMgr->getLValueElement(ElementType, *N, Base);
683 inline const llvm::APSInt *ProgramState::getSymVal(SymbolRef sym) const {
684 return getStateManager().getSymVal(this, sym);
687 inline SVal ProgramState::getSVal(const Stmt *Ex, bool useOnlyDirectBindings) const{
688 return Env.getSVal(Ex, *getStateManager().svalBuilder,
689 useOnlyDirectBindings);
692 inline SVal ProgramState::getSValAsScalarOrLoc(const Stmt *S) const {
693 if (const Expr *Ex = dyn_cast<Expr>(S)) {
694 QualType T = Ex->getType();
695 if (Ex->isLValue() || Loc::isLocType(T) || T->isIntegerType())
702 inline SVal ProgramState::getRawSVal(Loc LV, QualType T) const {
703 return getStateManager().StoreMgr->Retrieve(getStore(), LV, T);
706 inline SVal ProgramState::getSVal(const MemRegion* R) const {
707 return getStateManager().StoreMgr->Retrieve(getStore(), loc::MemRegionVal(R));
710 inline BasicValueFactory &ProgramState::getBasicVals() const {
711 return getStateManager().getBasicVals();
714 inline SymbolManager &ProgramState::getSymbolManager() const {
715 return getStateManager().getSymbolManager();
719 const ProgramState *ProgramState::add(typename ProgramStateTrait<T>::key_type K) const {
720 return getStateManager().add<T>(this, K, get_context<T>());
723 template <typename T>
724 typename ProgramStateTrait<T>::context_type ProgramState::get_context() const {
725 return getStateManager().get_context<T>();
729 const ProgramState *ProgramState::remove(typename ProgramStateTrait<T>::key_type K) const {
730 return getStateManager().remove<T>(this, K, get_context<T>());
734 const ProgramState *ProgramState::remove(typename ProgramStateTrait<T>::key_type K,
735 typename ProgramStateTrait<T>::context_type C) const {
736 return getStateManager().remove<T>(this, K, C);
739 template <typename T>
740 const ProgramState *ProgramState::remove() const {
741 return getStateManager().remove<T>(this);
745 const ProgramState *ProgramState::set(typename ProgramStateTrait<T>::data_type D) const {
746 return getStateManager().set<T>(this, D);
750 const ProgramState *ProgramState::set(typename ProgramStateTrait<T>::key_type K,
751 typename ProgramStateTrait<T>::value_type E) const {
752 return getStateManager().set<T>(this, K, E, get_context<T>());
756 const ProgramState *ProgramState::set(typename ProgramStateTrait<T>::key_type K,
757 typename ProgramStateTrait<T>::value_type E,
758 typename ProgramStateTrait<T>::context_type C) const {
759 return getStateManager().set<T>(this, K, E, C);
762 template <typename CB>
763 CB ProgramState::scanReachableSymbols(SVal val) const {
765 scanReachableSymbols(val, cb);
769 template <typename CB>
770 CB ProgramState::scanReachableSymbols(const SVal *beg, const SVal *end) const {
772 scanReachableSymbols(beg, end, cb);
776 template <typename CB>
777 CB ProgramState::scanReachableSymbols(const MemRegion * const *beg,
778 const MemRegion * const *end) const {
780 scanReachableSymbols(beg, end, cb);
784 /// \class ScanReachableSymbols
785 /// A Utility class that allows to visit the reachable symbols using a custom
787 class ScanReachableSymbols : public SubRegionMap::Visitor {
788 typedef llvm::DenseMap<const void*, unsigned> VisitedItems;
790 VisitedItems visited;
791 const ProgramState *state;
792 SymbolVisitor &visitor;
793 llvm::OwningPtr<SubRegionMap> SRM;
796 ScanReachableSymbols(const ProgramState *st, SymbolVisitor& v)
797 : state(st), visitor(v) {}
799 bool scan(nonloc::CompoundVal val);
801 bool scan(const MemRegion *R);
802 bool scan(const SymExpr *sym);
804 // From SubRegionMap::Visitor.
805 bool Visit(const MemRegion* Parent, const MemRegion* SubRegion) {
806 return scan(SubRegion);
810 } // end GR namespace
812 } // end clang namespace