clang 17.0.0git
Store.cpp
Go to the documentation of this file.
1//===- Store.cpp - Interface for maps from Locations to Values ------------===//
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 defined the types Store and StoreManager.
10//
11//===----------------------------------------------------------------------===//
12
16#include "clang/AST/CharUnits.h"
17#include "clang/AST/Decl.h"
18#include "clang/AST/DeclCXX.h"
19#include "clang/AST/DeclObjC.h"
20#include "clang/AST/Expr.h"
21#include "clang/AST/Type.h"
22#include "clang/Basic/LLVM.h"
31#include "llvm/ADT/APSInt.h"
32#include "llvm/ADT/SmallVector.h"
33#include "llvm/Support/Casting.h"
34#include "llvm/Support/ErrorHandling.h"
35#include <cassert>
36#include <cstdint>
37#include <optional>
38
39using namespace clang;
40using namespace ento;
41
43 : svalBuilder(stateMgr.getSValBuilder()), StateMgr(stateMgr),
44 MRMgr(svalBuilder.getRegionManager()), Ctx(stateMgr.getContext()) {}
45
47 const CallEvent &Call,
48 const StackFrameContext *LCtx) {
49 StoreRef Store = StoreRef(OldStore, *this);
50
52 Call.getInitialStackFrameContents(LCtx, InitialBindings);
53
54 for (const auto &I : InitialBindings)
55 Store = Bind(Store.getStore(), I.first.castAs<Loc>(), I.second);
56
57 return Store;
58}
59
61 QualType EleTy,
62 uint64_t index) {
64 return MRMgr.getElementRegion(EleTy, idx, Base, svalBuilder.getContext());
65}
66
68 QualType T) {
70 assert(!T.isNull());
71 return MRMgr.getElementRegion(T, idx, R, Ctx);
72}
73
74std::optional<const MemRegion *> StoreManager::castRegion(const MemRegion *R,
75 QualType CastToTy) {
77
78 // Handle casts to Objective-C objects.
79 if (CastToTy->isObjCObjectPointerType())
80 return R->StripCasts();
81
82 if (CastToTy->isBlockPointerType()) {
83 // FIXME: We may need different solutions, depending on the symbol
84 // involved. Blocks can be casted to/from 'id', as they can be treated
85 // as Objective-C objects. This could possibly be handled by enhancing
86 // our reasoning of downcasts of symbolic objects.
87 if (isa<CodeTextRegion, SymbolicRegion>(R))
88 return R;
89
90 // We don't know what to make of it. Return a NULL region, which
91 // will be interpreted as UnknownVal.
92 return std::nullopt;
93 }
94
95 // Now assume we are casting from pointer to pointer. Other cases should
96 // already be handled.
97 QualType PointeeTy = CastToTy->getPointeeType();
98 QualType CanonPointeeTy = Ctx.getCanonicalType(PointeeTy);
99 CanonPointeeTy = CanonPointeeTy.getLocalUnqualifiedType();
100
101 // Handle casts to void*. We just pass the region through.
102 if (CanonPointeeTy == Ctx.VoidTy)
103 return R;
104
105 const auto IsSameRegionType = [&Ctx](const MemRegion *R, QualType OtherTy) {
106 if (const auto *TR = dyn_cast<TypedValueRegion>(R)) {
107 QualType ObjTy = Ctx.getCanonicalType(TR->getValueType());
108 if (OtherTy == ObjTy.getLocalUnqualifiedType())
109 return true;
110 }
111 return false;
112 };
113
114 // Handle casts from compatible types.
115 if (R->isBoundable() && IsSameRegionType(R, CanonPointeeTy))
116 return R;
117
118 // Process region cast according to the kind of the region being cast.
119 switch (R->getKind()) {
120 case MemRegion::CXXThisRegionKind:
121 case MemRegion::CodeSpaceRegionKind:
122 case MemRegion::StackLocalsSpaceRegionKind:
123 case MemRegion::StackArgumentsSpaceRegionKind:
124 case MemRegion::HeapSpaceRegionKind:
125 case MemRegion::UnknownSpaceRegionKind:
126 case MemRegion::StaticGlobalSpaceRegionKind:
127 case MemRegion::GlobalInternalSpaceRegionKind:
128 case MemRegion::GlobalSystemSpaceRegionKind:
129 case MemRegion::GlobalImmutableSpaceRegionKind: {
130 llvm_unreachable("Invalid region cast");
131 }
132
133 case MemRegion::FunctionCodeRegionKind:
134 case MemRegion::BlockCodeRegionKind:
135 case MemRegion::BlockDataRegionKind:
136 case MemRegion::StringRegionKind:
137 // FIXME: Need to handle arbitrary downcasts.
138 case MemRegion::SymbolicRegionKind:
139 case MemRegion::AllocaRegionKind:
140 case MemRegion::CompoundLiteralRegionKind:
141 case MemRegion::FieldRegionKind:
142 case MemRegion::ObjCIvarRegionKind:
143 case MemRegion::ObjCStringRegionKind:
144 case MemRegion::NonParamVarRegionKind:
145 case MemRegion::ParamVarRegionKind:
146 case MemRegion::CXXTempObjectRegionKind:
147 case MemRegion::CXXBaseObjectRegionKind:
148 case MemRegion::CXXDerivedObjectRegionKind:
149 return MakeElementRegion(cast<SubRegion>(R), PointeeTy);
150
151 case MemRegion::ElementRegionKind: {
152 // If we are casting from an ElementRegion to another type, the
153 // algorithm is as follows:
154 //
155 // (1) Compute the "raw offset" of the ElementRegion from the
156 // base region. This is done by calling 'getAsRawOffset()'.
157 //
158 // (2a) If we get a 'RegionRawOffset' after calling
159 // 'getAsRawOffset()', determine if the absolute offset
160 // can be exactly divided into chunks of the size of the
161 // casted-pointee type. If so, create a new ElementRegion with
162 // the pointee-cast type as the new ElementType and the index
163 // being the offset divded by the chunk size. If not, create
164 // a new ElementRegion at offset 0 off the raw offset region.
165 //
166 // (2b) If we don't a get a 'RegionRawOffset' after calling
167 // 'getAsRawOffset()', it means that we are at offset 0.
168 //
169 // FIXME: Handle symbolic raw offsets.
170
171 const ElementRegion *elementR = cast<ElementRegion>(R);
172 const RegionRawOffset &rawOff = elementR->getAsArrayOffset();
173 const MemRegion *baseR = rawOff.getRegion();
174
175 // If we cannot compute a raw offset, throw up our hands and return
176 // a NULL MemRegion*.
177 if (!baseR)
178 return std::nullopt;
179
180 CharUnits off = rawOff.getOffset();
181
182 if (off.isZero()) {
183 // Edge case: we are at 0 bytes off the beginning of baseR. We check to
184 // see if the type we are casting to is the same as the type of the base
185 // region. If so, just return the base region.
186 if (IsSameRegionType(baseR, CanonPointeeTy))
187 return baseR;
188 // Otherwise, create a new ElementRegion at offset 0.
189 return MakeElementRegion(cast<SubRegion>(baseR), PointeeTy);
190 }
191
192 // We have a non-zero offset from the base region. We want to determine
193 // if the offset can be evenly divided by sizeof(PointeeTy). If so,
194 // we create an ElementRegion whose index is that value. Otherwise, we
195 // create two ElementRegions, one that reflects a raw offset and the other
196 // that reflects the cast.
197
198 // Compute the index for the new ElementRegion.
199 int64_t newIndex = 0;
200 const MemRegion *newSuperR = nullptr;
201
202 // We can only compute sizeof(PointeeTy) if it is a complete type.
203 if (!PointeeTy->isIncompleteType()) {
204 // Compute the size in **bytes**.
205 CharUnits pointeeTySize = Ctx.getTypeSizeInChars(PointeeTy);
206 if (!pointeeTySize.isZero()) {
207 // Is the offset a multiple of the size? If so, we can layer the
208 // ElementRegion (with elementType == PointeeTy) directly on top of
209 // the base region.
210 if (off % pointeeTySize == 0) {
211 newIndex = off / pointeeTySize;
212 newSuperR = baseR;
213 }
214 }
215 }
216
217 if (!newSuperR) {
218 // Create an intermediate ElementRegion to represent the raw byte.
219 // This will be the super region of the final ElementRegion.
220 newSuperR = MakeElementRegion(cast<SubRegion>(baseR), Ctx.CharTy,
221 off.getQuantity());
222 }
223
224 return MakeElementRegion(cast<SubRegion>(newSuperR), PointeeTy, newIndex);
225 }
226 }
227
228 llvm_unreachable("unreachable");
229}
230
232 const MemRegion *MR = V.getAsRegion();
233 if (!MR)
234 return true;
235
236 const auto *TVR = dyn_cast<TypedValueRegion>(MR);
237 if (!TVR)
238 return true;
239
240 const CXXRecordDecl *RD = TVR->getValueType()->getAsCXXRecordDecl();
241 if (!RD)
242 return true;
243
245 if (!Expected)
247
248 return Expected->getCanonicalDecl() == RD->getCanonicalDecl();
249}
250
252 // Early return to avoid doing the wrong thing in the face of
253 // reinterpret_cast.
254 if (!regionMatchesCXXRecordType(Derived, Cast->getSubExpr()->getType()))
255 return UnknownVal();
256
257 // Walk through the cast path to create nested CXXBaseRegions.
258 SVal Result = Derived;
259 for (CastExpr::path_const_iterator I = Cast->path_begin(),
260 E = Cast->path_end();
261 I != E; ++I) {
262 Result = evalDerivedToBase(Result, (*I)->getType(), (*I)->isVirtual());
263 }
264 return Result;
265}
266
268 // Walk through the path to create nested CXXBaseRegions.
269 SVal Result = Derived;
270 for (const auto &I : Path)
271 Result = evalDerivedToBase(Result, I.Base->getType(),
272 I.Base->isVirtual());
273 return Result;
274}
275
277 bool IsVirtual) {
278 const MemRegion *DerivedReg = Derived.getAsRegion();
279 if (!DerivedReg)
280 return Derived;
281
282 const CXXRecordDecl *BaseDecl = BaseType->getPointeeCXXRecordDecl();
283 if (!BaseDecl)
284 BaseDecl = BaseType->getAsCXXRecordDecl();
285 assert(BaseDecl && "not a C++ object?");
286
287 if (const auto *AlreadyDerivedReg =
288 dyn_cast<CXXDerivedObjectRegion>(DerivedReg)) {
289 if (const auto *SR =
290 dyn_cast<SymbolicRegion>(AlreadyDerivedReg->getSuperRegion()))
291 if (SR->getSymbol()->getType()->getPointeeCXXRecordDecl() == BaseDecl)
292 return loc::MemRegionVal(SR);
293
294 DerivedReg = AlreadyDerivedReg->getSuperRegion();
295 }
296
297 const MemRegion *BaseReg = MRMgr.getCXXBaseObjectRegion(
298 BaseDecl, cast<SubRegion>(DerivedReg), IsVirtual);
299
300 return loc::MemRegionVal(BaseReg);
301}
302
303/// Returns the static type of the given region, if it represents a C++ class
304/// object.
305///
306/// This handles both fully-typed regions, where the dynamic type is known, and
307/// symbolic regions, where the dynamic type is merely bounded (and even then,
308/// only ostensibly!), but does not take advantage of any dynamic type info.
309static const CXXRecordDecl *getCXXRecordType(const MemRegion *MR) {
310 if (const auto *TVR = dyn_cast<TypedValueRegion>(MR))
311 return TVR->getValueType()->getAsCXXRecordDecl();
312 if (const auto *SR = dyn_cast<SymbolicRegion>(MR))
313 return SR->getSymbol()->getType()->getPointeeCXXRecordDecl();
314 return nullptr;
315}
316
318 QualType TargetType) {
319 const MemRegion *MR = Base.getAsRegion();
320 if (!MR)
321 return UnknownVal();
322
323 // Assume the derived class is a pointer or a reference to a CXX record.
324 TargetType = TargetType->getPointeeType();
325 assert(!TargetType.isNull());
326 const CXXRecordDecl *TargetClass = TargetType->getAsCXXRecordDecl();
327 if (!TargetClass && !TargetType->isVoidType())
328 return UnknownVal();
329
330 // Drill down the CXXBaseObject chains, which represent upcasts (casts from
331 // derived to base).
332 while (const CXXRecordDecl *MRClass = getCXXRecordType(MR)) {
333 // If found the derived class, the cast succeeds.
334 if (MRClass == TargetClass)
335 return loc::MemRegionVal(MR);
336
337 // We skip over incomplete types. They must be the result of an earlier
338 // reinterpret_cast, as one can only dynamic_cast between types in the same
339 // class hierarchy.
340 if (!TargetType->isVoidType() && MRClass->hasDefinition()) {
341 // Static upcasts are marked as DerivedToBase casts by Sema, so this will
342 // only happen when multiple or virtual inheritance is involved.
343 CXXBasePaths Paths(/*FindAmbiguities=*/false, /*RecordPaths=*/true,
344 /*DetectVirtual=*/false);
345 if (MRClass->isDerivedFrom(TargetClass, Paths))
346 return evalDerivedToBase(loc::MemRegionVal(MR), Paths.front());
347 }
348
349 if (const auto *BaseR = dyn_cast<CXXBaseObjectRegion>(MR)) {
350 // Drill down the chain to get the derived classes.
351 MR = BaseR->getSuperRegion();
352 continue;
353 }
354
355 // If this is a cast to void*, return the region.
356 if (TargetType->isVoidType())
357 return loc::MemRegionVal(MR);
358
359 // Strange use of reinterpret_cast can give us paths we don't reason
360 // about well, by putting in ElementRegions where we'd expect
361 // CXXBaseObjectRegions. If it's a valid reinterpret_cast (i.e. if the
362 // derived class has a zero offset from the base class), then it's safe
363 // to strip the cast; if it's invalid, -Wreinterpret-base-class should
364 // catch it. In the interest of performance, the analyzer will silently
365 // do the wrong thing in the invalid case (because offsets for subregions
366 // will be wrong).
367 const MemRegion *Uncasted = MR->StripCasts(/*IncludeBaseCasts=*/false);
368 if (Uncasted == MR) {
369 // We reached the bottom of the hierarchy and did not find the derived
370 // class. We must be casting the base to derived, so the cast should
371 // fail.
372 break;
373 }
374
375 MR = Uncasted;
376 }
377
378 // If we're casting a symbolic base pointer to a derived class, use
379 // CXXDerivedObjectRegion to represent the cast. If it's a pointer to an
380 // unrelated type, it must be a weird reinterpret_cast and we have to
381 // be fine with ElementRegion. TODO: Should we instead make
382 // Derived{TargetClass, Element{SourceClass, SR}}?
383 if (const auto *SR = dyn_cast<SymbolicRegion>(MR)) {
384 QualType T = SR->getSymbol()->getType();
385 const CXXRecordDecl *SourceClass = T->getPointeeCXXRecordDecl();
386 if (TargetClass && SourceClass && TargetClass->isDerivedFrom(SourceClass))
387 return loc::MemRegionVal(
388 MRMgr.getCXXDerivedObjectRegion(TargetClass, SR));
389 return loc::MemRegionVal(GetElementZeroRegion(SR, TargetType));
390 }
391
392 // We failed if the region we ended up with has perfect type info.
393 if (isa<TypedValueRegion>(MR))
394 return std::nullopt;
395
396 return UnknownVal();
397}
398
399SVal StoreManager::getLValueFieldOrIvar(const Decl *D, SVal Base) {
400 if (Base.isUnknownOrUndef())
401 return Base;
402
403 Loc BaseL = Base.castAs<Loc>();
404 const SubRegion* BaseR = nullptr;
405
406 switch (BaseL.getSubKind()) {
407 case loc::MemRegionValKind:
408 BaseR = cast<SubRegion>(BaseL.castAs<loc::MemRegionVal>().getRegion());
409 break;
410
411 case loc::GotoLabelKind:
412 // These are anormal cases. Flag an undefined value.
413 return UndefinedVal();
414
415 case loc::ConcreteIntKind:
416 // While these seem funny, this can happen through casts.
417 // FIXME: What we should return is the field offset, not base. For example,
418 // add the field offset to the integer value. That way things
419 // like this work properly: &(((struct foo *) 0xa)->f)
420 // However, that's not easy to fix without reducing our abilities
421 // to catch null pointer dereference. Eg., ((struct foo *)0x0)->f = 7
422 // is a null dereference even though we're dereferencing offset of f
423 // rather than null. Coming up with an approach that computes offsets
424 // over null pointers properly while still being able to catch null
425 // dereferences might be worth it.
426 return Base;
427
428 default:
429 llvm_unreachable("Unhandled Base.");
430 }
431
432 // NOTE: We must have this check first because ObjCIvarDecl is a subclass
433 // of FieldDecl.
434 if (const auto *ID = dyn_cast<ObjCIvarDecl>(D))
435 return loc::MemRegionVal(MRMgr.getObjCIvarRegion(ID, BaseR));
436
437 return loc::MemRegionVal(MRMgr.getFieldRegion(cast<FieldDecl>(D), BaseR));
438}
439
441 return getLValueFieldOrIvar(decl, base);
442}
443
445 SVal Base) {
446
447 // Special case, if index is 0, return the same type as if
448 // this was not an array dereference.
449 if (Offset.isZeroConstant()) {
450 QualType BT = Base.getType(this->Ctx);
451 if (!BT.isNull() && !elementType.isNull()) {
452 QualType PointeeTy = BT->getPointeeType();
453 if (!PointeeTy.isNull() &&
454 PointeeTy.getCanonicalType() == elementType.getCanonicalType())
455 return Base;
456 }
457 }
458
459 // If the base is an unknown or undefined value, just return it back.
460 // FIXME: For absolute pointer addresses, we just return that value back as
461 // well, although in reality we should return the offset added to that
462 // value. See also the similar FIXME in getLValueFieldOrIvar().
463 if (Base.isUnknownOrUndef() || isa<loc::ConcreteInt>(Base))
464 return Base;
465
466 if (isa<loc::GotoLabel>(Base))
467 return UnknownVal();
468
469 const SubRegion *BaseRegion =
470 Base.castAs<loc::MemRegionVal>().getRegionAs<SubRegion>();
471
472 // Pointer of any type can be cast and used as array base.
473 const auto *ElemR = dyn_cast<ElementRegion>(BaseRegion);
474
475 // Convert the offset to the appropriate size and signedness.
477
478 if (!ElemR) {
479 // If the base region is not an ElementRegion, create one.
480 // This can happen in the following example:
481 //
482 // char *p = __builtin_alloc(10);
483 // p[1] = 8;
484 //
485 // Observe that 'p' binds to an AllocaRegion.
487 BaseRegion, Ctx));
488 }
489
490 SVal BaseIdx = ElemR->getIndex();
491
492 if (!isa<nonloc::ConcreteInt>(BaseIdx))
493 return UnknownVal();
494
495 const llvm::APSInt &BaseIdxI =
497
498 // Only allow non-integer offsets if the base region has no offset itself.
499 // FIXME: This is a somewhat arbitrary restriction. We should be using
500 // SValBuilder here to add the two offsets without checking their types.
501 if (!isa<nonloc::ConcreteInt>(Offset)) {
502 if (isa<ElementRegion>(BaseRegion->StripCasts()))
503 return UnknownVal();
504
506 elementType, Offset, cast<SubRegion>(ElemR->getSuperRegion()), Ctx));
507 }
508
509 const llvm::APSInt& OffI = Offset.castAs<nonloc::ConcreteInt>().getValue();
510 assert(BaseIdxI.isSigned());
511
512 // Compute the new index.
513 nonloc::ConcreteInt NewIdx(svalBuilder.getBasicValueFactory().getValue(BaseIdxI +
514 OffI));
515
516 // Construct the new ElementRegion.
517 const SubRegion *ArrayR = cast<SubRegion>(ElemR->getSuperRegion());
518 return loc::MemRegionVal(MRMgr.getElementRegion(elementType, NewIdx, ArrayR,
519 Ctx));
520}
521
523
525 Store store,
526 const MemRegion* R,
527 SVal val) {
528 SymbolRef SymV = val.getAsLocSymbol();
529 if (!SymV || SymV != Sym)
530 return true;
531
532 if (Binding) {
533 First = false;
534 return false;
535 }
536 else
537 Binding = R;
538
539 return true;
540}
Defines the clang::ASTContext interface.
#define V(N, I)
Definition: ASTContext.h:3217
static SVal getValue(SVal val, SValBuilder &svalBuilder)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
unsigned Offset
Definition: Format.cpp:2776
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
static bool regionMatchesCXXRecordType(SVal V, QualType Ty)
Definition: Store.cpp:231
static const CXXRecordDecl * getCXXRecordType(const MemRegion *MR)
Returns the static type of the given region, if it represents a C++ class object.
Definition: Store.cpp:309
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2505
CanQualType CharTy
Definition: ASTContext.h:1080
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
CanQualType VoidTy
Definition: ASTContext.h:1078
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:507
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3482
const CXXBaseSpecifier *const * path_const_iterator
Definition: Expr.h:3549
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
bool isZero() const
isZero - Test whether the quantity equals zero.
Definition: CharUnits.h:122
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:185
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1939
A (possibly-)qualified type.
Definition: Type.h:736
QualType getLocalUnqualifiedType() const
Return this type with all of the instance-specific qualifiers removed, but without removing any quali...
Definition: Type.h:982
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:803
QualType getCanonicalType() const
Definition: Type.h:6701
It represents a stack frame of the call stack (based on CallEvent).
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1783
bool isBlockPointerType() const
Definition: Type.h:6918
bool isVoidType() const
Definition: Type.h:7218
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
Definition: Type.cpp:1768
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:629
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2259
bool isObjCObjectPointerType() const
Definition: Type.h:7038
Represents an abstract call to a function or method along a particular path.
Definition: CallEvent.h:149
ElementRegion is used to represent both array elements and casts.
Definition: MemRegion.h:1189
RegionRawOffset getAsArrayOffset() const
Compute the offset within the array. The array might also be a subobject.
Definition: MemRegion.cpp:1376
const CXXDerivedObjectRegion * getCXXDerivedObjectRegion(const CXXRecordDecl *BaseClass, const SubRegion *Super)
Create a CXXDerivedObjectRegion with the given derived class for region Super.
Definition: MemRegion.cpp:1243
const FieldRegion * getFieldRegion(const FieldDecl *fd, const SubRegion *superRegion)
getFieldRegion - Retrieve or create the memory region associated with a specified FieldDecl.
Definition: MemRegion.cpp:1181
const ObjCIvarRegion * getObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *superRegion)
getObjCIvarRegion - Retrieve or create the memory region associated with a specified Objective-c inst...
Definition: MemRegion.cpp:1187
const ElementRegion * getElementRegion(QualType elementType, NonLoc Idx, const SubRegion *superRegion, ASTContext &Ctx)
getElementRegion - Retrieve the memory region associated with the associated element type,...
Definition: MemRegion.cpp:1135
const CXXBaseObjectRegion * getCXXBaseObjectRegion(const CXXRecordDecl *BaseClass, const SubRegion *Super, bool IsVirtual)
Create a CXXBaseObjectRegion with the given base class for region Super.
Definition: MemRegion.cpp:1223
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:95
virtual bool isBoundable() const
Definition: MemRegion.h:179
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * StripCasts(bool StripBaseAndDerivedCasts=true) const
Definition: MemRegion.cpp:1342
Kind getKind() const
Definition: MemRegion.h:173
CharUnits getOffset() const
Definition: MemRegion.h:1179
const MemRegion * getRegion() const
Definition: MemRegion.h:1182
BasicValueFactory & getBasicValueFactory()
Definition: SValBuilder.h:149
NonLoc makeArrayIndex(uint64_t idx)
Definition: SValBuilder.h:263
ASTContext & getContext()
Definition: SValBuilder.h:136
SVal convertToArrayIndex(SVal val)
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
Definition: SVals.h:72
unsigned getSubKind() const
Definition: SVals.h:109
SymbolRef getAsLocSymbol(bool IncludeBaseRegions=false) const
If this SVal is a location and wraps a symbol, return that SymbolRef.
Definition: SVals.cpp:68
const MemRegion * getAsRegion() const
Definition: SVals.cpp:120
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
Definition: SVals.h:99
bool HandleBinding(StoreManager &SMgr, Store store, const MemRegion *R, SVal val) override
Definition: Store.cpp:524
SVal evalDerivedToBase(SVal Derived, const CastExpr *Cast)
Evaluates a chain of derived-to-base casts through the path specified in Cast.
Definition: Store.cpp:251
ProgramStateManager & StateMgr
Definition: Store.h:56
virtual StoreRef Bind(Store store, Loc loc, SVal val)=0
Return a store with the specified value bound to the given location.
std::optional< SVal > evalBaseToDerived(SVal Base, QualType DerivedPtrType)
Attempts to do a down cast.
Definition: Store.cpp:317
const ElementRegion * MakeElementRegion(const SubRegion *baseRegion, QualType pointeeTy, uint64_t index=0)
Definition: Store.cpp:60
StoreRef enterStackFrame(Store store, const CallEvent &Call, const StackFrameContext *CalleeCtx)
enterStackFrame - Let the StoreManager to do something when execution engine is about to execute into...
Definition: Store.cpp:46
MemRegionManager & MRMgr
MRMgr - Manages region objects associated with this StoreManager.
Definition: Store.h:59
SValBuilder & svalBuilder
Definition: Store.h:55
virtual SVal getLValueIvar(const ObjCIvarDecl *decl, SVal base)
Definition: Store.cpp:440
StoreManager(ProgramStateManager &stateMgr)
Definition: Store.cpp:42
const ElementRegion * GetElementZeroRegion(const SubRegion *R, QualType T)
Definition: Store.cpp:67
virtual SVal getLValueElement(QualType elementType, NonLoc offset, SVal Base)
Definition: Store.cpp:444
std::optional< const MemRegion * > castRegion(const MemRegion *region, QualType CastToTy)
castRegion - Used by ExprEngine::VisitCast to handle casts from a MemRegion* to a specific location t...
Definition: Store.cpp:74
ASTContext & Ctx
Definition: Store.h:60
SubRegion - A region that subsets another larger region.
Definition: MemRegion.h:442
Symbolic value.
Definition: SymExpr.h:29
const MemRegion * getRegion() const
Get the underlining region.
Definition: SVals.h:512
Value representing integer constant.
Definition: SVals.h:329
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
Definition: StoreRef.h:27
@ Result
The result type of a method or function.