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 the state of the program along the analysisa path.
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/DynamicTypeInfo.h"
20 #include "clang/StaticAnalyzer/Core/PathSensitive/Environment.h"
21 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
22 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
23 #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
24 #include "clang/StaticAnalyzer/Core/PathSensitive/TaintTag.h"
25 #include "llvm/ADT/FoldingSet.h"
26 #include "llvm/ADT/ImmutableMap.h"
27 #include "llvm/ADT/PointerIntPair.h"
31 class BumpPtrAllocator;
40 class CallEventManager;
42 typedef ConstraintManager* (*ConstraintManagerCreator)(ProgramStateManager&,
44 typedef StoreManager* (*StoreManagerCreator)(ProgramStateManager&);
46 //===----------------------------------------------------------------------===//
47 // ProgramStateTrait - Traits used by the Generic Data Map of a ProgramState.
48 //===----------------------------------------------------------------------===//
50 template <typename T> struct ProgramStatePartialTrait;
52 template <typename T> struct ProgramStateTrait {
53 typedef typename T::data_type data_type;
54 static inline void *MakeVoidPtr(data_type D) { return (void*) D; }
55 static inline data_type MakeData(void *const* P) {
56 return P ? (data_type) *P : (data_type) 0;
60 /// \class ProgramState
61 /// ProgramState - This class encapsulates:
63 /// 1. A mapping from expressions to values (Environment)
64 /// 2. A mapping from locations to values (Store)
65 /// 3. Constraints on symbolic values (GenericDataMap)
67 /// Together these represent the "abstract state" of a program.
69 /// ProgramState is intended to be used as a functional object; that is,
70 /// once it is created and made "persistent" in a FoldingSet, its
71 /// values will never change.
72 class ProgramState : public llvm::FoldingSetNode {
74 typedef llvm::ImmutableSet<llvm::APSInt*> IntSetTy;
75 typedef llvm::ImmutableMap<void*, void*> GenericDataMap;
78 void operator=(const ProgramState& R) LLVM_DELETED_FUNCTION;
80 friend class ProgramStateManager;
81 friend class ExplodedGraph;
82 friend class ExplodedNode;
84 ProgramStateManager *stateMgr;
85 Environment Env; // Maps a Stmt to its current SVal.
86 Store store; // Maps a location to its current value.
87 GenericDataMap GDM; // Custom data stored by a client of this class.
90 /// makeWithStore - Return a ProgramState with the same values as the current
91 /// state with the exception of using the specified Store.
92 ProgramStateRef makeWithStore(const StoreRef &store) const;
94 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 {
112 /// Return the ConstraintManager.
113 ConstraintManager &getConstraintManager() const;
115 /// getEnvironment - Return the environment associated with this state.
116 /// The environment is the mapping from expressions to values.
117 const Environment& getEnvironment() const { return Env; }
119 /// Return the store associated with this state. The store
120 /// is a mapping from locations to values.
121 Store getStore() const { return store; }
124 /// getGDM - Return the generic data map associated with this state.
125 GenericDataMap getGDM() const { return GDM; }
127 void setGDM(GenericDataMap gdm) { GDM = gdm; }
129 /// Profile - Profile the contents of a ProgramState object for use in a
130 /// FoldingSet. Two ProgramState objects are considered equal if they
131 /// have the same Environment, Store, and GenericDataMap.
132 static void Profile(llvm::FoldingSetNodeID& ID, const ProgramState *V) {
134 ID.AddPointer(V->store);
138 /// Profile - Used to profile the contents of this object for inclusion
140 void Profile(llvm::FoldingSetNodeID& ID) const {
144 BasicValueFactory &getBasicVals() const;
145 SymbolManager &getSymbolManager() const;
147 //==---------------------------------------------------------------------==//
148 // Constraints on values.
149 //==---------------------------------------------------------------------==//
151 // Each ProgramState records constraints on symbolic values. These constraints
152 // are managed using the ConstraintManager associated with a ProgramStateManager.
153 // As constraints gradually accrue on symbolic values, added constraints
154 // may conflict and indicate that a state is infeasible (as no real values
155 // could satisfy all the constraints). This is the principal mechanism
156 // for modeling path-sensitivity in ExprEngine/ProgramState.
158 // Various "assume" methods form the interface for adding constraints to
159 // symbolic values. A call to 'assume' indicates an assumption being placed
160 // on one or symbolic values. 'assume' methods take the following inputs:
162 // (1) A ProgramState object representing the current state.
164 // (2) The assumed constraint (which is specific to a given "assume" method).
166 // (3) A binary value "Assumption" that indicates whether the constraint is
167 // assumed to be true or false.
169 // The output of "assume*" is a new ProgramState object with the added constraints.
170 // If no new state is feasible, NULL is returned.
173 /// Assumes that the value of \p cond is zero (if \p assumption is "false")
174 /// or non-zero (if \p assumption is "true").
176 /// This returns a new state with the added constraint on \p cond.
177 /// If no new state is feasible, NULL is returned.
178 ProgramStateRef assume(DefinedOrUnknownSVal cond, bool assumption) const;
180 /// Assumes both "true" and "false" for \p cond, and returns both
181 /// corresponding states (respectively).
183 /// This is more efficient than calling assume() twice. Note that one (but not
184 /// both) of the returned states may be NULL.
185 std::pair<ProgramStateRef, ProgramStateRef>
186 assume(DefinedOrUnknownSVal cond) const;
188 ProgramStateRef assumeInBound(DefinedOrUnknownSVal idx,
189 DefinedOrUnknownSVal upperBound,
191 QualType IndexType = QualType()) const;
193 /// \brief Check if the given SVal is constrained to zero or is a zero
195 ConditionTruthVal isNull(SVal V) const;
197 /// Utility method for getting regions.
198 const VarRegion* getRegion(const VarDecl *D, const LocationContext *LC) const;
200 //==---------------------------------------------------------------------==//
201 // Binding and retrieving values to/from the environment and symbolic store.
202 //==---------------------------------------------------------------------==//
204 /// Create a new state by binding the value 'V' to the statement 'S' in the
205 /// state's environment.
206 ProgramStateRef BindExpr(const Stmt *S, const LocationContext *LCtx,
207 SVal V, bool Invalidate = true) const;
209 ProgramStateRef bindLoc(Loc location,
211 bool notifyChanges = true) const;
213 ProgramStateRef bindLoc(SVal location, SVal V) const;
215 ProgramStateRef bindDefault(SVal loc, SVal V) const;
217 ProgramStateRef killBinding(Loc LV) const;
219 /// \brief Returns the state with bindings for the given regions
220 /// cleared from the store.
222 /// Optionally invalidates global regions as well.
224 /// \param Regions the set of regions to be invalidated.
225 /// \param E the expression that caused the invalidation.
226 /// \param BlockCount The number of times the current basic block has been
228 /// \param CausesPointerEscape the flag is set to true when
229 /// the invalidation entails escape of a symbol (representing a
230 /// pointer). For example, due to it being passed as an argument in a
232 /// \param IS the set of invalidated symbols.
233 /// \param Call if non-null, the invalidated regions represent parameters to
234 /// the call and should be considered directly invalidated.
235 /// \param ITraits information about special handling for a particular
238 invalidateRegions(ArrayRef<const MemRegion *> Regions, const Expr *E,
239 unsigned BlockCount, const LocationContext *LCtx,
240 bool CausesPointerEscape, InvalidatedSymbols *IS = 0,
241 const CallEvent *Call = 0,
242 RegionAndSymbolInvalidationTraits *ITraits = 0) const;
245 invalidateRegions(ArrayRef<SVal> Regions, const Expr *E,
246 unsigned BlockCount, const LocationContext *LCtx,
247 bool CausesPointerEscape, InvalidatedSymbols *IS = 0,
248 const CallEvent *Call = 0,
249 RegionAndSymbolInvalidationTraits *ITraits = 0) const;
251 /// enterStackFrame - Returns the state for entry to the given stack frame,
252 /// preserving the current state.
253 ProgramStateRef enterStackFrame(const CallEvent &Call,
254 const StackFrameContext *CalleeCtx) const;
256 /// Get the lvalue for a variable reference.
257 Loc getLValue(const VarDecl *D, const LocationContext *LC) const;
259 Loc getLValue(const CompoundLiteralExpr *literal,
260 const LocationContext *LC) const;
262 /// Get the lvalue for an ivar reference.
263 SVal getLValue(const ObjCIvarDecl *decl, SVal base) const;
265 /// Get the lvalue for a field reference.
266 SVal getLValue(const FieldDecl *decl, SVal Base) const;
268 /// Get the lvalue for an indirect field reference.
269 SVal getLValue(const IndirectFieldDecl *decl, SVal Base) const;
271 /// Get the lvalue for an array index.
272 SVal getLValue(QualType ElementType, SVal Idx, SVal Base) const;
274 /// Returns the SVal bound to the statement 'S' in the state's environment.
275 SVal getSVal(const Stmt *S, const LocationContext *LCtx) const;
277 SVal getSValAsScalarOrLoc(const Stmt *Ex, const LocationContext *LCtx) const;
279 /// \brief Return the value bound to the specified location.
280 /// Returns UnknownVal() if none found.
281 SVal getSVal(Loc LV, QualType T = QualType()) const;
283 /// Returns the "raw" SVal bound to LV before any value simplfication.
284 SVal getRawSVal(Loc LV, QualType T= QualType()) const;
286 /// \brief Return the value bound to the specified location.
287 /// Returns UnknownVal() if none found.
288 SVal getSVal(const MemRegion* R) const;
290 SVal getSValAsScalarOrLoc(const MemRegion *R) const;
292 /// \brief Visits the symbols reachable from the given SVal using the provided
295 /// This is a convenience API. Consider using ScanReachableSymbols class
296 /// directly when making multiple scans on the same state with the same
297 /// visitor to avoid repeated initialization cost.
298 /// \sa ScanReachableSymbols
299 bool scanReachableSymbols(SVal val, SymbolVisitor& visitor) const;
301 /// \brief Visits the symbols reachable from the SVals in the given range
302 /// using the provided SymbolVisitor.
303 bool scanReachableSymbols(const SVal *I, const SVal *E,
304 SymbolVisitor &visitor) const;
306 /// \brief Visits the symbols reachable from the regions in the given
307 /// MemRegions range using the provided SymbolVisitor.
308 bool scanReachableSymbols(const MemRegion * const *I,
309 const MemRegion * const *E,
310 SymbolVisitor &visitor) const;
312 template <typename CB> CB scanReachableSymbols(SVal val) const;
313 template <typename CB> CB scanReachableSymbols(const SVal *beg,
314 const SVal *end) const;
316 template <typename CB> CB
317 scanReachableSymbols(const MemRegion * const *beg,
318 const MemRegion * const *end) const;
320 /// Create a new state in which the statement is marked as tainted.
321 ProgramStateRef addTaint(const Stmt *S, const LocationContext *LCtx,
322 TaintTagType Kind = TaintTagGeneric) const;
324 /// Create a new state in which the symbol is marked as tainted.
325 ProgramStateRef addTaint(SymbolRef S,
326 TaintTagType Kind = TaintTagGeneric) const;
328 /// Create a new state in which the region symbol is marked as tainted.
329 ProgramStateRef addTaint(const MemRegion *R,
330 TaintTagType Kind = TaintTagGeneric) const;
332 /// Check if the statement is tainted in the current state.
333 bool isTainted(const Stmt *S, const LocationContext *LCtx,
334 TaintTagType Kind = TaintTagGeneric) const;
335 bool isTainted(SVal V, TaintTagType Kind = TaintTagGeneric) const;
336 bool isTainted(SymbolRef Sym, TaintTagType Kind = TaintTagGeneric) const;
337 bool isTainted(const MemRegion *Reg, TaintTagType Kind=TaintTagGeneric) const;
339 /// \brief Get dynamic type information for a region.
340 DynamicTypeInfo getDynamicTypeInfo(const MemRegion *Reg) const;
342 /// \brief Set dynamic type information of the region; return the new state.
343 ProgramStateRef setDynamicTypeInfo(const MemRegion *Reg,
344 DynamicTypeInfo NewTy) const;
346 /// \brief Set dynamic type information of the region; return the new state.
347 ProgramStateRef setDynamicTypeInfo(const MemRegion *Reg,
349 bool CanBeSubClassed = true) const {
350 return setDynamicTypeInfo(Reg, DynamicTypeInfo(NewTy, CanBeSubClassed));
353 //==---------------------------------------------------------------------==//
354 // Accessing the Generic Data Map (GDM).
355 //==---------------------------------------------------------------------==//
357 void *const* FindGDM(void *K) const;
360 ProgramStateRef add(typename ProgramStateTrait<T>::key_type K) const;
362 template <typename T>
363 typename ProgramStateTrait<T>::data_type
365 return ProgramStateTrait<T>::MakeData(FindGDM(ProgramStateTrait<T>::GDMIndex()));
369 typename ProgramStateTrait<T>::lookup_type
370 get(typename ProgramStateTrait<T>::key_type key) const {
371 void *const* d = FindGDM(ProgramStateTrait<T>::GDMIndex());
372 return ProgramStateTrait<T>::Lookup(ProgramStateTrait<T>::MakeData(d), key);
375 template <typename T>
376 typename ProgramStateTrait<T>::context_type get_context() const;
380 ProgramStateRef remove(typename ProgramStateTrait<T>::key_type K) const;
383 ProgramStateRef remove(typename ProgramStateTrait<T>::key_type K,
384 typename ProgramStateTrait<T>::context_type C) const;
385 template <typename T>
386 ProgramStateRef remove() const;
389 ProgramStateRef set(typename ProgramStateTrait<T>::data_type D) const;
392 ProgramStateRef set(typename ProgramStateTrait<T>::key_type K,
393 typename ProgramStateTrait<T>::value_type E) const;
396 ProgramStateRef set(typename ProgramStateTrait<T>::key_type K,
397 typename ProgramStateTrait<T>::value_type E,
398 typename ProgramStateTrait<T>::context_type C) const;
401 bool contains(typename ProgramStateTrait<T>::key_type key) const {
402 void *const* d = FindGDM(ProgramStateTrait<T>::GDMIndex());
403 return ProgramStateTrait<T>::Contains(ProgramStateTrait<T>::MakeData(d), key);
407 void print(raw_ostream &Out, const char *nl = "\n",
408 const char *sep = "") const;
409 void printDOT(raw_ostream &Out) const;
410 void printTaint(raw_ostream &Out, const char *nl = "\n",
411 const char *sep = "") const;
414 void dumpTaint() const;
417 friend void ProgramStateRetain(const ProgramState *state);
418 friend void ProgramStateRelease(const ProgramState *state);
420 /// \sa invalidateValues()
421 /// \sa invalidateRegions()
423 invalidateRegionsImpl(ArrayRef<SVal> Values,
424 const Expr *E, unsigned BlockCount,
425 const LocationContext *LCtx,
426 bool ResultsInSymbolEscape,
427 InvalidatedSymbols *IS,
428 RegionAndSymbolInvalidationTraits *HTraits,
429 const CallEvent *Call) const;
432 //===----------------------------------------------------------------------===//
433 // ProgramStateManager - Factory object for ProgramStates.
434 //===----------------------------------------------------------------------===//
436 class ProgramStateManager {
437 friend class ProgramState;
438 friend void ProgramStateRelease(const ProgramState *state);
440 /// Eng - The SubEngine that owns this state manager.
441 SubEngine *Eng; /* Can be null. */
443 EnvironmentManager EnvMgr;
444 OwningPtr<StoreManager> StoreMgr;
445 OwningPtr<ConstraintManager> ConstraintMgr;
447 ProgramState::GenericDataMap::Factory GDMFactory;
449 typedef llvm::DenseMap<void*,std::pair<void*,void (*)(void*)> > GDMContextsTy;
450 GDMContextsTy GDMContexts;
452 /// StateSet - FoldingSet containing all the states created for analyzing
453 /// a particular function. This is used to unique states.
454 llvm::FoldingSet<ProgramState> StateSet;
456 /// Object that manages the data for all created SVals.
457 OwningPtr<SValBuilder> svalBuilder;
459 /// Manages memory for created CallEvents.
460 OwningPtr<CallEventManager> CallEventMgr;
462 /// A BumpPtrAllocator to allocate states.
463 llvm::BumpPtrAllocator &Alloc;
465 /// A vector of ProgramStates that we can reuse.
466 std::vector<ProgramState *> freeStates;
469 ProgramStateManager(ASTContext &Ctx,
470 StoreManagerCreator CreateStoreManager,
471 ConstraintManagerCreator CreateConstraintManager,
472 llvm::BumpPtrAllocator& alloc,
475 ~ProgramStateManager();
477 ProgramStateRef getInitialState(const LocationContext *InitLoc);
479 ASTContext &getContext() { return svalBuilder->getContext(); }
480 const ASTContext &getContext() const { return svalBuilder->getContext(); }
482 BasicValueFactory &getBasicVals() {
483 return svalBuilder->getBasicValueFactory();
486 SValBuilder &getSValBuilder() {
490 SymbolManager &getSymbolManager() {
491 return svalBuilder->getSymbolManager();
493 const SymbolManager &getSymbolManager() const {
494 return svalBuilder->getSymbolManager();
497 llvm::BumpPtrAllocator& getAllocator() { return Alloc; }
499 MemRegionManager& getRegionManager() {
500 return svalBuilder->getRegionManager();
502 const MemRegionManager& getRegionManager() const {
503 return svalBuilder->getRegionManager();
506 CallEventManager &getCallEventManager() { return *CallEventMgr; }
508 StoreManager& getStoreManager() { return *StoreMgr; }
509 ConstraintManager& getConstraintManager() { return *ConstraintMgr; }
510 SubEngine* getOwningEngine() { return Eng; }
512 ProgramStateRef removeDeadBindings(ProgramStateRef St,
513 const StackFrameContext *LCtx,
514 SymbolReaper& SymReaper);
518 SVal ArrayToPointer(Loc Array, QualType ElementTy) {
519 return StoreMgr->ArrayToPointer(Array, ElementTy);
522 // Methods that manipulate the GDM.
523 ProgramStateRef addGDM(ProgramStateRef St, void *Key, void *Data);
524 ProgramStateRef removeGDM(ProgramStateRef state, void *Key);
526 // Methods that query & manipulate the Store.
528 void iterBindings(ProgramStateRef state, StoreManager::BindingsHandler& F) {
529 StoreMgr->iterBindings(state->getStore(), F);
532 ProgramStateRef getPersistentState(ProgramState &Impl);
533 ProgramStateRef getPersistentStateWithGDM(ProgramStateRef FromState,
534 ProgramStateRef GDMState);
536 bool haveEqualEnvironments(ProgramStateRef S1, ProgramStateRef S2) {
537 return S1->Env == S2->Env;
540 bool haveEqualStores(ProgramStateRef S1, ProgramStateRef S2) {
541 return S1->store == S2->store;
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 ProgramStateRef set(ProgramStateRef st, typename ProgramStateTrait<T>::data_type D) {
565 return addGDM(st, ProgramStateTrait<T>::GDMIndex(),
566 ProgramStateTrait<T>::MakeVoidPtr(D));
570 ProgramStateRef set(ProgramStateRef 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 ProgramStateRef add(ProgramStateRef 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 ProgramStateRef remove(ProgramStateRef 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 ProgramStateRef remove(ProgramStateRef 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 void EndPath(ProgramStateRef St) {
615 ConstraintMgr->EndPath(St);
620 //===----------------------------------------------------------------------===//
621 // Out-of-line method definitions for ProgramState.
622 //===----------------------------------------------------------------------===//
624 inline ConstraintManager &ProgramState::getConstraintManager() const {
625 return stateMgr->getConstraintManager();
628 inline const VarRegion* ProgramState::getRegion(const VarDecl *D,
629 const LocationContext *LC) const
631 return getStateManager().getRegionManager().getVarRegion(D, LC);
634 inline ProgramStateRef ProgramState::assume(DefinedOrUnknownSVal Cond,
635 bool Assumption) const {
636 if (Cond.isUnknown())
639 return getStateManager().ConstraintMgr
640 ->assume(this, Cond.castAs<DefinedSVal>(), Assumption);
643 inline std::pair<ProgramStateRef , ProgramStateRef >
644 ProgramState::assume(DefinedOrUnknownSVal Cond) const {
645 if (Cond.isUnknown())
646 return std::make_pair(this, this);
648 return getStateManager().ConstraintMgr
649 ->assumeDual(this, Cond.castAs<DefinedSVal>());
652 inline ProgramStateRef ProgramState::bindLoc(SVal LV, SVal V) const {
653 if (Optional<Loc> L = LV.getAs<Loc>())
654 return bindLoc(*L, V);
658 inline Loc ProgramState::getLValue(const VarDecl *VD,
659 const LocationContext *LC) const {
660 return getStateManager().StoreMgr->getLValueVar(VD, LC);
663 inline Loc ProgramState::getLValue(const CompoundLiteralExpr *literal,
664 const LocationContext *LC) const {
665 return getStateManager().StoreMgr->getLValueCompoundLiteral(literal, LC);
668 inline SVal ProgramState::getLValue(const ObjCIvarDecl *D, SVal Base) const {
669 return getStateManager().StoreMgr->getLValueIvar(D, Base);
672 inline SVal ProgramState::getLValue(const FieldDecl *D, SVal Base) const {
673 return getStateManager().StoreMgr->getLValueField(D, Base);
676 inline SVal ProgramState::getLValue(const IndirectFieldDecl *D,
678 StoreManager &SM = *getStateManager().StoreMgr;
679 for (IndirectFieldDecl::chain_iterator I = D->chain_begin(),
682 Base = SM.getLValueField(cast<FieldDecl>(*I), Base);
688 inline SVal ProgramState::getLValue(QualType ElementType, SVal Idx, SVal Base) const{
689 if (Optional<NonLoc> N = Idx.getAs<NonLoc>())
690 return getStateManager().StoreMgr->getLValueElement(ElementType, *N, Base);
694 inline SVal ProgramState::getSVal(const Stmt *Ex,
695 const LocationContext *LCtx) const{
696 return Env.getSVal(EnvironmentEntry(Ex, LCtx),
697 *getStateManager().svalBuilder);
701 ProgramState::getSValAsScalarOrLoc(const Stmt *S,
702 const LocationContext *LCtx) const {
703 if (const Expr *Ex = dyn_cast<Expr>(S)) {
704 QualType T = Ex->getType();
705 if (Ex->isGLValue() || Loc::isLocType(T) ||
706 T->isIntegralOrEnumerationType())
707 return getSVal(S, LCtx);
713 inline SVal ProgramState::getRawSVal(Loc LV, QualType T) const {
714 return getStateManager().StoreMgr->getBinding(getStore(), LV, T);
717 inline SVal ProgramState::getSVal(const MemRegion* R) const {
718 return getStateManager().StoreMgr->getBinding(getStore(),
719 loc::MemRegionVal(R));
722 inline BasicValueFactory &ProgramState::getBasicVals() const {
723 return getStateManager().getBasicVals();
726 inline SymbolManager &ProgramState::getSymbolManager() const {
727 return getStateManager().getSymbolManager();
731 ProgramStateRef ProgramState::add(typename ProgramStateTrait<T>::key_type K) const {
732 return getStateManager().add<T>(this, K, get_context<T>());
735 template <typename T>
736 typename ProgramStateTrait<T>::context_type ProgramState::get_context() const {
737 return getStateManager().get_context<T>();
741 ProgramStateRef ProgramState::remove(typename ProgramStateTrait<T>::key_type K) const {
742 return getStateManager().remove<T>(this, K, get_context<T>());
746 ProgramStateRef ProgramState::remove(typename ProgramStateTrait<T>::key_type K,
747 typename ProgramStateTrait<T>::context_type C) const {
748 return getStateManager().remove<T>(this, K, C);
751 template <typename T>
752 ProgramStateRef ProgramState::remove() const {
753 return getStateManager().remove<T>(this);
757 ProgramStateRef ProgramState::set(typename ProgramStateTrait<T>::data_type D) const {
758 return getStateManager().set<T>(this, D);
762 ProgramStateRef ProgramState::set(typename ProgramStateTrait<T>::key_type K,
763 typename ProgramStateTrait<T>::value_type E) const {
764 return getStateManager().set<T>(this, K, E, get_context<T>());
768 ProgramStateRef ProgramState::set(typename ProgramStateTrait<T>::key_type K,
769 typename ProgramStateTrait<T>::value_type E,
770 typename ProgramStateTrait<T>::context_type C) const {
771 return getStateManager().set<T>(this, K, E, C);
774 template <typename CB>
775 CB ProgramState::scanReachableSymbols(SVal val) const {
777 scanReachableSymbols(val, cb);
781 template <typename CB>
782 CB ProgramState::scanReachableSymbols(const SVal *beg, const SVal *end) const {
784 scanReachableSymbols(beg, end, cb);
788 template <typename CB>
789 CB ProgramState::scanReachableSymbols(const MemRegion * const *beg,
790 const MemRegion * const *end) const {
792 scanReachableSymbols(beg, end, cb);
796 /// \class ScanReachableSymbols
797 /// A Utility class that allows to visit the reachable symbols using a custom
799 class ScanReachableSymbols {
800 typedef llvm::DenseSet<const void*> VisitedItems;
802 VisitedItems visited;
803 ProgramStateRef state;
804 SymbolVisitor &visitor;
807 ScanReachableSymbols(ProgramStateRef st, SymbolVisitor& v)
808 : state(st), visitor(v) {}
810 bool scan(nonloc::LazyCompoundVal val);
811 bool scan(nonloc::CompoundVal val);
813 bool scan(const MemRegion *R);
814 bool scan(const SymExpr *sym);
817 } // end ento namespace
819 } // end clang namespace