31#include "llvm/ADT/APSInt.h"
32#include "llvm/ADT/SmallVector.h"
33#include "llvm/Support/Casting.h"
34#include "llvm/Support/ErrorHandling.h"
43 : svalBuilder(stateMgr.getSValBuilder()), StateMgr(stateMgr),
44 MRMgr(svalBuilder.getRegionManager()), Ctx(stateMgr.getContext()) {}
52 Call.getInitialStackFrameContents(LCtx, InitialBindings);
54 for (
const auto &I : InitialBindings)
87 if (isa<CodeTextRegion, SymbolicRegion>(R))
106 if (
const auto *TR = dyn_cast<TypedValueRegion>(R)) {
115 if (R->
isBoundable() && IsSameRegionType(R, CanonPointeeTy))
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");
133 case MemRegion::FunctionCodeRegionKind:
134 case MemRegion::BlockCodeRegionKind:
135 case MemRegion::BlockDataRegionKind:
136 case MemRegion::StringRegionKind:
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::CXXLifetimeExtendedObjectRegionKind:
148 case MemRegion::CXXBaseObjectRegionKind:
149 case MemRegion::CXXDerivedObjectRegionKind:
152 case MemRegion::ElementRegionKind: {
187 if (IsSameRegionType(baseR, CanonPointeeTy))
200 int64_t newIndex = 0;
207 if (!pointeeTySize.
isZero()) {
211 if (off % pointeeTySize == 0) {
212 newIndex = off / pointeeTySize;
229 llvm_unreachable(
"unreachable");
237 const auto *TVR = dyn_cast<TypedValueRegion>(MR);
241 const CXXRecordDecl *RD = TVR->getValueType()->getAsCXXRecordDecl();
269 for (
const auto &I :
Path)
271 I.Base->isVirtual());
284 assert(BaseDecl &&
"not a C++ object?");
286 if (
const auto *AlreadyDerivedReg =
287 dyn_cast<CXXDerivedObjectRegion>(DerivedReg)) {
289 dyn_cast<SymbolicRegion>(AlreadyDerivedReg->getSuperRegion()))
290 if (SR->getSymbol()->getType()->getPointeeCXXRecordDecl() == BaseDecl)
293 DerivedReg = AlreadyDerivedReg->getSuperRegion();
297 BaseDecl, cast<SubRegion>(DerivedReg), IsVirtual);
309 if (
const auto *TVR = dyn_cast<TypedValueRegion>(MR))
310 return TVR->getValueType()->getAsCXXRecordDecl();
311 if (
const auto *SR = dyn_cast<SymbolicRegion>(MR))
312 return SR->getSymbol()->getType()->getPointeeCXXRecordDecl();
324 assert(!TargetType.
isNull());
326 if (!TargetClass && !TargetType->
isVoidType())
333 if (MRClass == TargetClass)
339 if (!TargetType->
isVoidType() && MRClass->hasDefinition()) {
344 if (MRClass->isDerivedFrom(TargetClass, Paths))
348 if (
const auto *BaseR = dyn_cast<CXXBaseObjectRegion>(MR)) {
350 MR = BaseR->getSuperRegion();
367 if (Uncasted == MR) {
382 if (
const auto *SR = dyn_cast<SymbolicRegion>(MR)) {
385 if (TargetClass && SourceClass && TargetClass->
isDerivedFrom(SourceClass))
392 if (isa<TypedValueRegion>(MR))
399 if (
Base.isUnknownOrUndef())
406 case loc::MemRegionValKind:
410 case loc::GotoLabelKind:
414 case loc::ConcreteIntKind:
428 llvm_unreachable(
"Unhandled Base.");
433 if (
const auto *ID = dyn_cast<ObjCIvarDecl>(
D))
440 return getLValueFieldOrIvar(
decl, base);
448 if (Offset.isZeroConstant()) {
452 if (!PointeeTy.
isNull() &&
462 if (
Base.isUnknownOrUndef() || isa<loc::ConcreteInt>(
Base))
465 if (isa<loc::GotoLabel>(
Base))
472 const auto *ElemR = dyn_cast<ElementRegion>(BaseRegion);
485 Offset = Off.value();
499 SVal BaseIdx = ElemR->getIndex();
501 if (!isa<nonloc::ConcreteInt>(BaseIdx))
504 const llvm::APSInt &BaseIdxI =
510 if (!isa<nonloc::ConcreteInt>(Offset)) {
511 if (isa<ElementRegion>(BaseRegion->
StripCasts()))
515 elementType, Offset, cast<SubRegion>(ElemR->getSuperRegion()),
Ctx));
519 assert(BaseIdxI.isSigned());
526 const SubRegion *ArrayR = cast<SubRegion>(ElemR->getSuperRegion());
538 if (!SymV || SymV != Sym)
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
static bool regionMatchesCXXRecordType(SVal V, QualType Ty)
static const CXXRecordDecl * getCXXRecordType(const MemRegion *MR)
Returns the static type of the given region, if it represents a C++ class object.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
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 base class of a C++ class.
Represents a C++ struct/union/class.
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
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...
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Decl - This represents one declaration (or definition), e.g.
ObjCIvarDecl - Represents an ObjC instance variable.
A (possibly-)qualified type.
QualType getLocalUnqualifiedType() const
Return this type with all of the instance-specific qualifiers removed, but without removing any quali...
bool isNull() const
Return true if this QualType doesn't point to a type yet.
QualType getCanonicalType() const
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...
bool isBlockPointerType() const
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
bool isObjCObjectPointerType() const
Represents an abstract call to a function or method along a particular path.
ElementRegion is used to represent both array elements and casts.
RegionRawOffset getAsArrayOffset() const
Compute the offset within the array. The array might also be a subobject.
const CXXDerivedObjectRegion * getCXXDerivedObjectRegion(const CXXRecordDecl *BaseClass, const SubRegion *Super)
Create a CXXDerivedObjectRegion with the given derived class for region Super.
const FieldRegion * getFieldRegion(const FieldDecl *fd, const SubRegion *superRegion)
getFieldRegion - Retrieve or create the memory region associated with a specified FieldDecl.
const ElementRegion * getElementRegion(QualType elementType, NonLoc Idx, const SubRegion *superRegion, const ASTContext &Ctx)
getElementRegion - Retrieve the memory region associated with the associated element type,...
const ObjCIvarRegion * getObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *superRegion)
getObjCIvarRegion - Retrieve or create the memory region associated with a specified Objective-c inst...
const CXXBaseObjectRegion * getCXXBaseObjectRegion(const CXXRecordDecl *BaseClass, const SubRegion *Super, bool IsVirtual)
Create a CXXBaseObjectRegion with the given base class for region Super.
MemRegion - The root abstract class for all memory regions.
virtual bool isBoundable() const
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * StripCasts(bool StripBaseAndDerivedCasts=true) const
ASTContext & getContext()
CharUnits getOffset() const
const MemRegion * getRegion() const
BasicValueFactory & getBasicValueFactory()
NonLoc makeArrayIndex(uint64_t idx)
ASTContext & getContext()
SVal convertToArrayIndex(SVal val)
NonLoc makeZeroArrayIndex()
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
std::optional< T > getAs() const
Convert to the specified SVal type, returning std::nullopt if this SVal is not of the desired type.
SymbolRef getAsLocSymbol(bool IncludeBaseRegions=false) const
If this SVal is a location and wraps a symbol, return that SymbolRef.
const MemRegion * getAsRegion() const
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
virtual ~BindingsHandler()
bool HandleBinding(StoreManager &SMgr, Store store, const MemRegion *R, SVal val) override
SVal evalDerivedToBase(SVal Derived, const CastExpr *Cast)
Evaluates a chain of derived-to-base casts through the path specified in Cast.
ProgramStateManager & StateMgr
std::optional< SVal > evalBaseToDerived(SVal Base, QualType DerivedPtrType)
Attempts to do a down cast.
const ElementRegion * MakeElementRegion(const SubRegion *baseRegion, QualType pointeeTy, uint64_t index=0)
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...
MemRegionManager & MRMgr
MRMgr - Manages region objects associated with this StoreManager.
SValBuilder & svalBuilder
virtual SVal getLValueIvar(const ObjCIvarDecl *decl, SVal base)
StoreManager(ProgramStateManager &stateMgr)
const ElementRegion * GetElementZeroRegion(const SubRegion *R, QualType T)
virtual SVal getLValueElement(QualType elementType, NonLoc offset, SVal Base)
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...
SubRegion - A region that subsets another larger region.
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * getRegion() const
Get the underlining region.
Value representing integer constant.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
The JSON file list parser is used to communicate input to InstallAPI.
@ Bind
'bind' clause, allowed on routine constructs.
@ Result
The result type of a method or function.
const FunctionProtoType * T