clang 23.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"
20#include "llvm/Support/raw_ostream.h"
21#include <optional>
22
23using namespace clang;
24using namespace ento;
25
26namespace clang { namespace ento {
27/// Increments the number of times this state is referenced.
28
29void ProgramStateRetain(const ProgramState *state) {
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) {
38 ProgramStateManager &Mgr = s->getStateManager();
39 Mgr.StateSet.RemoveNode(s);
40 s->~ProgramState();
41 Mgr.freeStates.push_back(s);
42 }
43}
44}}
45
48 : stateMgr(mgr),
49 Env(env),
50 store(st.getStore()),
51 GDM(gdm),
52 refCount(0) {
53 stateMgr->getStoreManager().incrementReferenceCount(store);
54}
55
57 : stateMgr(RHS.stateMgr), Env(RHS.Env), store(RHS.store), GDM(RHS.GDM),
58 PosteriorlyOverconstrained(RHS.PosteriorlyOverconstrained), refCount(0) {
59 stateMgr->getStoreManager().incrementReferenceCount(store);
60}
61
63 if (store)
64 stateMgr->getStoreManager().decrementReferenceCount(store);
65}
66
67int64_t ProgramState::getID() const {
68 return getStateManager().Alloc.identifyKnownAlignedObject<ProgramState>(this);
69}
70
72 StoreManagerCreator CreateSMgr,
73 ConstraintManagerCreator CreateCMgr,
74 llvm::BumpPtrAllocator &alloc,
75 ExprEngine *ExprEng)
76 : Eng(ExprEng), EnvMgr(alloc), GDMFactory(alloc),
77 svalBuilder(createSimpleSValBuilder(alloc, Ctx, *this)),
78 CallEventMgr(new CallEventManager(alloc)), Alloc(alloc) {
79 StoreMgr = (*CreateSMgr)(*this);
80 ConstraintMgr = (*CreateCMgr)(*this, ExprEng);
81}
82
83
85 for (GDMContextsTy::iterator I=GDMContexts.begin(), E=GDMContexts.end();
86 I!=E; ++I)
87 I->second.second(I->second.first);
88}
89
91 ProgramStateRef state, const StackFrame *SF, SymbolReaper &SymReaper) {
92
93 // This code essentially performs a "mark-and-sweep" of the VariableBindings.
94 // The roots are any Block-level exprs and Decls that our liveness algorithm
95 // tells us are live. We then see what Decls they may reference, and keep
96 // those around. This code more than likely can be made faster, and the
97 // frequency of which this method is called should be experimented with
98 // for optimum performance.
99 ProgramState NewState = *state;
100
101 NewState.Env = EnvMgr.removeDeadBindings(NewState.Env, SymReaper, state);
102
103 // Clean up the store.
104 StoreRef newStore =
105 StoreMgr->removeDeadBindings(NewState.getStore(), SF, SymReaper);
106 NewState.setStore(newStore);
107 SymReaper.setReapedStore(newStore);
108
109 return getPersistentState(NewState);
110}
111
113 SVal V,
114 const LocationContext *LCtx,
115 bool notifyChanges) const {
117 ExprEngine &Eng = Mgr.getOwningEngine();
118 ProgramStateRef State = makeWithStore(Mgr.StoreMgr->Bind(getStore(), LV, V));
119 const MemRegion *MR = LV.getAsRegion();
120
121 if (MR && notifyChanges)
122 return Eng.processRegionChange(State, MR, LCtx);
123
124 return State;
125}
126
129 const LocationContext *LCtx) const {
131 const MemRegion *R = loc.castAs<loc::MemRegionVal>().getRegion();
132 BindResult BindRes = Mgr.StoreMgr->BindDefaultInitial(getStore(), R, V);
133 ProgramStateRef State = makeWithStore(BindRes);
134 return Mgr.getOwningEngine().processRegionChange(State, R, LCtx);
135}
136
140 const MemRegion *R = loc.castAs<loc::MemRegionVal>().getRegion();
141 BindResult BindRes = Mgr.StoreMgr->BindDefaultZero(getStore(), R);
142 ProgramStateRef State = makeWithStore(BindRes);
143 return Mgr.getOwningEngine().processRegionChange(State, R, LCtx);
144}
145
148
150 RegionList Regions, ConstCFGElementRef Elem, unsigned Count,
151 const LocationContext *LCtx, bool CausedByPointerEscape,
153 RegionAndSymbolInvalidationTraits *ITraits) const {
155 for (const MemRegion *Reg : Regions)
156 Values.push_back(loc::MemRegionVal(Reg));
157
158 return invalidateRegions(Values, Elem, Count, LCtx, CausedByPointerEscape, IS,
159 Call, ITraits);
160}
161
163 ValueList Values, ConstCFGElementRef Elem, unsigned Count,
164 const LocationContext *LCtx, bool CausedByPointerEscape,
166 RegionAndSymbolInvalidationTraits *ITraits) const {
167
169 ExprEngine &Eng = Mgr.getOwningEngine();
170
171 InvalidatedSymbols InvalidatedSyms;
172 if (!IS)
173 IS = &InvalidatedSyms;
174
175 RegionAndSymbolInvalidationTraits ITraitsLocal;
176 if (!ITraits)
177 ITraits = &ITraitsLocal;
178
179 StoreManager::InvalidatedRegions TopLevelInvalidated;
181 const StoreRef &NewStore = Mgr.StoreMgr->invalidateRegions(
182 getStore(), Values, Elem, Count, LCtx, Call, *IS, *ITraits,
183 &TopLevelInvalidated, &Invalidated);
184
185 ProgramStateRef NewState = makeWithStore(NewStore);
186
187 if (CausedByPointerEscape) {
188 NewState = Eng.notifyCheckersOfPointerEscape(
189 NewState, IS, TopLevelInvalidated, Call, *ITraits);
190 }
191
192 return Eng.processRegionChanges(NewState, IS, TopLevelInvalidated,
193 Invalidated, LCtx, Call);
194}
195
197 Store OldStore = getStore();
198 const StoreRef &newStore =
199 getStateManager().StoreMgr->killBinding(OldStore, LV);
200
201 if (newStore.getStore() == OldStore)
202 return this;
203
204 return makeWithStore(newStore);
205}
206
207/// We should never form a MemRegion that would wrap a TypedValueRegion of a
208/// reference type. What we actually wanted was to create a MemRegion refering
209/// to the pointee of that reference.
210SVal ProgramState::desugarReference(SVal Val) const {
211 const auto *TyReg = dyn_cast_or_null<TypedValueRegion>(Val.getAsRegion());
212 if (!TyReg || !TyReg->getValueType()->isReferenceType())
213 return Val;
214 return getSVal(TyReg);
215}
216
217/// SymbolicRegions are expected to be wrapped by an ElementRegion as a
218/// canonical representation. As a canonical representation, SymbolicRegions
219/// should be wrapped by ElementRegions before getting a FieldRegion.
220/// See f8643a9b31c4029942f67d4534c9139b45173504 why.
221SVal ProgramState::wrapSymbolicRegion(SVal Val) const {
222 const auto *BaseReg = dyn_cast_or_null<SymbolicRegion>(Val.getAsRegion());
223 if (!BaseReg)
224 return Val;
225
227 QualType ElemTy = BaseReg->getPointeeStaticType();
228 return loc::MemRegionVal{SM.GetElementZeroRegion(BaseReg, ElemTy)};
229}
230
233 const StackFrame *CalleeCtx) const {
234 return makeWithStore(
235 getStateManager().StoreMgr->enterStackFrame(getStore(), Call, CalleeCtx));
236}
237
239 const ImplicitParamDecl *SelfDecl = LCtx->getSelfDecl();
240 if (!SelfDecl)
241 return SVal();
242 return getSVal(getRegion(SelfDecl, LCtx));
243}
244
246 // We only want to do fetches from regions that we can actually bind
247 // values. For example, SymbolicRegions of type 'id<...>' cannot
248 // have direct bindings (but their can be bindings on their subregions).
249 if (!R->isBoundable())
250 return UnknownVal();
251
252 if (const TypedValueRegion *TR = dyn_cast<TypedValueRegion>(R)) {
253 QualType T = TR->getValueType();
254 if (Loc::isLocType(T) || T->isIntegralOrEnumerationType())
255 return getSVal(R);
256 }
257
258 return UnknownVal();
259}
260
262 SVal V = getRawSVal(location, T);
263
264 // If 'V' is a symbolic value that is *perfectly* constrained to
265 // be a constant value, use that value instead to lessen the burden
266 // on later analysis stages (so we have less symbolic values to reason
267 // about).
268 // We only go into this branch if we can convert the APSInt value we have
269 // to the type of T, which is not always the case (e.g. for void).
270 if (!T.isNull() && (T->isIntegralOrEnumerationType() || Loc::isLocType(T))) {
271 if (SymbolRef sym = V.getAsSymbol()) {
272 if (const llvm::APSInt *Int = getStateManager()
274 .getSymVal(this, sym)) {
275 // FIXME: Because we don't correctly model (yet) sign-extension
276 // and truncation of symbolic values, we need to convert
277 // the integer value to the correct signedness and bitwidth.
278 //
279 // This shows up in the following:
280 //
281 // char foo();
282 // unsigned x = foo();
283 // if (x == 54)
284 // ...
285 //
286 // The symbolic value stored to 'x' is actually the conjured
287 // symbol for the call to foo(); the type of that symbol is 'char',
288 // not unsigned.
289 APSIntPtr NewV = getBasicVals().Convert(T, *Int);
290 if (V.getAs<Loc>())
291 return loc::ConcreteInt(NewV);
292 return nonloc::ConcreteInt(NewV);
293 }
294 }
295 }
296
297 return V;
298}
299
301 const LocationContext *LCtx, SVal V,
302 bool Invalidate) const {
303 Environment NewEnv = getStateManager().EnvMgr.bindExpr(
304 Env, EnvironmentEntry(E, LCtx), V, Invalidate);
305 if (NewEnv == Env)
306 return this;
307
308 ProgramState NewSt = *this;
309 NewSt.Env = std::move(NewEnv);
310 return getStateManager().getPersistentState(NewSt);
311}
312
313[[nodiscard]] std::pair<ProgramStateRef, ProgramStateRef>
315 DefinedOrUnknownSVal UpperBound,
316 QualType indexTy) const {
317 if (Idx.isUnknown() || UpperBound.isUnknown())
318 return {this, this};
319
320 // Build an expression for 0 <= Idx < UpperBound.
321 // This is the same as Idx + MIN < UpperBound + MIN, if overflow is allowed.
322 // FIXME: This should probably be part of SValBuilder.
324 SValBuilder &svalBuilder = SM.getSValBuilder();
325 ASTContext &Ctx = svalBuilder.getContext();
326
327 // Get the offset: the minimum value of the array index type.
328 BasicValueFactory &BVF = svalBuilder.getBasicValueFactory();
329 if (indexTy.isNull())
330 indexTy = svalBuilder.getArrayIndexType();
331 nonloc::ConcreteInt Min(BVF.getMinValue(indexTy));
332
333 // Adjust the index.
334 SVal newIdx = svalBuilder.evalBinOpNN(this, BO_Add,
335 Idx.castAs<NonLoc>(), Min, indexTy);
336 if (newIdx.isUnknownOrUndef())
337 return {this, this};
338
339 // Adjust the upper bound.
340 SVal newBound =
341 svalBuilder.evalBinOpNN(this, BO_Add, UpperBound.castAs<NonLoc>(),
342 Min, indexTy);
343
344 if (newBound.isUnknownOrUndef())
345 return {this, this};
346
347 // Build the actual comparison.
348 SVal inBound = svalBuilder.evalBinOpNN(this, BO_LT, newIdx.castAs<NonLoc>(),
349 newBound.castAs<NonLoc>(), Ctx.IntTy);
350 if (inBound.isUnknownOrUndef())
351 return {this, this};
352
353 // Finally, let the constraint manager take care of it.
354 ConstraintManager &CM = SM.getConstraintManager();
355 return CM.assumeDual(this, inBound.castAs<DefinedSVal>());
356}
357
359 DefinedOrUnknownSVal UpperBound,
360 bool Assumption,
361 QualType indexTy) const {
362 std::pair<ProgramStateRef, ProgramStateRef> R =
363 assumeInBoundDual(Idx, UpperBound, indexTy);
364 return Assumption ? R.first : R.second;
365}
366
369 if (IsNull.isUnderconstrained())
370 return IsNull;
371 return ConditionTruthVal(!IsNull.getValue());
372}
373
375 return stateMgr->getSValBuilder().areEqual(this, Lhs, Rhs);
376}
377
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
393 ProgramState State(this,
394 EnvMgr.getInitialEnvironment(),
395 StoreMgr->getInitialStore(InitLoc),
396 GDMFactory.getEmptyMap());
397
398 return getPersistentState(State);
399}
400
402 ProgramStateRef FromState,
403 ProgramStateRef GDMState) {
404 ProgramState NewState(*FromState);
405 NewState.GDM = GDMState->GDM;
406 return getPersistentState(NewState);
407}
408
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 = Alloc.Allocate<ProgramState>();
425 }
426 new (newState) ProgramState(State);
427 StateSet.InsertNode(newState, InsertPos);
428 return newState;
429}
430
431ProgramStateRef ProgramState::makeWithStore(const StoreRef &store) const {
432 ProgramState NewSt(*this);
433 NewSt.setStore(store);
434 return getStateManager().getPersistentState(NewSt);
435}
436
437ProgramStateRef ProgramState::makeWithStore(const BindResult &BindRes) const {
439 ProgramStateRef State = makeWithStore(BindRes.ResultingStore);
440
441 // We must always notify the checkers for failing binds because otherwise they
442 // may keep stale traits for these symbols.
443 // Eg., Malloc checker may report leaks if we failed to bind that symbol.
444 if (BindRes.FailedToBindValues.empty())
445 return State;
446 return Eng.escapeValues(State, BindRes.FailedToBindValues, PSK_EscapeOnBind);
447}
448
449ProgramStateRef ProgramState::cloneAsPosteriorlyOverconstrained() const {
450 ProgramState NewSt(*this);
451 NewSt.PosteriorlyOverconstrained = true;
452 return getStateManager().getPersistentState(NewSt);
453}
454
455void ProgramState::setStore(const StoreRef &newStore) {
456 Store newStoreStore = newStore.getStore();
457 if (newStoreStore)
458 stateMgr->getStoreManager().incrementReferenceCount(newStoreStore);
459 if (store)
460 stateMgr->getStoreManager().decrementReferenceCount(store);
461 store = newStoreStore;
462}
463
465 Base = desugarReference(Base);
466 Base = wrapSymbolicRegion(Base);
467 return getStateManager().StoreMgr->getLValueField(D, Base);
468}
469
471 StoreManager &SM = *getStateManager().StoreMgr;
472 Base = desugarReference(Base);
473 Base = wrapSymbolicRegion(Base);
474
475 // FIXME: This should work with `SM.getLValueField(D->getAnonField(), Base)`,
476 // but that would break some tests. There is probably a bug somewhere that it
477 // would expose.
478 for (const auto *I : D->chain()) {
479 Base = SM.getLValueField(cast<FieldDecl>(I), Base);
480 }
481 return Base;
482}
483
484//===----------------------------------------------------------------------===//
485// State pretty-printing.
486//===----------------------------------------------------------------------===//
487
488void ProgramState::printJson(raw_ostream &Out, const LocationContext *LCtx,
489 const char *NL, unsigned int Space,
490 bool IsDot) const {
491 Indent(Out, Space, IsDot) << "\"program_state\": {" << NL;
492 ++Space;
493
495
496 // Print the store.
497 Mgr.getStoreManager().printJson(Out, getStore(), NL, Space, IsDot);
498
499 // Print out the environment.
500 Env.printJson(Out, Mgr.getContext(), LCtx, NL, Space, IsDot);
501
502 // Print out the constraints.
503 Mgr.getConstraintManager().printJson(Out, this, NL, Space, IsDot);
504
505 // Print out the tracked dynamic types.
506 printDynamicTypeInfoJson(Out, this, NL, Space, IsDot);
507
508 // Print checker-specific data.
509 Mgr.getOwningEngine().printJson(Out, this, LCtx, NL, Space, IsDot);
510
511 --Space;
512 Indent(Out, Space, IsDot) << '}';
513}
514
515void ProgramState::printDOT(raw_ostream &Out, const LocationContext *LCtx,
516 unsigned int Space) const {
517 printJson(Out, LCtx, /*NL=*/"\\l", Space, /*IsDot=*/true);
518}
519
520LLVM_DUMP_METHOD void ProgramState::dump() const {
521 printJson(llvm::errs());
522}
523
525 return stateMgr->getOwningEngine().getAnalysisManager();
526}
527
528//===----------------------------------------------------------------------===//
529// Generic Data Map.
530//===----------------------------------------------------------------------===//
531
532void *const *ProgramState::FindGDM(const void *K) const {
533 return GDM.lookup(K);
534}
535
537 const void *K, void *(*CreateContext)(llvm::BumpPtrAllocator &),
538 void (*DeleteContext)(void *)) {
539
540 std::pair<void*, void (*)(void*)>& p = GDMContexts[K];
541 if (!p.first) {
542 p.first = CreateContext(Alloc);
543 p.second = DeleteContext;
544 }
545
546 return p.first;
547}
548
550 void *Data) {
551 ProgramState::GenericDataMap M1 = St->getGDM();
552 ProgramState::GenericDataMap M2 = GDMFactory.add(M1, Key, Data);
553
554 if (M1 == M2)
555 return St;
556
557 ProgramState NewSt = *St;
558 NewSt.GDM = M2;
559 return getPersistentState(NewSt);
560}
561
563 const void *Key) {
564 ProgramState::GenericDataMap OldM = state->getGDM();
565 ProgramState::GenericDataMap NewM = GDMFactory.remove(OldM, Key);
566
567 if (NewM == OldM)
568 return state;
569
570 ProgramState NewState = *state;
571 NewState.GDM = NewM;
572 return getPersistentState(NewState);
573}
574
576 bool wasVisited = !visited.insert(val.getCVData()).second;
577 if (wasVisited)
578 return true;
579
580 StoreManager &StoreMgr = state->getStateManager().getStoreManager();
581 // FIXME: We don't really want to use getBaseRegion() here because pointer
582 // arithmetic doesn't apply, but scanReachableSymbols only accepts base
583 // regions right now.
584 const MemRegion *R = val.getRegion()->getBaseRegion();
585 return StoreMgr.scanReachableSymbols(val.getStore(), R, *this);
586}
587
589 for (SVal V : val)
590 if (!scan(V))
591 return false;
592
593 return true;
594}
595
597 for (SymbolRef SubSym : sym->symbols()) {
598 bool wasVisited = !visited.insert(SubSym).second;
599 if (wasVisited)
600 continue;
601
602 if (!visitor.VisitSymbol(SubSym))
603 return false;
604 }
605
606 return true;
607}
608
610 if (std::optional<loc::MemRegionVal> X = val.getAs<loc::MemRegionVal>())
611 return scan(X->getRegion());
612
613 if (std::optional<nonloc::LazyCompoundVal> X =
615 return scan(*X);
616
617 if (std::optional<nonloc::LocAsInteger> X = val.getAs<nonloc::LocAsInteger>())
618 return scan(X->getLoc());
619
620 if (SymbolRef Sym = val.getAsSymbol())
621 return scan(Sym);
622
623 if (std::optional<nonloc::CompoundVal> X = val.getAs<nonloc::CompoundVal>())
624 return scan(*X);
625
626 return true;
627}
628
630 if (isa<MemSpaceRegion>(R))
631 return true;
632
633 bool wasVisited = !visited.insert(R).second;
634 if (wasVisited)
635 return true;
636
637 if (!visitor.VisitMemRegion(R))
638 return false;
639
640 // If this is a symbolic region, visit the symbol for the region.
641 if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R))
642 if (!visitor.VisitSymbol(SR->getSymbol()))
643 return false;
644
645 // If this is a subregion, also visit the parent regions.
646 if (const SubRegion *SR = dyn_cast<SubRegion>(R)) {
647 const MemRegion *Super = SR->getSuperRegion();
648 if (!scan(Super))
649 return false;
650
651 // When we reach the topmost region, scan all symbols in it.
652 if (isa<MemSpaceRegion>(Super)) {
653 StoreManager &StoreMgr = state->getStateManager().getStoreManager();
654 if (!StoreMgr.scanReachableSymbols(state->getStore(), SR, *this))
655 return false;
656 }
657 }
658
659 // Regions captured by a block are also implicitly reachable.
660 if (const BlockDataRegion *BDR = dyn_cast<BlockDataRegion>(R)) {
661 for (auto Var : BDR->referenced_vars()) {
662 if (!scan(Var.getCapturedRegion()))
663 return false;
664 }
665 }
666
667 return true;
668}
669
671 ScanReachableSymbols S(this, visitor);
672 return S.scan(val);
673}
674
676 llvm::iterator_range<region_iterator> Reachable,
677 SymbolVisitor &visitor) const {
678 ScanReachableSymbols S(this, visitor);
679 for (const MemRegion *R : Reachable) {
680 if (!S.scan(R))
681 return false;
682 }
683 return true;
684}
#define V(N, I)
#define X(type, name)
Definition Value.h:97
#define SM(sm)
ArrayRef< const MemRegion * > RegionList
ArrayRef< SVal > ValueList
__device__ __2f16 float __ockl_bool s
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:227
CanQualType IntTy
This represents one expression.
Definition Expr.h:112
Represents a member of a struct/union/class.
Definition Decl.h:3178
Represents a field injected from an anonymous union/struct into the parent scope.
Definition Decl.h:3485
ArrayRef< NamedDecl * > chain() const
Definition Decl.h:3506
const ImplicitParamDecl * getSelfDecl() const
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1004
It represents a stack frame of the call stack (based on CallEvent).
A safe wrapper around APSInt objects allocated and owned by BasicValueFactory.
Definition APSIntPtr.h:19
APSIntPtr getMinValue(const llvm::APSInt &v)
APSIntPtr Convert(const llvm::APSInt &To, const llvm::APSInt &From)
Convert - Create a new persistent APSInt with the same value as 'From' but with the bitwidth and sign...
BlockDataRegion - A region that represents a block instance.
Definition MemRegion.h:706
Manages the lifetime of CallEvent objects.
Definition CallEvent.h:1374
Represents an abstract call to a function or method along a particular path.
Definition CallEvent.h:153
ProgramStatePair assumeDual(ProgramStateRef State, DefinedSVal Cond)
Returns a pair of states (StTrue, StFalse) where the given condition is assumed to be true or false,...
virtual void printJson(raw_ostream &Out, ProgramStateRef State, const char *NL, unsigned int Space, bool IsDot) const =0
An entry in the environment consists of a Stmt and an LocationContext.
Definition Environment.h:35
Environment bindExpr(Environment Env, const EnvironmentEntry &E, SVal V, bool Invalidate)
Bind a symbolic value to the given environment entry.
An immutable map from EnvironmentEntries to SVals.
Definition Environment.h:55
ProgramStateRef processRegionChange(ProgramStateRef state, const MemRegion *MR, const LocationContext *LCtx)
Definition ExprEngine.h:469
void printJson(raw_ostream &Out, ProgramStateRef State, const LocationContext *LCtx, const char *NL, unsigned int Space, bool IsDot) const
printJson - Called by ProgramStateManager to print checker-specific data.
ProgramStateRef processRegionChanges(ProgramStateRef state, const InvalidatedSymbols *invalidated, ArrayRef< const MemRegion * > ExplicitRegions, ArrayRef< const MemRegion * > Regions, const LocationContext *LCtx, const CallEvent *Call)
processRegionChanges - Called by ProgramStateManager whenever a change is made to the store.
ProgramStateRef notifyCheckersOfPointerEscape(ProgramStateRef State, const InvalidatedSymbols *Invalidated, ArrayRef< const MemRegion * > ExplicitRegions, const CallEvent *Call, RegionAndSymbolInvalidationTraits &ITraits)
Call PointerEscape callback when a value escapes as a result of region invalidation.
ProgramStateRef escapeValues(ProgramStateRef State, ArrayRef< SVal > Vs, PointerEscapeKind K, const CallEvent *Call=nullptr) const
A simple wrapper when you only need to notify checkers of pointer-escape of some values.
static bool isLocType(QualType T)
Definition SVals.h:262
MemRegion - The root abstract class for all memory regions.
Definition MemRegion.h:98
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * getBaseRegion() const
void * FindGDMContext(const void *index, void *(*CreateContext)(llvm::BumpPtrAllocator &), void(*DeleteContext)(void *))
ProgramStateRef removeDeadBindingsFromEnvironmentAndStore(ProgramStateRef St, const StackFrame *SF, SymbolReaper &SymReaper)
ProgramStateRef getPersistentStateWithGDM(ProgramStateRef FromState, ProgramStateRef GDMState)
ProgramStateRef removeGDM(ProgramStateRef state, const void *Key)
ProgramStateRef addGDM(ProgramStateRef St, const void *Key, void *Data)
ProgramStateRef getPersistentState(ProgramState &Impl)
ProgramStateRef getInitialState(const LocationContext *InitLoc)
ProgramStateManager(ASTContext &Ctx, StoreManagerCreator CreateStoreManager, ConstraintManagerCreator CreateConstraintManager, llvm::BumpPtrAllocator &alloc, ExprEngine *expreng)
ConstraintManager & getConstraintManager()
ProgramState - This class encapsulates:
bool scanReachableSymbols(SVal val, SymbolVisitor &visitor) const
Visits the symbols reachable from the given SVal using the provided SymbolVisitor.
Loc getLValue(const CXXBaseSpecifier &BaseSpec, const SubRegion *Super) const
Get the lvalue for a base class object reference.
ProgramStateRef bindDefaultZero(SVal loc, const LocationContext *LCtx) const
Performs C++ zero-initialization procedure on the region of memory represented by loc.
friend class ProgramStateManager
llvm::ImmutableMap< const void *, void * > GenericDataMap
void printJson(raw_ostream &Out, const LocationContext *LCtx=nullptr, const char *NL="\n", unsigned int Space=0, bool IsDot=false) const
ProgramStateRef bindDefaultInitial(SVal loc, SVal V, const LocationContext *LCtx) const
Initializes the region of memory represented by loc with an initial value.
ConstraintManager & getConstraintManager() const
Return the ConstraintManager.
SVal getSelfSVal(const LocationContext *LC) const
Return the value of 'self' if available in the given context.
SVal getRawSVal(Loc LV, QualType T=QualType()) const
Returns the "raw" SVal bound to LV before any value simplification.
ConditionTruthVal isNull(SVal V) const
Check if the given SVal is constrained to zero or is a zero constant.
ProgramStateManager & getStateManager() const
Return the ProgramStateManager associated with this state.
ProgramStateRef killBinding(Loc LV) const
ProgramState(ProgramStateManager *mgr, const Environment &env, StoreRef st, GenericDataMap gdm)
This ctor is used when creating the first ProgramState object.
ProgramStateRef BindExpr(const Expr *E, const LocationContext *LCtx, SVal V, bool Invalidate=true) const
Create a new state by binding the value V to the expression E in the state's environment.
Store getStore() const
Return the store associated with this state.
SVal getSVal(const Expr *E, const LocationContext *LCtx) const
Returns the SVal bound to the expression E in the state's environment.
ConditionTruthVal areEqual(SVal Lhs, SVal Rhs) const
void printDOT(raw_ostream &Out, const LocationContext *LCtx=nullptr, unsigned int Space=0) const
ConditionTruthVal isNonNull(SVal V) const
Check if the given SVal is not constrained to zero and is not a zero constant.
ProgramStateRef assumeInBound(DefinedOrUnknownSVal idx, DefinedOrUnknownSVal upperBound, bool assumption, QualType IndexType=QualType()) const
LLVM_ATTRIBUTE_RETURNS_NONNULL const VarRegion * getRegion(const VarDecl *D, const LocationContext *LC) const
Utility method for getting regions.
ProgramStateRef invalidateRegions(ArrayRef< const MemRegion * > Regions, ConstCFGElementRef Elem, 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.
ProgramStateRef bindLoc(Loc location, SVal V, const LocationContext *LCtx, bool notifyChanges=true) const
BasicValueFactory & getBasicVals() const
std::pair< ProgramStateRef, ProgramStateRef > assumeInBoundDual(DefinedOrUnknownSVal idx, DefinedOrUnknownSVal upperBound, QualType IndexType=QualType()) const
void *const * FindGDM(const void *K) const
AnalysisManager & getAnalysisManager() const
SVal getSValAsScalarOrLoc(const Expr *E, const LocationContext *LCtx) const
ProgramStateRef enterStackFrame(const CallEvent &Call, const StackFrame *CalleeSF) const
enterStackFrame - Returns the state for entry to the given stack frame, preserving the current state.
Information about invalidation for a particular region/symbol.
Definition MemRegion.h:1661
BasicValueFactory & getBasicValueFactory()
ASTContext & getContext()
QualType getArrayIndexType() const
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.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
Definition SVals.h:56
bool isUnknownOrUndef() const
Definition SVals.h:109
SymbolRef getAsSymbol(bool IncludeBaseRegions=false) const
If this SVal wraps a symbol return that SymbolRef.
Definition SVals.cpp:103
std::optional< T > getAs() const
Convert to the specified SVal type, returning std::nullopt if this SVal is not of the desired type.
Definition SVals.h:87
const MemRegion * getAsRegion() const
Definition SVals.cpp:119
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
Definition SVals.h:83
bool isUnknown() const
Definition SVals.h:105
A utility class that visits the reachable symbols using a custom SymbolVisitor.
bool scan(nonloc::LazyCompoundVal val)
virtual bool scanReachableSymbols(Store S, const MemRegion *R, ScanReachableSymbols &Visitor)=0
Finds the transitive closure of symbols within the given region.
SmallVector< const MemRegion *, 8 > InvalidatedRegions
Definition Store.h:211
virtual void printJson(raw_ostream &Out, Store S, const char *NL, unsigned int Space, bool IsDot) const =0
Store getStore() const
Definition StoreRef.h:46
SubRegion - A region that subsets another larger region.
Definition MemRegion.h:474
Symbolic value.
Definition SymExpr.h:32
llvm::iterator_range< symbol_iterator > symbols() const
Definition SymExpr.h:107
A class responsible for cleaning up unused symbols.
void setReapedStore(StoreRef st)
Set to the value of the symbolic store after StoreManager::removeDeadBindings has been called.
SymbolicRegion - A special, "non-concrete" region.
Definition MemRegion.h:808
TypedValueRegion - An abstract class representing regions having a typed value.
Definition MemRegion.h:563
The simplest example of a concrete compound value is nonloc::CompoundVal, which represents a concrete...
Definition SVals.h:339
Value representing integer constant.
Definition SVals.h:300
While nonloc::CompoundVal covers a few simple use cases, nonloc::LazyCompoundVal is a more performant...
Definition SVals.h:389
LLVM_ATTRIBUTE_RETURNS_NONNULL const LazyCompoundValData * getCVData() const
Definition SVals.h:399
LLVM_ATTRIBUTE_RETURNS_NONNULL const TypedValueRegion * getRegion() const
This function itself is immaterial.
Definition SVals.cpp:193
const void * getStore() const
It might return null.
Definition SVals.cpp:189
@ PSK_EscapeOnBind
A pointer escapes due to binding its value to a location that the analyzer cannot track.
SValBuilder * createSimpleSValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context, ProgramStateManager &stateMgr)
llvm::DenseSet< SymbolRef > InvalidatedSymbols
Definition Store.h:51
void printDynamicTypeInfoJson(raw_ostream &Out, ProgramStateRef State, const char *NL="\n", unsigned int Space=0, bool IsDot=false)
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
const SymExpr * SymbolRef
Definition SymExpr.h:133
std::unique_ptr< ConstraintManager >(* ConstraintManagerCreator)(ProgramStateManager &, ExprEngine *)
std::unique_ptr< StoreManager >(* StoreManagerCreator)(ProgramStateManager &)
void ProgramStateRetain(const ProgramState *state)
Increments the number of times this state is referenced.
void ProgramStateRelease(const ProgramState *state)
Decrement the number of times this state is referenced.
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
Definition StoreRef.h:27
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
CFGBlock::ConstCFGElementRef ConstCFGElementRef
Definition CFG.h:1227
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
Definition JsonSupport.h:21
U cast(CodeGen::Address addr)
Definition Address.h:327
llvm::SmallVector< SVal, 0 > FailedToBindValues
Definition Store.h:58
StoreRef ResultingStore
Definition Store.h:54