clang  9.0.0svn
ProgramState.cpp
Go to the documentation of this file.
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 
15 #include "clang/Analysis/CFG.h"
20 #include "llvm/Support/raw_ostream.h"
21 
22 using namespace clang;
23 using namespace ento;
24 
25 namespace clang { namespace ento {
26 /// Increments the number of times this state is referenced.
27 
29  ++const_cast<ProgramState*>(state)->refCount;
30 }
31 
32 /// Decrement the number of times this state is referenced.
34  assert(state->refCount > 0);
35  ProgramState *s = const_cast<ProgramState*>(state);
36  if (--s->refCount == 0) {
38  Mgr.StateSet.RemoveNode(s);
39  s->~ProgramState();
40  Mgr.freeStates.push_back(s);
41  }
42 }
43 }}
44 
46  StoreRef st, GenericDataMap gdm)
47  : stateMgr(mgr),
48  Env(env),
49  store(st.getStore()),
50  GDM(gdm),
51  refCount(0) {
52  stateMgr->getStoreManager().incrementReferenceCount(store);
53 }
54 
56  : llvm::FoldingSetNode(),
57  stateMgr(RHS.stateMgr),
58  Env(RHS.Env),
59  store(RHS.store),
60  GDM(RHS.GDM),
61  refCount(0) {
62  stateMgr->getStoreManager().incrementReferenceCount(store);
63 }
64 
66  if (store)
67  stateMgr->getStoreManager().decrementReferenceCount(store);
68 }
69 
70 int64_t ProgramState::getID() const {
71  return getStateManager().Alloc.identifyKnownAlignedObject<ProgramState>(this);
72 }
73 
75  StoreManagerCreator CreateSMgr,
76  ConstraintManagerCreator CreateCMgr,
77  llvm::BumpPtrAllocator &alloc,
78  SubEngine *SubEng)
79  : Eng(SubEng), EnvMgr(alloc), GDMFactory(alloc),
80  svalBuilder(createSimpleSValBuilder(alloc, Ctx, *this)),
81  CallEventMgr(new CallEventManager(alloc)), Alloc(alloc) {
82  StoreMgr = (*CreateSMgr)(*this);
83  ConstraintMgr = (*CreateCMgr)(*this, SubEng);
84 }
85 
86 
88  for (GDMContextsTy::iterator I=GDMContexts.begin(), E=GDMContexts.end();
89  I!=E; ++I)
90  I->second.second(I->second.first);
91 }
92 
95  const StackFrameContext *LCtx,
96  SymbolReaper& SymReaper) {
97 
98  // This code essentially performs a "mark-and-sweep" of the VariableBindings.
99  // The roots are any Block-level exprs and Decls that our liveness algorithm
100  // tells us are live. We then see what Decls they may reference, and keep
101  // those around. This code more than likely can be made faster, and the
102  // frequency of which this method is called should be experimented with
103  // for optimum performance.
104  ProgramState NewState = *state;
105 
106  NewState.Env = EnvMgr.removeDeadBindings(NewState.Env, SymReaper, state);
107 
108  // Clean up the store.
109  StoreRef newStore = StoreMgr->removeDeadBindings(NewState.getStore(), LCtx,
110  SymReaper);
111  NewState.setStore(newStore);
112  SymReaper.setReapedStore(newStore);
113 
114  ProgramStateRef Result = getPersistentState(NewState);
115  return ConstraintMgr->removeDeadBindings(Result, SymReaper);
116 }
117 
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 
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 
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 
153 
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 
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 
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;
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  newState = Eng.notifyCheckersOfPointerEscape(newState, IS,
214  TopLevelInvalidated,
215  Call,
216  *ITraits);
217  }
218 
219  return Eng.processRegionChanges(newState, IS, TopLevelInvalidated,
220  Invalidated, LCtx, Call);
221 }
222 
224  assert(!LV.getAs<loc::MemRegionVal>() && "Use invalidateRegion instead.");
225 
226  Store OldStore = getStore();
227  const StoreRef &newStore =
228  getStateManager().StoreMgr->killBinding(OldStore, LV);
229 
230  if (newStore.getStore() == OldStore)
231  return this;
232 
233  return makeWithStore(newStore);
234 }
235 
238  const StackFrameContext *CalleeCtx) const {
239  const StoreRef &NewStore =
240  getStateManager().StoreMgr->enterStackFrame(getStore(), Call, CalleeCtx);
241  return makeWithStore(NewStore);
242 }
243 
245  // We only want to do fetches from regions that we can actually bind
246  // values. For example, SymbolicRegions of type 'id<...>' cannot
247  // have direct bindings (but their can be bindings on their subregions).
248  if (!R->isBoundable())
249  return UnknownVal();
250 
251  if (const TypedValueRegion *TR = dyn_cast<TypedValueRegion>(R)) {
252  QualType T = TR->getValueType();
254  return getSVal(R);
255  }
256 
257  return UnknownVal();
258 }
259 
260 SVal ProgramState::getSVal(Loc location, QualType T) const {
261  SVal V = getRawSVal(location, T);
262 
263  // If 'V' is a symbolic value that is *perfectly* constrained to
264  // be a constant value, use that value instead to lessen the burden
265  // on later analysis stages (so we have less symbolic values to reason
266  // about).
267  // We only go into this branch if we can convert the APSInt value we have
268  // to the type of T, which is not always the case (e.g. for void).
269  if (!T.isNull() && (T->isIntegralOrEnumerationType() || Loc::isLocType(T))) {
270  if (SymbolRef sym = V.getAsSymbol()) {
271  if (const llvm::APSInt *Int = getStateManager()
272  .getConstraintManager()
273  .getSymVal(this, sym)) {
274  // FIXME: Because we don't correctly model (yet) sign-extension
275  // and truncation of symbolic values, we need to convert
276  // the integer value to the correct signedness and bitwidth.
277  //
278  // This shows up in the following:
279  //
280  // char foo();
281  // unsigned x = foo();
282  // if (x == 54)
283  // ...
284  //
285  // The symbolic value stored to 'x' is actually the conjured
286  // symbol for the call to foo(); the type of that symbol is 'char',
287  // not unsigned.
288  const llvm::APSInt &NewV = getBasicVals().Convert(T, *Int);
289 
290  if (V.getAs<Loc>())
291  return loc::ConcreteInt(NewV);
292  else
293  return nonloc::ConcreteInt(NewV);
294  }
295  }
296  }
297 
298  return V;
299 }
300 
302  const LocationContext *LCtx,
303  SVal V, bool Invalidate) const{
304  Environment NewEnv =
305  getStateManager().EnvMgr.bindExpr(Env, EnvironmentEntry(S, LCtx), V,
306  Invalidate);
307  if (NewEnv == Env)
308  return this;
309 
310  ProgramState NewSt = *this;
311  NewSt.Env = NewEnv;
312  return getStateManager().getPersistentState(NewSt);
313 }
314 
316  DefinedOrUnknownSVal UpperBound,
317  bool Assumption,
318  QualType indexTy) const {
319  if (Idx.isUnknown() || UpperBound.isUnknown())
320  return this;
321 
322  // Build an expression for 0 <= Idx < UpperBound.
323  // This is the same as Idx + MIN < UpperBound + MIN, if overflow is allowed.
324  // FIXME: This should probably be part of SValBuilder.
325  ProgramStateManager &SM = getStateManager();
326  SValBuilder &svalBuilder = SM.getSValBuilder();
327  ASTContext &Ctx = svalBuilder.getContext();
328 
329  // Get the offset: the minimum value of the array index type.
330  BasicValueFactory &BVF = svalBuilder.getBasicValueFactory();
331  if (indexTy.isNull())
332  indexTy = svalBuilder.getArrayIndexType();
333  nonloc::ConcreteInt Min(BVF.getMinValue(indexTy));
334 
335  // Adjust the index.
336  SVal newIdx = svalBuilder.evalBinOpNN(this, BO_Add,
337  Idx.castAs<NonLoc>(), Min, indexTy);
338  if (newIdx.isUnknownOrUndef())
339  return this;
340 
341  // Adjust the upper bound.
342  SVal newBound =
343  svalBuilder.evalBinOpNN(this, BO_Add, UpperBound.castAs<NonLoc>(),
344  Min, indexTy);
345 
346  if (newBound.isUnknownOrUndef())
347  return this;
348 
349  // Build the actual comparison.
350  SVal inBound = svalBuilder.evalBinOpNN(this, BO_LT, newIdx.castAs<NonLoc>(),
351  newBound.castAs<NonLoc>(), Ctx.IntTy);
352  if (inBound.isUnknownOrUndef())
353  return this;
354 
355  // Finally, let the constraint manager take care of it.
357  return CM.assume(this, inBound.castAs<DefinedSVal>(), Assumption);
358 }
359 
361  ConditionTruthVal IsNull = isNull(V);
362  if (IsNull.isUnderconstrained())
363  return IsNull;
364  return ConditionTruthVal(!IsNull.getValue());
365 }
366 
368  return stateMgr->getSValBuilder().areEqual(this, Lhs, Rhs);
369 }
370 
372  if (V.isZeroConstant())
373  return true;
374 
375  if (V.isConstant())
376  return false;
377 
378  SymbolRef Sym = V.getAsSymbol(/* IncludeBaseRegion */ true);
379  if (!Sym)
380  return ConditionTruthVal();
381 
382  return getStateManager().ConstraintMgr->isNull(this, Sym);
383 }
384 
386  ProgramState State(this,
387  EnvMgr.getInitialEnvironment(),
388  StoreMgr->getInitialStore(InitLoc),
389  GDMFactory.getEmptyMap());
390 
391  return getPersistentState(State);
392 }
393 
395  ProgramStateRef FromState,
396  ProgramStateRef GDMState) {
397  ProgramState NewState(*FromState);
398  NewState.GDM = GDMState->GDM;
399  return getPersistentState(NewState);
400 }
401 
403 
404  llvm::FoldingSetNodeID ID;
405  State.Profile(ID);
406  void *InsertPos;
407 
408  if (ProgramState *I = StateSet.FindNodeOrInsertPos(ID, InsertPos))
409  return I;
410 
411  ProgramState *newState = nullptr;
412  if (!freeStates.empty()) {
413  newState = freeStates.back();
414  freeStates.pop_back();
415  }
416  else {
417  newState = (ProgramState*) Alloc.Allocate<ProgramState>();
418  }
419  new (newState) ProgramState(State);
420  StateSet.InsertNode(newState, InsertPos);
421  return newState;
422 }
423 
424 ProgramStateRef ProgramState::makeWithStore(const StoreRef &store) const {
425  ProgramState NewSt(*this);
426  NewSt.setStore(store);
427  return getStateManager().getPersistentState(NewSt);
428 }
429 
430 void ProgramState::setStore(const StoreRef &newStore) {
431  Store newStoreStore = newStore.getStore();
432  if (newStoreStore)
433  stateMgr->getStoreManager().incrementReferenceCount(newStoreStore);
434  if (store)
435  stateMgr->getStoreManager().decrementReferenceCount(store);
436  store = newStoreStore;
437 }
438 
439 //===----------------------------------------------------------------------===//
440 // State pretty-printing.
441 //===----------------------------------------------------------------------===//
442 
443 void ProgramState::print(raw_ostream &Out,
444  const char *NL, const char *Sep,
445  const LocationContext *LC) const {
446  // Print the store.
447  ProgramStateManager &Mgr = getStateManager();
448  const ASTContext &Context = getStateManager().getContext();
449  Mgr.getStoreManager().print(getStore(), Out, NL);
450 
451  // Print out the environment.
452  Env.print(Out, NL, Sep, Context, LC);
453 
454  // Print out the constraints.
455  Mgr.getConstraintManager().print(this, Out, NL, Sep);
456 
457  // Print out the tracked dynamic types.
458  printDynamicTypeInfo(this, Out, NL, Sep);
459 
460  // Print checker-specific data.
461  Mgr.getOwningEngine().printState(Out, this, NL, Sep, LC);
462 }
463 
464 void ProgramState::printDOT(raw_ostream &Out,
465  const LocationContext *LC) const {
466  print(Out, "\\l", "\\|", LC);
467 }
468 
469 LLVM_DUMP_METHOD void ProgramState::dump() const {
470  print(llvm::errs());
471 }
472 
474  return stateMgr->getOwningEngine().getAnalysisManager();
475 }
476 
477 //===----------------------------------------------------------------------===//
478 // Generic Data Map.
479 //===----------------------------------------------------------------------===//
480 
481 void *const* ProgramState::FindGDM(void *K) const {
482  return GDM.lookup(K);
483 }
484 
485 void*
487  void *(*CreateContext)(llvm::BumpPtrAllocator&),
488  void (*DeleteContext)(void*)) {
489 
490  std::pair<void*, void (*)(void*)>& p = GDMContexts[K];
491  if (!p.first) {
492  p.first = CreateContext(Alloc);
493  p.second = DeleteContext;
494  }
495 
496  return p.first;
497 }
498 
500  ProgramState::GenericDataMap M1 = St->getGDM();
501  ProgramState::GenericDataMap M2 = GDMFactory.add(M1, Key, Data);
502 
503  if (M1 == M2)
504  return St;
505 
506  ProgramState NewSt = *St;
507  NewSt.GDM = M2;
508  return getPersistentState(NewSt);
509 }
510 
512  ProgramState::GenericDataMap OldM = state->getGDM();
513  ProgramState::GenericDataMap NewM = GDMFactory.remove(OldM, Key);
514 
515  if (NewM == OldM)
516  return state;
517 
518  ProgramState NewState = *state;
519  NewState.GDM = NewM;
520  return getPersistentState(NewState);
521 }
522 
524  bool wasVisited = !visited.insert(val.getCVData()).second;
525  if (wasVisited)
526  return true;
527 
528  StoreManager &StoreMgr = state->getStateManager().getStoreManager();
529  // FIXME: We don't really want to use getBaseRegion() here because pointer
530  // arithmetic doesn't apply, but scanReachableSymbols only accepts base
531  // regions right now.
532  const MemRegion *R = val.getRegion()->getBaseRegion();
533  return StoreMgr.scanReachableSymbols(val.getStore(), R, *this);
534 }
535 
537  for (nonloc::CompoundVal::iterator I=val.begin(), E=val.end(); I!=E; ++I)
538  if (!scan(*I))
539  return false;
540 
541  return true;
542 }
543 
545  for (SymExpr::symbol_iterator SI = sym->symbol_begin(),
546  SE = sym->symbol_end();
547  SI != SE; ++SI) {
548  bool wasVisited = !visited.insert(*SI).second;
549  if (wasVisited)
550  continue;
551 
552  if (!visitor.VisitSymbol(*SI))
553  return false;
554  }
555 
556  return true;
557 }
558 
561  return scan(X->getRegion());
562 
565  return scan(*X);
566 
568  return scan(X->getLoc());
569 
570  if (SymbolRef Sym = val.getAsSymbol())
571  return scan(Sym);
572 
573  if (const SymExpr *Sym = val.getAsSymbolicExpression())
574  return scan(Sym);
575 
577  return scan(*X);
578 
579  return true;
580 }
581 
583  if (isa<MemSpaceRegion>(R))
584  return true;
585 
586  bool wasVisited = !visited.insert(R).second;
587  if (wasVisited)
588  return true;
589 
590  if (!visitor.VisitMemRegion(R))
591  return false;
592 
593  // If this is a symbolic region, visit the symbol for the region.
594  if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R))
595  if (!visitor.VisitSymbol(SR->getSymbol()))
596  return false;
597 
598  // If this is a subregion, also visit the parent regions.
599  if (const SubRegion *SR = dyn_cast<SubRegion>(R)) {
600  const MemRegion *Super = SR->getSuperRegion();
601  if (!scan(Super))
602  return false;
603 
604  // When we reach the topmost region, scan all symbols in it.
605  if (isa<MemSpaceRegion>(Super)) {
606  StoreManager &StoreMgr = state->getStateManager().getStoreManager();
607  if (!StoreMgr.scanReachableSymbols(state->getStore(), SR, *this))
608  return false;
609  }
610  }
611 
612  // Regions captured by a block are also implicitly reachable.
613  if (const BlockDataRegion *BDR = dyn_cast<BlockDataRegion>(R)) {
614  BlockDataRegion::referenced_vars_iterator I = BDR->referenced_vars_begin(),
615  E = BDR->referenced_vars_end();
616  for ( ; I != E; ++I) {
617  if (!scan(I.getCapturedRegion()))
618  return false;
619  }
620  }
621 
622  return true;
623 }
624 
626  ScanReachableSymbols S(this, visitor);
627  return S.scan(val);
628 }
629 
631  llvm::iterator_range<region_iterator> Reachable,
632  SymbolVisitor &visitor) const {
633  ScanReachableSymbols S(this, visitor);
634  for (const MemRegion *R : Reachable) {
635  if (!S.scan(R))
636  return false;
637  }
638  return true;
639 }
virtual ProgramStateRef assume(ProgramStateRef state, DefinedSVal Cond, bool Assumption)=0
ProgramStateRef addGDM(ProgramStateRef St, void *Key, void *Data)
TypedValueRegion - An abstract class representing regions having a typed value.
Definition: MemRegion.h:529
ProgramStateRef processRegionChange(ProgramStateRef state, const MemRegion *MR, const LocationContext *LCtx)
Definition: SubEngine.h:145
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
QualType getArrayIndexType() const
Definition: SValBuilder.h:164
A (possibly-)qualified type.
Definition: Type.h:639
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:94
bool isUnderconstrained() const
Return true if the constrained is underconstrained and we do not know if the constraint is true of va...
Store getStore() const
Definition: StoreRef.h:46
LLVM_NODISCARD ProgramStateRef enterStackFrame(const CallEvent &Call, const StackFrameContext *CalleeCtx) const
enterStackFrame - Returns the state for entry to the given stack frame, preserving the current state...
llvm::DenseSet< SymbolRef > InvalidatedSymbols
Definition: Store.h:51
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:29
SValBuilder * createSimpleSValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context, ProgramStateManager &stateMgr)
Stmt - This represents one statement.
Definition: Stmt.h:65
BasicValueFactory & getBasicVals()
Definition: ProgramState.h:500
Manages the lifetime of CallEvent objects.
Definition: CallEvent.h:1086
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
Value representing integer constant.
Definition: SVals.h:376
ConditionTruthVal isNonNull(SVal V) const
Check if the given SVal is not constrained to zero and is not a zero constant.
A utility class that visits the reachable symbols using a custom SymbolVisitor.
Definition: ProgramState.h:855
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
Definition: StoreRef.h:27
ProgramStateRef removeDeadBindings(ProgramStateRef St, const StackFrameContext *LCtx, SymbolReaper &SymReaper)
Store getStore() const
Return the store associated with this state.
Definition: ProgramState.h:125
LLVM_NODISCARD ProgramStateRef bindDefaultInitial(SVal loc, SVal V, const LocationContext *LCtx) const
Initializes the region of memory represented by loc with an initial value.
Symbolic value.
Definition: SymExpr.h:29
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
LineState State
llvm::ImmutableList< SVal >::iterator iterator
Definition: SVals.h:464
std::unique_ptr< StoreManager >(* StoreManagerCreator)(ProgramStateManager &)
Definition: ProgramState.h:43
symbol_iterator symbol_begin() const
Definition: SymExpr.h:86
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
const SymExpr * getAsSymbolicExpression() const
getAsSymbolicExpression - If this Sval wraps a symbolic expression then return that expression...
Definition: SVals.cpp:136
void setReapedStore(StoreRef st)
Set to the value of the symbolic store after StoreManager::removeDeadBindings has been called...
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition: Type.h:6664
const llvm::APSInt & Convert(const llvm::APSInt &To, const llvm::APSInt &From)
Convert - Create a new persistent APSInt with the same value as &#39;From&#39; but with the bitwidth and sign...
static bool isLocType(QualType T)
Definition: SVals.h:326
ProgramStateManager & getStateManager() const
Return the ProgramStateManager associated with this state.
Definition: ProgramState.h:110
BlockDataRegion - A region that represents a block instance.
Definition: MemRegion.h:672
AnalysisManager & getAnalysisManager() const
bool scanReachableSymbols(SVal val, SymbolVisitor &visitor) const
Visits the symbols reachable from the given SVal using the provided SymbolVisitor.
virtual void print(Store store, raw_ostream &Out, const char *nl)=0
bool isUnknown() const
Definition: SVals.h:136
virtual void decrementReferenceCount(Store store)
If the StoreManager supports it, decrement the reference count of the specified Store object...
Definition: Store.h:207
const LazyCompoundValData * getCVData() const
Definition: SVals.h:490
SmallVector< const MemRegion *, 8 > InvalidatedRegions
Definition: Store.h:209
bool isConstant() const
Definition: SVals.cpp:221
SVal getSVal(const Stmt *S, const LocationContext *LCtx) const
Returns the SVal bound to the statement &#39;S&#39; in the state&#39;s environment.
Definition: ProgramState.h:755
virtual void print(ProgramStateRef state, raw_ostream &Out, const char *nl, const char *sep)=0
SymbolRef getAsSymbol(bool IncludeBaseRegions=false) const
If this SVal wraps a symbol return that SymbolRef.
Definition: SVals.cpp:126
std::unique_ptr< ConstraintManager >(* ConstraintManagerCreator)(ProgramStateManager &, SubEngine *)
Definition: ProgramState.h:41
LLVM_NODISCARD ProgramStateRef BindExpr(const Stmt *S, const LocationContext *LCtx, SVal V, bool Invalidate=true) const
Create a new state by binding the value &#39;V&#39; to the statement &#39;S&#39; in the state&#39;s environment.
llvm::ImmutableMap< void *, void * > GenericDataMap
Definition: ProgramState.h:75
SymbolicRegion - A special, "non-concrete" region.
Definition: MemRegion.h:763
ProgramState - This class encapsulates:
Definition: ProgramState.h:72
This represents one expression.
Definition: Expr.h:108
SourceLocation End
LLVM_NODISCARD ProgramStateRef bindDefaultZero(SVal loc, const LocationContext *LCtx) const
Performs C++ zero-initialization procedure on the region of memory represented by loc...
ConditionTruthVal isNull(SVal V) const
Check if the given SVal is constrained to zero or is a zero constant.
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:704
const SourceManager & SM
Definition: Format.cpp:1568
void *const * FindGDM(void *K) const
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
Definition: SVals.h:111
LLVM_NODISCARD ProgramStateRef bindLoc(Loc location, SVal V, const LocationContext *LCtx, bool notifyChanges=true) const
virtual bool isBoundable() const
Definition: MemRegion.h:173
ProgramStateRef removeGDM(ProgramStateRef state, void *Key)
bool scan(nonloc::LazyCompoundVal val)
void print(raw_ostream &Out, const char *nl="\, const char *sep="", const LocationContext *CurrentLC=nullptr) const
ProgramStateRef getInitialState(const LocationContext *InitLoc)
const MemRegion * getAsRegion() const
Definition: SVals.cpp:150
An entry in the environment consists of a Stmt and an LocationContext.
Definition: Environment.h:35
ASTContext & getContext()
Definition: SValBuilder.h:155
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
Definition: SVals.h:75
A class responsible for cleaning up unused symbols.
ConditionTruthVal areEqual(SVal Lhs, SVal Rhs) const
virtual void printState(raw_ostream &Out, ProgramStateRef State, const char *NL, const char *Sep, const LocationContext *LCtx=nullptr)=0
printState - Called by ProgramStateManager to print checker-specific data.
ProgramStateRef getPersistentStateWithGDM(ProgramStateRef FromState, ProgramStateRef GDMState)
virtual SVal evalBinOpNN(ProgramStateRef state, BinaryOperator::Opcode op, NonLoc lhs, NonLoc rhs, QualType resultTy)=0
Create a new value which represents a binary expression with two non- location operands.
An immutable map from EnvironemntEntries to SVals.
Definition: Environment.h:56
LLVM_NODISCARD ProgramStateRef invalidateRegions(ArrayRef< const MemRegion *> Regions, const Expr *E, unsigned BlockCount, const LocationContext *LCtx, bool CausesPointerEscape, InvalidatedSymbols *IS=nullptr, const CallEvent *Call=nullptr, RegionAndSymbolInvalidationTraits *ITraits=nullptr) const
Returns the state with bindings for the given regions cleared from the store.
Dataflow Directional Tag Classes.
void ProgramStateRelease(const ProgramState *state)
Decrement the number of times this state is referenced.
ArrayRef< const MemRegion * > RegionList
bool isZeroConstant() const
Definition: SVals.cpp:233
static symbol_iterator symbol_end()
Definition: SymExpr.h:87
LLVM_NODISCARD ProgramStateRef killBinding(Loc LV) const
const void * getStore() const
Definition: SVals.cpp:165
Represents an abstract call to a function or method along a particular path.
Definition: CallEvent.h:170
virtual bool scanReachableSymbols(Store S, const MemRegion *R, ScanReachableSymbols &Visitor)=0
Finds the transitive closure of symbols within the given region.
const llvm::APSInt & getMinValue(const llvm::APSInt &v)
ConstraintManager & getConstraintManager()
Definition: ProgramState.h:527
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
Definition: SVals.h:103
BasicValueFactory & getBasicValueFactory()
Definition: SValBuilder.h:168
SubRegion - A region that subsets another larger region.
Definition: MemRegion.h:435
ProgramState(ProgramStateManager *mgr, const Environment &env, StoreRef st, GenericDataMap gdm)
This ctor is used when creating the first ProgramState object.
void ProgramStateRetain(const ProgramState *state)
Increments the number of times this state is referenced.
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
Definition: SemaDecl.cpp:14051
ProgramStateManager(ASTContext &Ctx, StoreManagerCreator CreateStoreManager, ConstraintManagerCreator CreateConstraintManager, llvm::BumpPtrAllocator &alloc, SubEngine *subeng)
const TypedValueRegion * getRegion() const
Definition: SVals.cpp:169
Environment removeDeadBindings(Environment Env, SymbolReaper &SymReaper, ProgramStateRef state)
void printDOT(raw_ostream &Out, const LocationContext *CurrentLC=nullptr) const
void * FindGDMContext(void *index, void *(*CreateContext)(llvm::BumpPtrAllocator &), void(*DeleteContext)(void *))
const MemRegion * getBaseRegion() const
Definition: MemRegion.cpp:1160
virtual void incrementReferenceCount(Store store)
If the StoreManager supports it, increment the reference count of the specified Store object...
Definition: Store.h:202
CanQualType IntTy
Definition: ASTContext.h:1024
static void Profile(llvm::FoldingSetNodeID &ID, const ProgramState *V)
Profile - Profile the contents of a ProgramState object for use in a FoldingSet.
Definition: ProgramState.h:136
LLVM_NODISCARD ProgramStateRef assumeInBound(DefinedOrUnknownSVal idx, DefinedOrUnknownSVal upperBound, bool assumption, QualType IndexType=QualType()) const
ProgramStateRef getPersistentState(ProgramState &Impl)
SVal getSValAsScalarOrLoc(const Stmt *Ex, const LocationContext *LCtx) const
Definition: ProgramState.h:762
void printDynamicTypeInfo(ProgramStateRef State, raw_ostream &Out, const char *NL, const char *Sep)
bool isUnknownOrUndef() const
Definition: SVals.h:144
ArrayRef< SVal > ValueList
Iterator over symbols that the current symbol depends on.
Definition: SymExpr.h:70