1 //= ProgramState.cpp - 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 implements ProgramState and ProgramStateManager.
12 //===----------------------------------------------------------------------===//
14 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
15 #include "clang/Analysis/CFG.h"
16 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
17 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
18 #include "clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h"
19 #include "clang/StaticAnalyzer/Core/PathSensitive/TaintManager.h"
20 #include "llvm/Support/raw_ostream.h"
22 using namespace clang;
25 namespace clang { namespace ento {
26 /// Increments the number of times this state is referenced.
28 void ProgramStateRetain(const ProgramState *state) {
29 ++const_cast<ProgramState*>(state)->refCount;
32 /// Decrement the number of times this state is referenced.
33 void ProgramStateRelease(const ProgramState *state) {
34 assert(state->refCount > 0);
35 ProgramState *s = const_cast<ProgramState*>(state);
36 if (--s->refCount == 0) {
37 ProgramStateManager &Mgr = s->getStateManager();
38 Mgr.StateSet.RemoveNode(s);
40 Mgr.freeStates.push_back(s);
45 ProgramState::ProgramState(ProgramStateManager *mgr, const Environment& env,
46 StoreRef st, GenericDataMap gdm)
52 stateMgr->getStoreManager().incrementReferenceCount(store);
55 ProgramState::ProgramState(const ProgramState &RHS)
56 : llvm::FoldingSetNode(),
57 stateMgr(RHS.stateMgr),
62 stateMgr->getStoreManager().incrementReferenceCount(store);
65 ProgramState::~ProgramState() {
67 stateMgr->getStoreManager().decrementReferenceCount(store);
70 ProgramStateManager::ProgramStateManager(ASTContext &Ctx,
71 StoreManagerCreator CreateSMgr,
72 ConstraintManagerCreator CreateCMgr,
73 llvm::BumpPtrAllocator &alloc,
75 : Eng(SubEng), EnvMgr(alloc), GDMFactory(alloc),
76 svalBuilder(createSimpleSValBuilder(alloc, Ctx, *this)),
77 CallEventMgr(new CallEventManager(alloc)), Alloc(alloc) {
78 StoreMgr.reset((*CreateSMgr)(*this));
79 ConstraintMgr.reset((*CreateCMgr)(*this, SubEng));
83 ProgramStateManager::~ProgramStateManager() {
84 for (GDMContextsTy::iterator I=GDMContexts.begin(), E=GDMContexts.end();
86 I->second.second(I->second.first);
90 ProgramStateManager::removeDeadBindings(ProgramStateRef state,
91 const StackFrameContext *LCtx,
92 SymbolReaper& SymReaper) {
94 // This code essentially performs a "mark-and-sweep" of the VariableBindings.
95 // The roots are any Block-level exprs and Decls that our liveness algorithm
96 // tells us are live. We then see what Decls they may reference, and keep
97 // those around. This code more than likely can be made faster, and the
98 // frequency of which this method is called should be experimented with
99 // for optimum performance.
100 ProgramState NewState = *state;
102 NewState.Env = EnvMgr.removeDeadBindings(NewState.Env, SymReaper, state);
104 // Clean up the store.
105 StoreRef newStore = StoreMgr->removeDeadBindings(NewState.getStore(), LCtx,
107 NewState.setStore(newStore);
108 SymReaper.setReapedStore(newStore);
110 ProgramStateRef Result = getPersistentState(NewState);
111 return ConstraintMgr->removeDeadBindings(Result, SymReaper);
114 ProgramStateRef ProgramState::bindLoc(Loc LV, SVal V, bool notifyChanges) const {
115 ProgramStateManager &Mgr = getStateManager();
116 ProgramStateRef newState = makeWithStore(Mgr.StoreMgr->Bind(getStore(),
118 const MemRegion *MR = LV.getAsRegion();
119 if (MR && Mgr.getOwningEngine() && notifyChanges)
120 return Mgr.getOwningEngine()->processRegionChange(newState, MR);
125 ProgramStateRef ProgramState::bindDefault(SVal loc, SVal V) const {
126 ProgramStateManager &Mgr = getStateManager();
127 const MemRegion *R = loc.castAs<loc::MemRegionVal>().getRegion();
128 const StoreRef &newStore = Mgr.StoreMgr->BindDefault(getStore(), R, V);
129 ProgramStateRef new_state = makeWithStore(newStore);
130 return Mgr.getOwningEngine() ?
131 Mgr.getOwningEngine()->processRegionChange(new_state, R) :
135 typedef ArrayRef<const MemRegion *> RegionList;
136 typedef ArrayRef<SVal> ValueList;
139 ProgramState::invalidateRegions(RegionList Regions,
140 const Expr *E, unsigned Count,
141 const LocationContext *LCtx,
142 bool CausedByPointerEscape,
143 InvalidatedSymbols *IS,
144 const CallEvent *Call,
145 RegionList ConstRegions) const {
146 SmallVector<SVal, 8> Values;
147 for (RegionList::const_iterator I = Regions.begin(),
148 End = Regions.end(); I != End; ++I)
149 Values.push_back(loc::MemRegionVal(*I));
151 SmallVector<SVal, 8> ConstValues;
152 for (RegionList::const_iterator I = ConstRegions.begin(),
153 End = ConstRegions.end(); I != End; ++I)
154 ConstValues.push_back(loc::MemRegionVal(*I));
157 InvalidatedSymbols invalidated;
158 return invalidateRegionsImpl(Values, E, Count, LCtx,
159 CausedByPointerEscape,
160 invalidated, Call, ConstValues);
162 return invalidateRegionsImpl(Values, E, Count, LCtx, CausedByPointerEscape,
163 *IS, Call, ConstValues);
167 ProgramState::invalidateRegions(ValueList Values,
168 const Expr *E, unsigned Count,
169 const LocationContext *LCtx,
170 bool CausedByPointerEscape,
171 InvalidatedSymbols *IS,
172 const CallEvent *Call,
173 ValueList ConstValues) const {
175 InvalidatedSymbols invalidated;
176 return invalidateRegionsImpl(Values, E, Count, LCtx,
177 CausedByPointerEscape,
178 invalidated, Call, ConstValues);
180 return invalidateRegionsImpl(Values, E, Count, LCtx, CausedByPointerEscape,
181 *IS, Call, ConstValues);
185 ProgramState::invalidateRegionsImpl(ValueList Values,
186 const Expr *E, unsigned Count,
187 const LocationContext *LCtx,
188 bool CausedByPointerEscape,
189 InvalidatedSymbols &IS,
190 const CallEvent *Call,
191 ValueList ConstValues) const {
192 ProgramStateManager &Mgr = getStateManager();
193 SubEngine* Eng = Mgr.getOwningEngine();
194 InvalidatedSymbols ConstIS;
197 StoreManager::InvalidatedRegions TopLevelInvalidated;
198 StoreManager::InvalidatedRegions TopLevelConstInvalidated;
199 StoreManager::InvalidatedRegions Invalidated;
200 const StoreRef &newStore
201 = Mgr.StoreMgr->invalidateRegions(getStore(), Values, ConstValues,
202 E, Count, LCtx, Call,
204 &TopLevelInvalidated,
205 &TopLevelConstInvalidated,
208 ProgramStateRef newState = makeWithStore(newStore);
210 if (CausedByPointerEscape) {
211 newState = Eng->notifyCheckersOfPointerEscape(newState, &IS,
214 if (!ConstValues.empty()) {
215 StoreManager::InvalidatedRegions Empty;
216 newState = Eng->notifyCheckersOfPointerEscape(newState, &ConstIS,
217 TopLevelConstInvalidated,
223 return Eng->processRegionChanges(newState, &IS,
224 TopLevelInvalidated, Invalidated,
228 const StoreRef &newStore =
229 Mgr.StoreMgr->invalidateRegions(getStore(), Values, ConstValues,
230 E, Count, LCtx, Call,
231 IS, ConstIS, NULL, NULL, NULL);
232 return makeWithStore(newStore);
235 ProgramStateRef ProgramState::killBinding(Loc LV) const {
236 assert(!LV.getAs<loc::MemRegionVal>() && "Use invalidateRegion instead.");
238 Store OldStore = getStore();
239 const StoreRef &newStore =
240 getStateManager().StoreMgr->killBinding(OldStore, LV);
242 if (newStore.getStore() == OldStore)
245 return makeWithStore(newStore);
249 ProgramState::enterStackFrame(const CallEvent &Call,
250 const StackFrameContext *CalleeCtx) const {
251 const StoreRef &NewStore =
252 getStateManager().StoreMgr->enterStackFrame(getStore(), Call, CalleeCtx);
253 return makeWithStore(NewStore);
256 SVal ProgramState::getSValAsScalarOrLoc(const MemRegion *R) const {
257 // We only want to do fetches from regions that we can actually bind
258 // values. For example, SymbolicRegions of type 'id<...>' cannot
259 // have direct bindings (but their can be bindings on their subregions).
260 if (!R->isBoundable())
263 if (const TypedValueRegion *TR = dyn_cast<TypedValueRegion>(R)) {
264 QualType T = TR->getValueType();
265 if (Loc::isLocType(T) || T->isIntegralOrEnumerationType())
272 SVal ProgramState::getSVal(Loc location, QualType T) const {
273 SVal V = getRawSVal(cast<Loc>(location), T);
275 // If 'V' is a symbolic value that is *perfectly* constrained to
276 // be a constant value, use that value instead to lessen the burden
277 // on later analysis stages (so we have less symbolic values to reason
280 if (SymbolRef sym = V.getAsSymbol()) {
281 if (const llvm::APSInt *Int = getStateManager()
282 .getConstraintManager()
283 .getSymVal(this, sym)) {
284 // FIXME: Because we don't correctly model (yet) sign-extension
285 // and truncation of symbolic values, we need to convert
286 // the integer value to the correct signedness and bitwidth.
288 // This shows up in the following:
291 // unsigned x = foo();
295 // The symbolic value stored to 'x' is actually the conjured
296 // symbol for the call to foo(); the type of that symbol is 'char',
298 const llvm::APSInt &NewV = getBasicVals().Convert(T, *Int);
301 return loc::ConcreteInt(NewV);
303 return nonloc::ConcreteInt(NewV);
311 ProgramStateRef ProgramState::BindExpr(const Stmt *S,
312 const LocationContext *LCtx,
313 SVal V, bool Invalidate) const{
315 getStateManager().EnvMgr.bindExpr(Env, EnvironmentEntry(S, LCtx), V,
320 ProgramState NewSt = *this;
322 return getStateManager().getPersistentState(NewSt);
325 ProgramStateRef ProgramState::assumeInBound(DefinedOrUnknownSVal Idx,
326 DefinedOrUnknownSVal UpperBound,
328 QualType indexTy) const {
329 if (Idx.isUnknown() || UpperBound.isUnknown())
332 // Build an expression for 0 <= Idx < UpperBound.
333 // This is the same as Idx + MIN < UpperBound + MIN, if overflow is allowed.
334 // FIXME: This should probably be part of SValBuilder.
335 ProgramStateManager &SM = getStateManager();
336 SValBuilder &svalBuilder = SM.getSValBuilder();
337 ASTContext &Ctx = svalBuilder.getContext();
339 // Get the offset: the minimum value of the array index type.
340 BasicValueFactory &BVF = svalBuilder.getBasicValueFactory();
341 // FIXME: This should be using ValueManager::ArrayindexTy...somehow.
342 if (indexTy.isNull())
344 nonloc::ConcreteInt Min(BVF.getMinValue(indexTy));
347 SVal newIdx = svalBuilder.evalBinOpNN(this, BO_Add,
348 Idx.castAs<NonLoc>(), Min, indexTy);
349 if (newIdx.isUnknownOrUndef())
352 // Adjust the upper bound.
354 svalBuilder.evalBinOpNN(this, BO_Add, UpperBound.castAs<NonLoc>(),
357 if (newBound.isUnknownOrUndef())
360 // Build the actual comparison.
361 SVal inBound = svalBuilder.evalBinOpNN(this, BO_LT, newIdx.castAs<NonLoc>(),
362 newBound.castAs<NonLoc>(), Ctx.IntTy);
363 if (inBound.isUnknownOrUndef())
366 // Finally, let the constraint manager take care of it.
367 ConstraintManager &CM = SM.getConstraintManager();
368 return CM.assume(this, inBound.castAs<DefinedSVal>(), Assumption);
371 ConditionTruthVal ProgramState::isNull(SVal V) const {
372 if (V.isZeroConstant())
378 SymbolRef Sym = V.getAsSymbol(/* IncludeBaseRegion */ true);
380 return ConditionTruthVal();
382 return getStateManager().ConstraintMgr->isNull(this, Sym);
385 ProgramStateRef ProgramStateManager::getInitialState(const LocationContext *InitLoc) {
386 ProgramState State(this,
387 EnvMgr.getInitialEnvironment(),
388 StoreMgr->getInitialStore(InitLoc),
389 GDMFactory.getEmptyMap());
391 return getPersistentState(State);
394 ProgramStateRef ProgramStateManager::getPersistentStateWithGDM(
395 ProgramStateRef FromState,
396 ProgramStateRef GDMState) {
397 ProgramState NewState(*FromState);
398 NewState.GDM = GDMState->GDM;
399 return getPersistentState(NewState);
402 ProgramStateRef ProgramStateManager::getPersistentState(ProgramState &State) {
404 llvm::FoldingSetNodeID ID;
408 if (ProgramState *I = StateSet.FindNodeOrInsertPos(ID, InsertPos))
411 ProgramState *newState = 0;
412 if (!freeStates.empty()) {
413 newState = freeStates.back();
414 freeStates.pop_back();
417 newState = (ProgramState*) Alloc.Allocate<ProgramState>();
419 new (newState) ProgramState(State);
420 StateSet.InsertNode(newState, InsertPos);
424 ProgramStateRef ProgramState::makeWithStore(const StoreRef &store) const {
425 ProgramState NewSt(*this);
426 NewSt.setStore(store);
427 return getStateManager().getPersistentState(NewSt);
430 void ProgramState::setStore(const StoreRef &newStore) {
431 Store newStoreStore = newStore.getStore();
433 stateMgr->getStoreManager().incrementReferenceCount(newStoreStore);
435 stateMgr->getStoreManager().decrementReferenceCount(store);
436 store = newStoreStore;
439 //===----------------------------------------------------------------------===//
440 // State pretty-printing.
441 //===----------------------------------------------------------------------===//
443 void ProgramState::print(raw_ostream &Out,
444 const char *NL, const char *Sep) const {
446 ProgramStateManager &Mgr = getStateManager();
447 Mgr.getStoreManager().print(getStore(), Out, NL, Sep);
449 // Print out the environment.
450 Env.print(Out, NL, Sep);
452 // Print out the constraints.
453 Mgr.getConstraintManager().print(this, Out, NL, Sep);
455 // Print checker-specific data.
456 Mgr.getOwningEngine()->printState(Out, this, NL, Sep);
459 void ProgramState::printDOT(raw_ostream &Out) const {
460 print(Out, "\\l", "\\|");
463 void ProgramState::dump() const {
467 void ProgramState::printTaint(raw_ostream &Out,
468 const char *NL, const char *Sep) const {
469 TaintMapImpl TM = get<TaintMap>();
472 Out <<"Tainted Symbols:" << NL;
474 for (TaintMapImpl::iterator I = TM.begin(), E = TM.end(); I != E; ++I) {
475 Out << I->first << " : " << I->second << NL;
479 void ProgramState::dumpTaint() const {
480 printTaint(llvm::errs());
483 //===----------------------------------------------------------------------===//
485 //===----------------------------------------------------------------------===//
487 void *const* ProgramState::FindGDM(void *K) const {
488 return GDM.lookup(K);
492 ProgramStateManager::FindGDMContext(void *K,
493 void *(*CreateContext)(llvm::BumpPtrAllocator&),
494 void (*DeleteContext)(void*)) {
496 std::pair<void*, void (*)(void*)>& p = GDMContexts[K];
498 p.first = CreateContext(Alloc);
499 p.second = DeleteContext;
505 ProgramStateRef ProgramStateManager::addGDM(ProgramStateRef St, void *Key, void *Data){
506 ProgramState::GenericDataMap M1 = St->getGDM();
507 ProgramState::GenericDataMap M2 = GDMFactory.add(M1, Key, Data);
512 ProgramState NewSt = *St;
514 return getPersistentState(NewSt);
517 ProgramStateRef ProgramStateManager::removeGDM(ProgramStateRef state, void *Key) {
518 ProgramState::GenericDataMap OldM = state->getGDM();
519 ProgramState::GenericDataMap NewM = GDMFactory.remove(OldM, Key);
524 ProgramState NewState = *state;
526 return getPersistentState(NewState);
529 bool ScanReachableSymbols::scan(nonloc::CompoundVal val) {
530 for (nonloc::CompoundVal::iterator I=val.begin(), E=val.end(); I!=E; ++I)
537 bool ScanReachableSymbols::scan(const SymExpr *sym) {
538 unsigned &isVisited = visited[sym];
543 if (!visitor.VisitSymbol(sym))
546 // TODO: should be rewritten using SymExpr::symbol_iterator.
547 switch (sym->getKind()) {
548 case SymExpr::RegionValueKind:
549 case SymExpr::ConjuredKind:
550 case SymExpr::DerivedKind:
551 case SymExpr::ExtentKind:
552 case SymExpr::MetadataKind:
554 case SymExpr::CastSymbolKind:
555 return scan(cast<SymbolCast>(sym)->getOperand());
556 case SymExpr::SymIntKind:
557 return scan(cast<SymIntExpr>(sym)->getLHS());
558 case SymExpr::IntSymKind:
559 return scan(cast<IntSymExpr>(sym)->getRHS());
560 case SymExpr::SymSymKind: {
561 const SymSymExpr *x = cast<SymSymExpr>(sym);
562 return scan(x->getLHS()) && scan(x->getRHS());
568 bool ScanReachableSymbols::scan(SVal val) {
569 if (Optional<loc::MemRegionVal> X = val.getAs<loc::MemRegionVal>())
570 return scan(X->getRegion());
572 if (Optional<nonloc::LazyCompoundVal> X =
573 val.getAs<nonloc::LazyCompoundVal>()) {
574 StoreManager &StoreMgr = state->getStateManager().getStoreManager();
575 // FIXME: We don't really want to use getBaseRegion() here because pointer
576 // arithmetic doesn't apply, but scanReachableSymbols only accepts base
577 // regions right now.
578 if (!StoreMgr.scanReachableSymbols(X->getStore(),
579 X->getRegion()->getBaseRegion(),
584 if (Optional<nonloc::LocAsInteger> X = val.getAs<nonloc::LocAsInteger>())
585 return scan(X->getLoc());
587 if (SymbolRef Sym = val.getAsSymbol())
590 if (const SymExpr *Sym = val.getAsSymbolicExpression())
593 if (Optional<nonloc::CompoundVal> X = val.getAs<nonloc::CompoundVal>())
599 bool ScanReachableSymbols::scan(const MemRegion *R) {
600 if (isa<MemSpaceRegion>(R))
603 unsigned &isVisited = visited[R];
609 if (!visitor.VisitMemRegion(R))
612 // If this is a symbolic region, visit the symbol for the region.
613 if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R))
614 if (!visitor.VisitSymbol(SR->getSymbol()))
617 // If this is a subregion, also visit the parent regions.
618 if (const SubRegion *SR = dyn_cast<SubRegion>(R)) {
619 const MemRegion *Super = SR->getSuperRegion();
623 // When we reach the topmost region, scan all symbols in it.
624 if (isa<MemSpaceRegion>(Super)) {
625 StoreManager &StoreMgr = state->getStateManager().getStoreManager();
626 if (!StoreMgr.scanReachableSymbols(state->getStore(), SR, *this))
631 // Regions captured by a block are also implicitly reachable.
632 if (const BlockDataRegion *BDR = dyn_cast<BlockDataRegion>(R)) {
633 BlockDataRegion::referenced_vars_iterator I = BDR->referenced_vars_begin(),
634 E = BDR->referenced_vars_end();
635 for ( ; I != E; ++I) {
636 if (!scan(I.getCapturedRegion()))
644 bool ProgramState::scanReachableSymbols(SVal val, SymbolVisitor& visitor) const {
645 ScanReachableSymbols S(this, visitor);
649 bool ProgramState::scanReachableSymbols(const SVal *I, const SVal *E,
650 SymbolVisitor &visitor) const {
651 ScanReachableSymbols S(this, visitor);
652 for ( ; I != E; ++I) {
659 bool ProgramState::scanReachableSymbols(const MemRegion * const *I,
660 const MemRegion * const *E,
661 SymbolVisitor &visitor) const {
662 ScanReachableSymbols S(this, visitor);
663 for ( ; I != E; ++I) {
670 ProgramStateRef ProgramState::addTaint(const Stmt *S,
671 const LocationContext *LCtx,
672 TaintTagType Kind) const {
673 if (const Expr *E = dyn_cast_or_null<Expr>(S))
674 S = E->IgnoreParens();
676 SymbolRef Sym = getSVal(S, LCtx).getAsSymbol();
678 return addTaint(Sym, Kind);
680 const MemRegion *R = getSVal(S, LCtx).getAsRegion();
683 // Cannot add taint, so just return the state.
687 ProgramStateRef ProgramState::addTaint(const MemRegion *R,
688 TaintTagType Kind) const {
689 if (const SymbolicRegion *SR = dyn_cast_or_null<SymbolicRegion>(R))
690 return addTaint(SR->getSymbol(), Kind);
694 ProgramStateRef ProgramState::addTaint(SymbolRef Sym,
695 TaintTagType Kind) const {
696 // If this is a symbol cast, remove the cast before adding the taint. Taint
698 while (const SymbolCast *SC = dyn_cast<SymbolCast>(Sym))
699 Sym = SC->getOperand();
701 ProgramStateRef NewState = set<TaintMap>(Sym, Kind);
706 bool ProgramState::isTainted(const Stmt *S, const LocationContext *LCtx,
707 TaintTagType Kind) const {
708 if (const Expr *E = dyn_cast_or_null<Expr>(S))
709 S = E->IgnoreParens();
711 SVal val = getSVal(S, LCtx);
712 return isTainted(val, Kind);
715 bool ProgramState::isTainted(SVal V, TaintTagType Kind) const {
716 if (const SymExpr *Sym = V.getAsSymExpr())
717 return isTainted(Sym, Kind);
718 if (const MemRegion *Reg = V.getAsRegion())
719 return isTainted(Reg, Kind);
723 bool ProgramState::isTainted(const MemRegion *Reg, TaintTagType K) const {
727 // Element region (array element) is tainted if either the base or the offset
729 if (const ElementRegion *ER = dyn_cast<ElementRegion>(Reg))
730 return isTainted(ER->getSuperRegion(), K) || isTainted(ER->getIndex(), K);
732 if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(Reg))
733 return isTainted(SR->getSymbol(), K);
735 if (const SubRegion *ER = dyn_cast<SubRegion>(Reg))
736 return isTainted(ER->getSuperRegion(), K);
741 bool ProgramState::isTainted(SymbolRef Sym, TaintTagType Kind) const {
745 // Traverse all the symbols this symbol depends on to see if any are tainted.
746 bool Tainted = false;
747 for (SymExpr::symbol_iterator SI = Sym->symbol_begin(), SE =Sym->symbol_end();
749 if (!isa<SymbolData>(*SI))
752 const TaintTagType *Tag = get<TaintMap>(*SI);
753 Tainted = (Tag && *Tag == Kind);
755 // If this is a SymbolDerived with a tainted parent, it's also tainted.
756 if (const SymbolDerived *SD = dyn_cast<SymbolDerived>(*SI))
757 Tainted = Tainted || isTainted(SD->getParentSymbol(), Kind);
759 // If memory region is tainted, data is also tainted.
760 if (const SymbolRegionValue *SRV = dyn_cast<SymbolRegionValue>(*SI))
761 Tainted = Tainted || isTainted(SRV->getRegion(), Kind);
763 // If If this is a SymbolCast from a tainted value, it's also tainted.
764 if (const SymbolCast *SC = dyn_cast<SymbolCast>(*SI))
765 Tainted = Tainted || isTainted(SC->getOperand(), Kind);
774 /// The GDM component containing the dynamic type info. This is a map from a
775 /// symbol to its most likely type.
776 REGISTER_TRAIT_WITH_PROGRAMSTATE(DynamicTypeMap,
777 CLANG_ENTO_PROGRAMSTATE_MAP(const MemRegion *,
780 DynamicTypeInfo ProgramState::getDynamicTypeInfo(const MemRegion *Reg) const {
781 Reg = Reg->StripCasts();
783 // Look up the dynamic type in the GDM.
784 const DynamicTypeInfo *GDMType = get<DynamicTypeMap>(Reg);
788 // Otherwise, fall back to what we know about the region.
789 if (const TypedRegion *TR = dyn_cast<TypedRegion>(Reg))
790 return DynamicTypeInfo(TR->getLocationType(), /*CanBeSubclass=*/false);
792 if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(Reg)) {
793 SymbolRef Sym = SR->getSymbol();
794 return DynamicTypeInfo(Sym->getType());
797 return DynamicTypeInfo();
800 ProgramStateRef ProgramState::setDynamicTypeInfo(const MemRegion *Reg,
801 DynamicTypeInfo NewTy) const {
802 Reg = Reg->StripCasts();
803 ProgramStateRef NewState = set<DynamicTypeMap>(Reg, NewTy);