1 //= ProgramState.cpp - Path-Sensitive "State" for tracking values --*- C++ -*--=
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 //  This file implements ProgramState and ProgramStateManager.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
14 #include "clang/Analysis/CFG.h"
15 #include "clang/Basic/JsonSupport.h"
16 #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
17 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
18 #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"
19 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
20 #include "clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h"
21 #include "llvm/Support/raw_ostream.h"
22 
23 using namespace clang;
24 using namespace ento;
25 
26 namespace clang { namespace  ento {
27 /// Increments the number of times this state is referenced.
28 
29 void ProgramStateRetain(const ProgramState *state) {
30   ++const_cast<ProgramState*>(state)->refCount;
31 }
32 
33 /// Decrement the number of times this state is referenced.
34 void ProgramStateRelease(const ProgramState *state) {
35   assert(state->refCount > 0);
36   ProgramState *s = const_cast<ProgramState*>(state);
37   if (--s->refCount == 0) {
38     ProgramStateManager &Mgr = s->getStateManager();
39     Mgr.StateSet.RemoveNode(s);
40     s->~ProgramState();
41     Mgr.freeStates.push_back(s);
42   }
43 }
44 } // namespace ento
45 } // namespace clang
46 
47 ProgramState::ProgramState(ProgramStateManager *mgr, const Environment& env,
48                  StoreRef st, GenericDataMap gdm)
49   : stateMgr(mgr),
50     Env(env),
51     store(st.getStore()),
52     GDM(gdm),
53     refCount(0) {
54   stateMgr->getStoreManager().incrementReferenceCount(store);
55 }
56 
57 ProgramState::ProgramState(const ProgramState &RHS)
58     : llvm::FoldingSetNode(),
59       stateMgr(RHS.stateMgr),
60       Env(RHS.Env),
61       store(RHS.store),
62       GDM(RHS.GDM),
63       refCount(0) {
64   stateMgr->getStoreManager().incrementReferenceCount(store);
65 }
66 
67 ProgramState::~ProgramState() {
68   if (store)
69     stateMgr->getStoreManager().decrementReferenceCount(store);
70 }
71 
72 int64_t ProgramState::getID() const {
73   return getStateManager().Alloc.identifyKnownAlignedObject<ProgramState>(this);
74 }
75 
76 ProgramStateManager::ProgramStateManager(ASTContext &Ctx,
77                                          StoreManagerCreator CreateSMgr,
78                                          ConstraintManagerCreator CreateCMgr,
79                                          llvm::BumpPtrAllocator &alloc,
80                                          SubEngine *SubEng)
81   : Eng(SubEng), EnvMgr(alloc), GDMFactory(alloc),
82     svalBuilder(createSimpleSValBuilder(alloc, Ctx, *this)),
83     CallEventMgr(new CallEventManager(alloc)), Alloc(alloc) {
84   StoreMgr = (*CreateSMgr)(*this);
85   ConstraintMgr = (*CreateCMgr)(*this, SubEng);
86 }
87 
88 
89 ProgramStateManager::~ProgramStateManager() {
90   for (GDMContextsTy::iterator I=GDMContexts.begin(), E=GDMContexts.end();
91        I!=E; ++I)
92     I->second.second(I->second.first);
93 }
94 
95 ProgramStateRef ProgramStateManager::removeDeadBindingsFromEnvironmentAndStore(
96     ProgramStateRef state, const StackFrameContext *LCtx,
97     SymbolReaper &SymReaper) {
98 
99   // This code essentially performs a "mark-and-sweep" of the VariableBindings.
100   // The roots are any Block-level exprs and Decls that our liveness algorithm
101   // tells us are live.  We then see what Decls they may reference, and keep
102   // those around.  This code more than likely can be made faster, and the
103   // frequency of which this method is called should be experimented with
104   // for optimum performance.
105   ProgramState NewState = *state;
106 
107   NewState.Env = EnvMgr.removeDeadBindings(NewState.Env, SymReaper, state);
108 
109   // Clean up the store.
110   StoreRef newStore = StoreMgr->removeDeadBindings(NewState.getStore(), LCtx,
111                                                    SymReaper);
112   NewState.setStore(newStore);
113   SymReaper.setReapedStore(newStore);
114 
115   return getPersistentState(NewState);
116 }
117 
118 ProgramStateRef ProgramState::bindLoc(Loc LV,
119                                       SVal V,
120                                       const LocationContext *LCtx,
121                                       bool notifyChanges) const {
122   ProgramStateManager &Mgr = getStateManager();
123   ProgramStateRef newState = makeWithStore(Mgr.StoreMgr->Bind(getStore(),
124                                                              LV, V));
125   const MemRegion *MR = LV.getAsRegion();
126   if (MR && notifyChanges)
127     return Mgr.getOwningEngine().processRegionChange(newState, MR, LCtx);
128 
129   return newState;
130 }
131 
132 ProgramStateRef
133 ProgramState::bindDefaultInitial(SVal loc, SVal V,
134                                  const LocationContext *LCtx) const {
135   ProgramStateManager &Mgr = getStateManager();
136   const MemRegion *R = loc.castAs<loc::MemRegionVal>().getRegion();
137   const StoreRef &newStore = Mgr.StoreMgr->BindDefaultInitial(getStore(), R, V);
138   ProgramStateRef new_state = makeWithStore(newStore);
139   return Mgr.getOwningEngine().processRegionChange(new_state, R, LCtx);
140 }
141 
142 ProgramStateRef
143 ProgramState::bindDefaultZero(SVal loc, const LocationContext *LCtx) const {
144   ProgramStateManager &Mgr = getStateManager();
145   const MemRegion *R = loc.castAs<loc::MemRegionVal>().getRegion();
146   const StoreRef &newStore = Mgr.StoreMgr->BindDefaultZero(getStore(), R);
147   ProgramStateRef new_state = makeWithStore(newStore);
148   return Mgr.getOwningEngine().processRegionChange(new_state, R, LCtx);
149 }
150 
151 typedef ArrayRef<const MemRegion *> RegionList;
152 typedef ArrayRef<SVal> ValueList;
153 
154 ProgramStateRef
155 ProgramState::invalidateRegions(RegionList Regions,
156                              const Expr *E, unsigned Count,
157                              const LocationContext *LCtx,
158                              bool CausedByPointerEscape,
159                              InvalidatedSymbols *IS,
160                              const CallEvent *Call,
161                              RegionAndSymbolInvalidationTraits *ITraits) const {
162   SmallVector<SVal, 8> Values;
163   for (RegionList::const_iterator I = Regions.begin(),
164                                   End = Regions.end(); I != End; ++I)
165     Values.push_back(loc::MemRegionVal(*I));
166 
167   return invalidateRegionsImpl(Values, E, Count, LCtx, CausedByPointerEscape,
168                                IS, ITraits, Call);
169 }
170 
171 ProgramStateRef
172 ProgramState::invalidateRegions(ValueList Values,
173                              const Expr *E, unsigned Count,
174                              const LocationContext *LCtx,
175                              bool CausedByPointerEscape,
176                              InvalidatedSymbols *IS,
177                              const CallEvent *Call,
178                              RegionAndSymbolInvalidationTraits *ITraits) const {
179 
180   return invalidateRegionsImpl(Values, E, Count, LCtx, CausedByPointerEscape,
181                                IS, ITraits, Call);
182 }
183 
184 ProgramStateRef
185 ProgramState::invalidateRegionsImpl(ValueList Values,
186                                     const Expr *E, unsigned Count,
187                                     const LocationContext *LCtx,
188                                     bool CausedByPointerEscape,
189                                     InvalidatedSymbols *IS,
190                                     RegionAndSymbolInvalidationTraits *ITraits,
191                                     const CallEvent *Call) const {
192   ProgramStateManager &Mgr = getStateManager();
193   SubEngine &Eng = Mgr.getOwningEngine();
194 
195   InvalidatedSymbols InvalidatedSyms;
196   if (!IS)
197     IS = &InvalidatedSyms;
198 
199   RegionAndSymbolInvalidationTraits ITraitsLocal;
200   if (!ITraits)
201     ITraits = &ITraitsLocal;
202 
203   StoreManager::InvalidatedRegions TopLevelInvalidated;
204   StoreManager::InvalidatedRegions Invalidated;
205   const StoreRef &newStore
206   = Mgr.StoreMgr->invalidateRegions(getStore(), Values, E, Count, LCtx, Call,
207                                     *IS, *ITraits, &TopLevelInvalidated,
208                                     &Invalidated);
209 
210   ProgramStateRef newState = makeWithStore(newStore);
211 
212   if (CausedByPointerEscape) {
213     for (const MemRegion *R : Invalidated) {
214       if (!R->hasStackStorage())
215         continue;
216 
217       newState = Eng.processLocalRegionEscape(newState, R->getBaseRegion());
218     }
219 
220     newState = Eng.notifyCheckersOfPointerEscape(newState, IS,
221                                                  TopLevelInvalidated,
222                                                  Call,
223                                                  *ITraits);
224   }
225 
226   return Eng.processRegionChanges(newState, IS, TopLevelInvalidated,
227                                   Invalidated, LCtx, Call);
228 }
229 
230 ProgramStateRef ProgramState::killBinding(Loc LV) const {
231   assert(!LV.getAs<loc::MemRegionVal>() && "Use invalidateRegion instead.");
232 
233   Store OldStore = getStore();
234   const StoreRef &newStore =
235     getStateManager().StoreMgr->killBinding(OldStore, LV);
236 
237   if (newStore.getStore() == OldStore)
238     return this;
239 
240   return makeWithStore(newStore);
241 }
242 
243 ProgramStateRef
244 ProgramState::enterStackFrame(const CallEvent &Call,
245                               const StackFrameContext *CalleeCtx) const {
246   const StoreRef &NewStore =
247     getStateManager().StoreMgr->enterStackFrame(getStore(), Call, CalleeCtx);
248   return makeWithStore(NewStore);
249 }
250 
251 SVal ProgramState::getSValAsScalarOrLoc(const MemRegion *R) const {
252   // We only want to do fetches from regions that we can actually bind
253   // values.  For example, SymbolicRegions of type 'id<...>' cannot
254   // have direct bindings (but their can be bindings on their subregions).
255   if (!R->isBoundable())
256     return UnknownVal();
257 
258   if (const TypedValueRegion *TR = dyn_cast<TypedValueRegion>(R)) {
259     QualType T = TR->getValueType();
260     if (Loc::isLocType(T) || T->isIntegralOrEnumerationType())
261       return getSVal(R);
262   }
263 
264   return UnknownVal();
265 }
266 
267 SVal ProgramState::getSVal(Loc location, QualType T) const {
268   SVal V = getRawSVal(location, T);
269 
270   // If 'V' is a symbolic value that is *perfectly* constrained to
271   // be a constant value, use that value instead to lessen the burden
272   // on later analysis stages (so we have less symbolic values to reason
273   // about).
274   // We only go into this branch if we can convert the APSInt value we have
275   // to the type of T, which is not always the case (e.g. for void).
276   if (!T.isNull() && (T->isIntegralOrEnumerationType() || Loc::isLocType(T))) {
277     if (SymbolRef sym = V.getAsSymbol()) {
278       if (const llvm::APSInt *Int = getStateManager()
279                                     .getConstraintManager()
280                                     .getSymVal(this, sym)) {
281         // FIXME: Because we don't correctly model (yet) sign-extension
282         // and truncation of symbolic values, we need to convert
283         // the integer value to the correct signedness and bitwidth.
284         //
285         // This shows up in the following:
286         //
287         //   char foo();
288         //   unsigned x = foo();
289         //   if (x == 54)
290         //     ...
291         //
292         //  The symbolic value stored to 'x' is actually the conjured
293         //  symbol for the call to foo(); the type of that symbol is 'char',
294         //  not unsigned.
295         const llvm::APSInt &NewV = getBasicVals().Convert(T, *Int);
296 
297         if (V.getAs<Loc>())
298           return loc::ConcreteInt(NewV);
299         else
300           return nonloc::ConcreteInt(NewV);
301       }
302     }
303   }
304 
305   return V;
306 }
307 
308 ProgramStateRef ProgramState::BindExpr(const Stmt *S,
309                                            const LocationContext *LCtx,
310                                            SVal V, bool Invalidate) const{
311   Environment NewEnv =
312     getStateManager().EnvMgr.bindExpr(Env, EnvironmentEntry(S, LCtx), V,
313                                       Invalidate);
314   if (NewEnv == Env)
315     return this;
316 
317   ProgramState NewSt = *this;
318   NewSt.Env = NewEnv;
319   return getStateManager().getPersistentState(NewSt);
320 }
321 
322 ProgramStateRef ProgramState::assumeInBound(DefinedOrUnknownSVal Idx,
323                                       DefinedOrUnknownSVal UpperBound,
324                                       bool Assumption,
325                                       QualType indexTy) const {
326   if (Idx.isUnknown() || UpperBound.isUnknown())
327     return this;
328 
329   // Build an expression for 0 <= Idx < UpperBound.
330   // This is the same as Idx + MIN < UpperBound + MIN, if overflow is allowed.
331   // FIXME: This should probably be part of SValBuilder.
332   ProgramStateManager &SM = getStateManager();
333   SValBuilder &svalBuilder = SM.getSValBuilder();
334   ASTContext &Ctx = svalBuilder.getContext();
335 
336   // Get the offset: the minimum value of the array index type.
337   BasicValueFactory &BVF = svalBuilder.getBasicValueFactory();
338   if (indexTy.isNull())
339     indexTy = svalBuilder.getArrayIndexType();
340   nonloc::ConcreteInt Min(BVF.getMinValue(indexTy));
341 
342   // Adjust the index.
343   SVal newIdx = svalBuilder.evalBinOpNN(this, BO_Add,
344                                         Idx.castAs<NonLoc>(), Min, indexTy);
345   if (newIdx.isUnknownOrUndef())
346     return this;
347 
348   // Adjust the upper bound.
349   SVal newBound =
350     svalBuilder.evalBinOpNN(this, BO_Add, UpperBound.castAs<NonLoc>(),
351                             Min, indexTy);
352 
353   if (newBound.isUnknownOrUndef())
354     return this;
355 
356   // Build the actual comparison.
357   SVal inBound = svalBuilder.evalBinOpNN(this, BO_LT, newIdx.castAs<NonLoc>(),
358                                          newBound.castAs<NonLoc>(), Ctx.IntTy);
359   if (inBound.isUnknownOrUndef())
360     return this;
361 
362   // Finally, let the constraint manager take care of it.
363   ConstraintManager &CM = SM.getConstraintManager();
364   return CM.assume(this, inBound.castAs<DefinedSVal>(), Assumption);
365 }
366 
367 ConditionTruthVal ProgramState::isNonNull(SVal V) const {
368   ConditionTruthVal IsNull = isNull(V);
369   if (IsNull.isUnderconstrained())
370     return IsNull;
371   return ConditionTruthVal(!IsNull.getValue());
372 }
373 
374 ConditionTruthVal ProgramState::areEqual(SVal Lhs, SVal Rhs) const {
375   return stateMgr->getSValBuilder().areEqual(this, Lhs, Rhs);
376 }
377 
378 ConditionTruthVal ProgramState::isNull(SVal V) const {
379   if (V.isZeroConstant())
380     return true;
381 
382   if (V.isConstant())
383     return false;
384 
385   SymbolRef Sym = V.getAsSymbol(/* IncludeBaseRegion */ true);
386   if (!Sym)
387     return ConditionTruthVal();
388 
389   return getStateManager().ConstraintMgr->isNull(this, Sym);
390 }
391 
392 ProgramStateRef ProgramStateManager::getInitialState(const LocationContext *InitLoc) {
393   ProgramState State(this,
394                 EnvMgr.getInitialEnvironment(),
395                 StoreMgr->getInitialStore(InitLoc),
396                 GDMFactory.getEmptyMap());
397 
398   return getPersistentState(State);
399 }
400 
401 ProgramStateRef ProgramStateManager::getPersistentStateWithGDM(
402                                                      ProgramStateRef FromState,
403                                                      ProgramStateRef GDMState) {
404   ProgramState NewState(*FromState);
405   NewState.GDM = GDMState->GDM;
406   return getPersistentState(NewState);
407 }
408 
409 ProgramStateRef ProgramStateManager::getPersistentState(ProgramState &State) {
410 
411   llvm::FoldingSetNodeID ID;
412   State.Profile(ID);
413   void *InsertPos;
414 
415   if (ProgramState *I = StateSet.FindNodeOrInsertPos(ID, InsertPos))
416     return I;
417 
418   ProgramState *newState = nullptr;
419   if (!freeStates.empty()) {
420     newState = freeStates.back();
421     freeStates.pop_back();
422   }
423   else {
424     newState = (ProgramState*) Alloc.Allocate<ProgramState>();
425   }
426   new (newState) ProgramState(State);
427   StateSet.InsertNode(newState, InsertPos);
428   return newState;
429 }
430 
431 ProgramStateRef ProgramState::makeWithStore(const StoreRef &store) const {
432   ProgramState NewSt(*this);
433   NewSt.setStore(store);
434   return getStateManager().getPersistentState(NewSt);
435 }
436 
437 void ProgramState::setStore(const StoreRef &newStore) {
438   Store newStoreStore = newStore.getStore();
439   if (newStoreStore)
440     stateMgr->getStoreManager().incrementReferenceCount(newStoreStore);
441   if (store)
442     stateMgr->getStoreManager().decrementReferenceCount(store);
443   store = newStoreStore;
444 }
445 
446 //===----------------------------------------------------------------------===//
447 //  State pretty-printing.
448 //===----------------------------------------------------------------------===//
449 
450 void ProgramState::printJson(raw_ostream &Out, const LocationContext *LCtx,
451                              const char *NL, unsigned int Space,
452                              bool IsDot) const {
453   Indent(Out, Space, IsDot) << "\"program_state\": {" << NL;
454   ++Space;
455 
456   ProgramStateManager &Mgr = getStateManager();
457 
458   // Print the store.
459   Mgr.getStoreManager().printJson(Out, getStore(), NL, Space, IsDot);
460 
461   // Print out the environment.
462   Env.printJson(Out, Mgr.getContext(), LCtx, NL, Space, IsDot);
463 
464   // Print out the constraints.
465   Mgr.getConstraintManager().printJson(Out, this, NL, Space, IsDot);
466 
467   // Print out the tracked dynamic types.
468   printDynamicTypeInfoJson(Out, this, NL, Space, IsDot);
469 
470   // Print checker-specific data.
471   Mgr.getOwningEngine().printJson(Out, this, LCtx, NL, Space, IsDot);
472 
473   --Space;
474   Indent(Out, Space, IsDot) << '}';
475 }
476 
477 void ProgramState::printDOT(raw_ostream &Out, const LocationContext *LCtx,
478                             unsigned int Space) const {
479   printJson(Out, LCtx, /*NL=*/"\\l", Space, /*IsDot=*/true);
480 }
481 
482 LLVM_DUMP_METHOD void ProgramState::dump() const {
483   printJson(llvm::errs());
484 }
485 
486 AnalysisManager& ProgramState::getAnalysisManager() const {
487   return stateMgr->getOwningEngine().getAnalysisManager();
488 }
489 
490 //===----------------------------------------------------------------------===//
491 // Generic Data Map.
492 //===----------------------------------------------------------------------===//
493 
494 void *const* ProgramState::FindGDM(void *K) const {
495   return GDM.lookup(K);
496 }
497 
498 void*
499 ProgramStateManager::FindGDMContext(void *K,
500                                void *(*CreateContext)(llvm::BumpPtrAllocator&),
501                                void (*DeleteContext)(void*)) {
502 
503   std::pair<void*, void (*)(void*)>& p = GDMContexts[K];
504   if (!p.first) {
505     p.first = CreateContext(Alloc);
506     p.second = DeleteContext;
507   }
508 
509   return p.first;
510 }
511 
512 ProgramStateRef ProgramStateManager::addGDM(ProgramStateRef St, void *Key, void *Data){
513   ProgramState::GenericDataMap M1 = St->getGDM();
514   ProgramState::GenericDataMap M2 = GDMFactory.add(M1, Key, Data);
515 
516   if (M1 == M2)
517     return St;
518 
519   ProgramState NewSt = *St;
520   NewSt.GDM = M2;
521   return getPersistentState(NewSt);
522 }
523 
524 ProgramStateRef ProgramStateManager::removeGDM(ProgramStateRef state, void *Key) {
525   ProgramState::GenericDataMap OldM = state->getGDM();
526   ProgramState::GenericDataMap NewM = GDMFactory.remove(OldM, Key);
527 
528   if (NewM == OldM)
529     return state;
530 
531   ProgramState NewState = *state;
532   NewState.GDM = NewM;
533   return getPersistentState(NewState);
534 }
535 
536 bool ScanReachableSymbols::scan(nonloc::LazyCompoundVal val) {
537   bool wasVisited = !visited.insert(val.getCVData()).second;
538   if (wasVisited)
539     return true;
540 
541   StoreManager &StoreMgr = state->getStateManager().getStoreManager();
542   // FIXME: We don't really want to use getBaseRegion() here because pointer
543   // arithmetic doesn't apply, but scanReachableSymbols only accepts base
544   // regions right now.
545   const MemRegion *R = val.getRegion()->getBaseRegion();
546   return StoreMgr.scanReachableSymbols(val.getStore(), R, *this);
547 }
548 
549 bool ScanReachableSymbols::scan(nonloc::CompoundVal val) {
550   for (nonloc::CompoundVal::iterator I=val.begin(), E=val.end(); I!=E; ++I)
551     if (!scan(*I))
552       return false;
553 
554   return true;
555 }
556 
557 bool ScanReachableSymbols::scan(const SymExpr *sym) {
558   for (SymExpr::symbol_iterator SI = sym->symbol_begin(),
559                                 SE = sym->symbol_end();
560        SI != SE; ++SI) {
561     bool wasVisited = !visited.insert(*SI).second;
562     if (wasVisited)
563       continue;
564 
565     if (!visitor.VisitSymbol(*SI))
566       return false;
567   }
568 
569   return true;
570 }
571 
572 bool ScanReachableSymbols::scan(SVal val) {
573   if (Optional<loc::MemRegionVal> X = val.getAs<loc::MemRegionVal>())
574     return scan(X->getRegion());
575 
576   if (Optional<nonloc::LazyCompoundVal> X =
577           val.getAs<nonloc::LazyCompoundVal>())
578     return scan(*X);
579 
580   if (Optional<nonloc::LocAsInteger> X = val.getAs<nonloc::LocAsInteger>())
581     return scan(X->getLoc());
582 
583   if (SymbolRef Sym = val.getAsSymbol())
584     return scan(Sym);
585 
586   if (const SymExpr *Sym = val.getAsSymbolicExpression())
587     return scan(Sym);
588 
589   if (Optional<nonloc::CompoundVal> X = val.getAs<nonloc::CompoundVal>())
590     return scan(*X);
591 
592   return true;
593 }
594 
595 bool ScanReachableSymbols::scan(const MemRegion *R) {
596   if (isa<MemSpaceRegion>(R))
597     return true;
598 
599   bool wasVisited = !visited.insert(R).second;
600   if (wasVisited)
601     return true;
602 
603   if (!visitor.VisitMemRegion(R))
604     return false;
605 
606   // If this is a symbolic region, visit the symbol for the region.
607   if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R))
608     if (!visitor.VisitSymbol(SR->getSymbol()))
609       return false;
610 
611   // If this is a subregion, also visit the parent regions.
612   if (const SubRegion *SR = dyn_cast<SubRegion>(R)) {
613     const MemRegion *Super = SR->getSuperRegion();
614     if (!scan(Super))
615       return false;
616 
617     // When we reach the topmost region, scan all symbols in it.
618     if (isa<MemSpaceRegion>(Super)) {
619       StoreManager &StoreMgr = state->getStateManager().getStoreManager();
620       if (!StoreMgr.scanReachableSymbols(state->getStore(), SR, *this))
621         return false;
622     }
623   }
624 
625   // Regions captured by a block are also implicitly reachable.
626   if (const BlockDataRegion *BDR = dyn_cast<BlockDataRegion>(R)) {
627     BlockDataRegion::referenced_vars_iterator I = BDR->referenced_vars_begin(),
628                                               E = BDR->referenced_vars_end();
629     for ( ; I != E; ++I) {
630       if (!scan(I.getCapturedRegion()))
631         return false;
632     }
633   }
634 
635   return true;
636 }
637 
638 bool ProgramState::scanReachableSymbols(SVal val, SymbolVisitor& visitor) const {
639   ScanReachableSymbols S(this, visitor);
640   return S.scan(val);
641 }
642 
643 bool ProgramState::scanReachableSymbols(
644     llvm::iterator_range<region_iterator> Reachable,
645     SymbolVisitor &visitor) const {
646   ScanReachableSymbols S(this, visitor);
647   for (const MemRegion *R : Reachable) {
648     if (!S.scan(R))
649       return false;
650   }
651   return true;
652 }
653