clang  10.0.0git
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 
14 #include "clang/Analysis/CFG.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 
30  ++const_cast<ProgramState*>(state)->refCount;
31 }
32 
33 /// Decrement the number of times this state is referenced.
35  assert(state->refCount > 0);
36  ProgramState *s = const_cast<ProgramState*>(state);
37  if (--s->refCount == 0) {
39  Mgr.StateSet.RemoveNode(s);
40  s->~ProgramState();
41  Mgr.freeStates.push_back(s);
42  }
43 }
44 }}
45 
47  StoreRef st, GenericDataMap gdm)
48  : stateMgr(mgr),
49  Env(env),
50  store(st.getStore()),
51  GDM(gdm),
52  refCount(0) {
53  stateMgr->getStoreManager().incrementReferenceCount(store);
54 }
55 
57  : llvm::FoldingSetNode(),
58  stateMgr(RHS.stateMgr),
59  Env(RHS.Env),
60  store(RHS.store),
61  GDM(RHS.GDM),
62  refCount(0) {
63  stateMgr->getStoreManager().incrementReferenceCount(store);
64 }
65 
67  if (store)
68  stateMgr->getStoreManager().decrementReferenceCount(store);
69 }
70 
71 int64_t ProgramState::getID() const {
72  return getStateManager().Alloc.identifyKnownAlignedObject<ProgramState>(this);
73 }
74 
76  StoreManagerCreator CreateSMgr,
77  ConstraintManagerCreator CreateCMgr,
78  llvm::BumpPtrAllocator &alloc,
79  SubEngine *SubEng)
80  : Eng(SubEng), EnvMgr(alloc), GDMFactory(alloc),
81  svalBuilder(createSimpleSValBuilder(alloc, Ctx, *this)),
82  CallEventMgr(new CallEventManager(alloc)), Alloc(alloc) {
83  StoreMgr = (*CreateSMgr)(*this);
84  ConstraintMgr = (*CreateCMgr)(*this, SubEng);
85 }
86 
87 
89  for (GDMContextsTy::iterator I=GDMContexts.begin(), E=GDMContexts.end();
90  I!=E; ++I)
91  I->second.second(I->second.first);
92 }
93 
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  return getPersistentState(NewState);
115 }
116 
118  SVal V,
119  const LocationContext *LCtx,
120  bool notifyChanges) const {
121  ProgramStateManager &Mgr = getStateManager();
122  ProgramStateRef newState = makeWithStore(Mgr.StoreMgr->Bind(getStore(),
123  LV, V));
124  const MemRegion *MR = LV.getAsRegion();
125  if (MR && notifyChanges)
126  return Mgr.getOwningEngine().processRegionChange(newState, MR, LCtx);
127 
128  return newState;
129 }
130 
133  const LocationContext *LCtx) const {
134  ProgramStateManager &Mgr = getStateManager();
135  const MemRegion *R = loc.castAs<loc::MemRegionVal>().getRegion();
136  const StoreRef &newStore = Mgr.StoreMgr->BindDefaultInitial(getStore(), R, V);
137  ProgramStateRef new_state = makeWithStore(newStore);
138  return Mgr.getOwningEngine().processRegionChange(new_state, R, LCtx);
139 }
140 
143  ProgramStateManager &Mgr = getStateManager();
144  const MemRegion *R = loc.castAs<loc::MemRegionVal>().getRegion();
145  const StoreRef &newStore = Mgr.StoreMgr->BindDefaultZero(getStore(), R);
146  ProgramStateRef new_state = makeWithStore(newStore);
147  return Mgr.getOwningEngine().processRegionChange(new_state, R, LCtx);
148 }
149 
150 typedef ArrayRef<const MemRegion *> RegionList;
151 typedef ArrayRef<SVal> ValueList;
152 
155  const Expr *E, unsigned Count,
156  const LocationContext *LCtx,
157  bool CausedByPointerEscape,
158  InvalidatedSymbols *IS,
159  const CallEvent *Call,
160  RegionAndSymbolInvalidationTraits *ITraits) const {
161  SmallVector<SVal, 8> Values;
162  for (RegionList::const_iterator I = Regions.begin(),
163  End = Regions.end(); I != End; ++I)
164  Values.push_back(loc::MemRegionVal(*I));
165 
166  return invalidateRegionsImpl(Values, E, Count, LCtx, CausedByPointerEscape,
167  IS, ITraits, Call);
168 }
169 
172  const Expr *E, unsigned Count,
173  const LocationContext *LCtx,
174  bool CausedByPointerEscape,
175  InvalidatedSymbols *IS,
176  const CallEvent *Call,
177  RegionAndSymbolInvalidationTraits *ITraits) const {
178 
179  return invalidateRegionsImpl(Values, E, Count, LCtx, CausedByPointerEscape,
180  IS, ITraits, Call);
181 }
182 
184 ProgramState::invalidateRegionsImpl(ValueList Values,
185  const Expr *E, unsigned Count,
186  const LocationContext *LCtx,
187  bool CausedByPointerEscape,
188  InvalidatedSymbols *IS,
189  RegionAndSymbolInvalidationTraits *ITraits,
190  const CallEvent *Call) const {
191  ProgramStateManager &Mgr = getStateManager();
192  SubEngine &Eng = Mgr.getOwningEngine();
193 
194  InvalidatedSymbols InvalidatedSyms;
195  if (!IS)
196  IS = &InvalidatedSyms;
197 
198  RegionAndSymbolInvalidationTraits ITraitsLocal;
199  if (!ITraits)
200  ITraits = &ITraitsLocal;
201 
202  StoreManager::InvalidatedRegions TopLevelInvalidated;
204  const StoreRef &newStore
205  = Mgr.StoreMgr->invalidateRegions(getStore(), Values, E, Count, LCtx, Call,
206  *IS, *ITraits, &TopLevelInvalidated,
207  &Invalidated);
208 
209  ProgramStateRef newState = makeWithStore(newStore);
210 
211  if (CausedByPointerEscape) {
212  newState = Eng.notifyCheckersOfPointerEscape(newState, IS,
213  TopLevelInvalidated,
214  Call,
215  *ITraits);
216  }
217 
218  return Eng.processRegionChanges(newState, IS, TopLevelInvalidated,
219  Invalidated, LCtx, Call);
220 }
221 
223  assert(!LV.getAs<loc::MemRegionVal>() && "Use invalidateRegion instead.");
224 
225  Store OldStore = getStore();
226  const StoreRef &newStore =
227  getStateManager().StoreMgr->killBinding(OldStore, LV);
228 
229  if (newStore.getStore() == OldStore)
230  return this;
231 
232  return makeWithStore(newStore);
233 }
234 
237  const StackFrameContext *CalleeCtx) const {
238  const StoreRef &NewStore =
239  getStateManager().StoreMgr->enterStackFrame(getStore(), Call, CalleeCtx);
240  return makeWithStore(NewStore);
241 }
242 
244  // We only want to do fetches from regions that we can actually bind
245  // values. For example, SymbolicRegions of type 'id<...>' cannot
246  // have direct bindings (but their can be bindings on their subregions).
247  if (!R->isBoundable())
248  return UnknownVal();
249 
250  if (const TypedValueRegion *TR = dyn_cast<TypedValueRegion>(R)) {
251  QualType T = TR->getValueType();
253  return getSVal(R);
254  }
255 
256  return UnknownVal();
257 }
258 
259 SVal ProgramState::getSVal(Loc location, QualType T) const {
260  SVal V = getRawSVal(location, T);
261 
262  // If 'V' is a symbolic value that is *perfectly* constrained to
263  // be a constant value, use that value instead to lessen the burden
264  // on later analysis stages (so we have less symbolic values to reason
265  // about).
266  // We only go into this branch if we can convert the APSInt value we have
267  // to the type of T, which is not always the case (e.g. for void).
268  if (!T.isNull() && (T->isIntegralOrEnumerationType() || Loc::isLocType(T))) {
269  if (SymbolRef sym = V.getAsSymbol()) {
270  if (const llvm::APSInt *Int = getStateManager()
271  .getConstraintManager()
272  .getSymVal(this, sym)) {
273  // FIXME: Because we don't correctly model (yet) sign-extension
274  // and truncation of symbolic values, we need to convert
275  // the integer value to the correct signedness and bitwidth.
276  //
277  // This shows up in the following:
278  //
279  // char foo();
280  // unsigned x = foo();
281  // if (x == 54)
282  // ...
283  //
284  // The symbolic value stored to 'x' is actually the conjured
285  // symbol for the call to foo(); the type of that symbol is 'char',
286  // not unsigned.
287  const llvm::APSInt &NewV = getBasicVals().Convert(T, *Int);
288 
289  if (V.getAs<Loc>())
290  return loc::ConcreteInt(NewV);
291  else
292  return nonloc::ConcreteInt(NewV);
293  }
294  }
295  }
296 
297  return V;
298 }
299 
301  const LocationContext *LCtx,
302  SVal V, bool Invalidate) const{
303  Environment NewEnv =
304  getStateManager().EnvMgr.bindExpr(Env, EnvironmentEntry(S, LCtx), V,
305  Invalidate);
306  if (NewEnv == Env)
307  return this;
308 
309  ProgramState NewSt = *this;
310  NewSt.Env = NewEnv;
311  return getStateManager().getPersistentState(NewSt);
312 }
313 
315  DefinedOrUnknownSVal UpperBound,
316  bool Assumption,
317  QualType indexTy) const {
318  if (Idx.isUnknown() || UpperBound.isUnknown())
319  return this;
320 
321  // Build an expression for 0 <= Idx < UpperBound.
322  // This is the same as Idx + MIN < UpperBound + MIN, if overflow is allowed.
323  // FIXME: This should probably be part of SValBuilder.
324  ProgramStateManager &SM = getStateManager();
325  SValBuilder &svalBuilder = SM.getSValBuilder();
326  ASTContext &Ctx = svalBuilder.getContext();
327 
328  // Get the offset: the minimum value of the array index type.
329  BasicValueFactory &BVF = svalBuilder.getBasicValueFactory();
330  if (indexTy.isNull())
331  indexTy = svalBuilder.getArrayIndexType();
332  nonloc::ConcreteInt Min(BVF.getMinValue(indexTy));
333 
334  // Adjust the index.
335  SVal newIdx = svalBuilder.evalBinOpNN(this, BO_Add,
336  Idx.castAs<NonLoc>(), Min, indexTy);
337  if (newIdx.isUnknownOrUndef())
338  return this;
339 
340  // Adjust the upper bound.
341  SVal newBound =
342  svalBuilder.evalBinOpNN(this, BO_Add, UpperBound.castAs<NonLoc>(),
343  Min, indexTy);
344 
345  if (newBound.isUnknownOrUndef())
346  return this;
347 
348  // Build the actual comparison.
349  SVal inBound = svalBuilder.evalBinOpNN(this, BO_LT, newIdx.castAs<NonLoc>(),
350  newBound.castAs<NonLoc>(), Ctx.IntTy);
351  if (inBound.isUnknownOrUndef())
352  return this;
353 
354  // Finally, let the constraint manager take care of it.
356  return CM.assume(this, inBound.castAs<DefinedSVal>(), Assumption);
357 }
358 
360  ConditionTruthVal IsNull = isNull(V);
361  if (IsNull.isUnderconstrained())
362  return IsNull;
363  return ConditionTruthVal(!IsNull.getValue());
364 }
365 
367  return stateMgr->getSValBuilder().areEqual(this, Lhs, Rhs);
368 }
369 
371  if (V.isZeroConstant())
372  return true;
373 
374  if (V.isConstant())
375  return false;
376 
377  SymbolRef Sym = V.getAsSymbol(/* IncludeBaseRegion */ true);
378  if (!Sym)
379  return ConditionTruthVal();
380 
381  return getStateManager().ConstraintMgr->isNull(this, Sym);
382 }
383 
385  ProgramState State(this,
386  EnvMgr.getInitialEnvironment(),
387  StoreMgr->getInitialStore(InitLoc),
388  GDMFactory.getEmptyMap());
389 
390  return getPersistentState(State);
391 }
392 
394  ProgramStateRef FromState,
395  ProgramStateRef GDMState) {
396  ProgramState NewState(*FromState);
397  NewState.GDM = GDMState->GDM;
398  return getPersistentState(NewState);
399 }
400 
402 
403  llvm::FoldingSetNodeID ID;
404  State.Profile(ID);
405  void *InsertPos;
406 
407  if (ProgramState *I = StateSet.FindNodeOrInsertPos(ID, InsertPos))
408  return I;
409 
410  ProgramState *newState = nullptr;
411  if (!freeStates.empty()) {
412  newState = freeStates.back();
413  freeStates.pop_back();
414  }
415  else {
416  newState = (ProgramState*) Alloc.Allocate<ProgramState>();
417  }
418  new (newState) ProgramState(State);
419  StateSet.InsertNode(newState, InsertPos);
420  return newState;
421 }
422 
423 ProgramStateRef ProgramState::makeWithStore(const StoreRef &store) const {
424  ProgramState NewSt(*this);
425  NewSt.setStore(store);
426  return getStateManager().getPersistentState(NewSt);
427 }
428 
429 void ProgramState::setStore(const StoreRef &newStore) {
430  Store newStoreStore = newStore.getStore();
431  if (newStoreStore)
432  stateMgr->getStoreManager().incrementReferenceCount(newStoreStore);
433  if (store)
434  stateMgr->getStoreManager().decrementReferenceCount(store);
435  store = newStoreStore;
436 }
437 
438 //===----------------------------------------------------------------------===//
439 // State pretty-printing.
440 //===----------------------------------------------------------------------===//
441 
442 void ProgramState::printJson(raw_ostream &Out, const LocationContext *LCtx,
443  const char *NL, unsigned int Space,
444  bool IsDot) const {
445  Indent(Out, Space, IsDot) << "\"program_state\": {" << NL;
446  ++Space;
447 
448  ProgramStateManager &Mgr = getStateManager();
449 
450  // Print the store.
451  Mgr.getStoreManager().printJson(Out, getStore(), NL, Space, IsDot);
452 
453  // Print out the environment.
454  Env.printJson(Out, Mgr.getContext(), LCtx, NL, Space, IsDot);
455 
456  // Print out the constraints.
457  Mgr.getConstraintManager().printJson(Out, this, NL, Space, IsDot);
458 
459  // Print out the tracked dynamic types.
460  printDynamicTypeInfoJson(Out, this, NL, Space, IsDot);
461 
462  // Print checker-specific data.
463  Mgr.getOwningEngine().printJson(Out, this, LCtx, NL, Space, IsDot);
464 
465  --Space;
466  Indent(Out, Space, IsDot) << '}';
467 }
468 
469 void ProgramState::printDOT(raw_ostream &Out, const LocationContext *LCtx,
470  unsigned int Space) const {
471  printJson(Out, LCtx, /*NL=*/"\\l", Space, /*IsDot=*/true);
472 }
473 
474 LLVM_DUMP_METHOD void ProgramState::dump() const {
475  printJson(llvm::errs());
476 }
477 
479  return stateMgr->getOwningEngine().getAnalysisManager();
480 }
481 
482 //===----------------------------------------------------------------------===//
483 // Generic Data Map.
484 //===----------------------------------------------------------------------===//
485 
486 void *const* ProgramState::FindGDM(void *K) const {
487  return GDM.lookup(K);
488 }
489 
490 void*
492  void *(*CreateContext)(llvm::BumpPtrAllocator&),
493  void (*DeleteContext)(void*)) {
494 
495  std::pair<void*, void (*)(void*)>& p = GDMContexts[K];
496  if (!p.first) {
497  p.first = CreateContext(Alloc);
498  p.second = DeleteContext;
499  }
500 
501  return p.first;
502 }
503 
505  ProgramState::GenericDataMap M1 = St->getGDM();
506  ProgramState::GenericDataMap M2 = GDMFactory.add(M1, Key, Data);
507 
508  if (M1 == M2)
509  return St;
510 
511  ProgramState NewSt = *St;
512  NewSt.GDM = M2;
513  return getPersistentState(NewSt);
514 }
515 
517  ProgramState::GenericDataMap OldM = state->getGDM();
518  ProgramState::GenericDataMap NewM = GDMFactory.remove(OldM, Key);
519 
520  if (NewM == OldM)
521  return state;
522 
523  ProgramState NewState = *state;
524  NewState.GDM = NewM;
525  return getPersistentState(NewState);
526 }
527 
529  bool wasVisited = !visited.insert(val.getCVData()).second;
530  if (wasVisited)
531  return true;
532 
533  StoreManager &StoreMgr = state->getStateManager().getStoreManager();
534  // FIXME: We don't really want to use getBaseRegion() here because pointer
535  // arithmetic doesn't apply, but scanReachableSymbols only accepts base
536  // regions right now.
537  const MemRegion *R = val.getRegion()->getBaseRegion();
538  return StoreMgr.scanReachableSymbols(val.getStore(), R, *this);
539 }
540 
542  for (nonloc::CompoundVal::iterator I=val.begin(), E=val.end(); I!=E; ++I)
543  if (!scan(*I))
544  return false;
545 
546  return true;
547 }
548 
550  for (SymExpr::symbol_iterator SI = sym->symbol_begin(),
551  SE = sym->symbol_end();
552  SI != SE; ++SI) {
553  bool wasVisited = !visited.insert(*SI).second;
554  if (wasVisited)
555  continue;
556 
557  if (!visitor.VisitSymbol(*SI))
558  return false;
559  }
560 
561  return true;
562 }
563 
566  return scan(X->getRegion());
567 
570  return scan(*X);
571 
573  return scan(X->getLoc());
574 
575  if (SymbolRef Sym = val.getAsSymbol())
576  return scan(Sym);
577 
578  if (const SymExpr *Sym = val.getAsSymbolicExpression())
579  return scan(Sym);
580 
582  return scan(*X);
583 
584  return true;
585 }
586 
588  if (isa<MemSpaceRegion>(R))
589  return true;
590 
591  bool wasVisited = !visited.insert(R).second;
592  if (wasVisited)
593  return true;
594 
595  if (!visitor.VisitMemRegion(R))
596  return false;
597 
598  // If this is a symbolic region, visit the symbol for the region.
599  if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R))
600  if (!visitor.VisitSymbol(SR->getSymbol()))
601  return false;
602 
603  // If this is a subregion, also visit the parent regions.
604  if (const SubRegion *SR = dyn_cast<SubRegion>(R)) {
605  const MemRegion *Super = SR->getSuperRegion();
606  if (!scan(Super))
607  return false;
608 
609  // When we reach the topmost region, scan all symbols in it.
610  if (isa<MemSpaceRegion>(Super)) {
611  StoreManager &StoreMgr = state->getStateManager().getStoreManager();
612  if (!StoreMgr.scanReachableSymbols(state->getStore(), SR, *this))
613  return false;
614  }
615  }
616 
617  // Regions captured by a block are also implicitly reachable.
618  if (const BlockDataRegion *BDR = dyn_cast<BlockDataRegion>(R)) {
619  BlockDataRegion::referenced_vars_iterator I = BDR->referenced_vars_begin(),
620  E = BDR->referenced_vars_end();
621  for ( ; I != E; ++I) {
622  if (!scan(I.getCapturedRegion()))
623  return false;
624  }
625  }
626 
627  return true;
628 }
629 
631  ScanReachableSymbols S(this, visitor);
632  return S.scan(val);
633 }
634 
636  llvm::iterator_range<region_iterator> Reachable,
637  SymbolVisitor &visitor) const {
638  ScanReachableSymbols S(this, visitor);
639  for (const MemRegion *R : Reachable) {
640  if (!S.scan(R))
641  return false;
642  }
643  return true;
644 }
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:530
ProgramStateRef processRegionChange(ProgramStateRef state, const MemRegion *MR, const LocationContext *LCtx)
Definition: SubEngine.h:146
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
QualType getArrayIndexType() const
Definition: SValBuilder.h:164
A (possibly-)qualified type.
Definition: Type.h:654
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
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
SValBuilder * createSimpleSValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context, ProgramStateManager &stateMgr)
Stmt - This represents one statement.
Definition: Stmt.h:66
BasicValueFactory & getBasicVals()
Definition: ProgramState.h:502
Manages the lifetime of CallEvent objects.
Definition: CallEvent.h:1148
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
ProgramStateRef removeDeadBindingsFromEnvironmentAndStore(ProgramStateRef St, const StackFrameContext *LCtx, SymbolReaper &SymReaper)
Value representing integer constant.
Definition: SVals.h:379
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:858
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
Definition: StoreRef.h:27
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
virtual void printJson(raw_ostream &Out, Store S, const char *NL, unsigned int Space, bool IsDot) const =0
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:168
LineState State
llvm::ImmutableList< SVal >::iterator iterator
Definition: SVals.h:467
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:137
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:6881
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:329
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:673
AnalysisManager & getAnalysisManager() const
bool scanReachableSymbols(SVal val, SymbolVisitor &visitor) const
Visits the symbols reachable from the given SVal using the provided SymbolVisitor.
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:493
virtual void printJson(raw_ostream &Out, ProgramStateRef State, const char *NL, unsigned int Space, bool IsDot) const =0
SmallVector< const MemRegion *, 8 > InvalidatedRegions
Definition: Store.h:209
bool isConstant() const
Definition: SVals.cpp:222
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:758
SymbolRef getAsSymbol(bool IncludeBaseRegions=false) const
If this SVal wraps a symbol return that SymbolRef.
Definition: SVals.cpp:127
void printDOT(raw_ostream &Out, const LocationContext *LCtx=nullptr, unsigned int Space=0) const
void printJson(raw_ostream &Out, const LocationContext *LCtx=nullptr, const char *NL="\, unsigned int Space=0, bool IsDot=false) const
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:764
ProgramState - This class encapsulates:
Definition: ProgramState.h:72
This represents one expression.
Definition: Expr.h:108
SourceLocation End
#define V(N, I)
Definition: ASTContext.h:2941
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.
virtual void printJson(raw_ostream &Out, ProgramStateRef State, const LocationContext *LCtx, const char *NL, unsigned int Space, bool IsDot) const =0
printJson - Called by ProgramStateManager to print checker-specific data.
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:719
const SourceManager & SM
Definition: Format.cpp:1685
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:174
ProgramStateRef removeGDM(ProgramStateRef state, void *Key)
bool scan(nonloc::LazyCompoundVal val)
ProgramStateRef getInitialState(const LocationContext *InitLoc)
llvm::APSInt APSInt
const MemRegion * getAsRegion() const
Definition: SVals.cpp:151
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
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:234
static symbol_iterator symbol_end()
Definition: SymExpr.h:87
LLVM_NODISCARD ProgramStateRef killBinding(Loc LV) const
const void * getStore() const
Definition: SVals.cpp:166
Represents an abstract call to a function or method along a particular path.
Definition: CallEvent.h:138
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:533
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:436
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:14781
void printDynamicTypeInfoJson(raw_ostream &Out, ProgramStateRef State, const char *NL="\, unsigned int Space=0, bool IsDot=false)
ProgramStateManager(ASTContext &Ctx, StoreManagerCreator CreateStoreManager, ConstraintManagerCreator CreateConstraintManager, llvm::BumpPtrAllocator &alloc, SubEngine *subeng)
const TypedValueRegion * getRegion() const
Definition: SVals.cpp:170
Environment removeDeadBindings(Environment Env, SymbolReaper &SymReaper, ProgramStateRef state)
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:1025
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
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
Definition: JsonSupport.h:20
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:765
bool isUnknownOrUndef() const
Definition: SVals.h:144
ArrayRef< SVal > ValueList
Iterator over symbols that the current symbol depends on.
Definition: SymExpr.h:70