Go to the documentation of this file.
31 #include "llvm/ADT/APSInt.h"
32 #include "llvm/ADT/Optional.h"
33 #include "llvm/ADT/SmallVector.h"
34 #include "llvm/Support/Casting.h"
35 #include "llvm/Support/ErrorHandling.h"
39 using namespace clang;
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::CXXBaseObjectRegionKind:
148 case MemRegion::CXXDerivedObjectRegionKind:
151 case MemRegion::ElementRegionKind: {
186 if (IsSameRegionType(baseR, CanonPointeeTy))
199 int64_t newIndex = 0;
206 if (!pointeeTySize.
isZero()) {
210 if (off % pointeeTySize == 0) {
211 newIndex = off / pointeeTySize;
228 llvm_unreachable(
"unreachable");
232 const MemRegion *MR =
V.getAsRegion();
236 const auto *TVR = dyn_cast<TypedValueRegion>(MR);
240 const CXXRecordDecl *RD = TVR->getValueType()->getAsCXXRecordDecl();
258 SVal Result = Derived;
260 E =
Cast->path_end();
269 SVal Result = Derived;
270 for (
const auto &I : Path)
272 I.Base->isVirtual());
278 const MemRegion *DerivedReg = Derived.
getAsRegion();
285 assert(BaseDecl &&
"not a C++ object?");
287 if (
const auto *AlreadyDerivedReg =
288 dyn_cast<CXXDerivedObjectRegion>(DerivedReg)) {
290 dyn_cast<SymbolicRegion>(AlreadyDerivedReg->getSuperRegion()))
291 if (SR->getSymbol()->getType()->getPointeeCXXRecordDecl() == BaseDecl)
292 return loc::MemRegionVal(SR);
294 DerivedReg = AlreadyDerivedReg->getSuperRegion();
298 BaseDecl, cast<SubRegion>(DerivedReg), IsVirtual);
300 return loc::MemRegionVal(BaseReg);
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();
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)) {
383 QualType T = SR->getSymbol()->getType();
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() &&
472 const auto *ElemR = dyn_cast<ElementRegion>(BaseRegion);
489 SVal BaseIdx = ElemR->getIndex();
501 if (isa<ElementRegion>(BaseRegion->
StripCasts()))
505 elementType,
Offset, cast<SubRegion>(ElemR->getSuperRegion()),
Ctx));
509 assert(BaseIdxI.isSigned());
516 const SubRegion *ArrayR = cast<SubRegion>(ElemR->getSuperRegion());
528 if (!SymV || SymV != Sym)
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
const ObjCIvarRegion * getObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *superRegion)
getObjCIvarRegion - Retrieve or create the memory region associated with a specified Objective-c inst...
virtual SVal getLValueElement(QualType elementType, NonLoc offset, SVal Base)
bool isBlockPointerType() const
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
const MemRegion * getAsRegion() const
const MemRegion * StripCasts(bool StripBaseAndDerivedCasts=true) const
StoreManager(ProgramStateManager &stateMgr)
A (possibly-)qualified type.
QualType getCanonicalType() const
static bool regionMatchesCXXRecordType(SVal V, QualType Ty)
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...
It represents a stack frame of the call stack (based on CallEvent).
Value representing integer constant.
const CXXDerivedObjectRegion * getCXXDerivedObjectRegion(const CXXRecordDecl *BaseClass, const SubRegion *Super)
Create a CXXDerivedObjectRegion with the given derived class for region Super.
SVal evalDerivedToBase(SVal Derived, const CastExpr *Cast)
Evaluates a chain of derived-to-base casts through the path specified in Cast.
const void * Store
Store - This opaque type encapsulates an immutable mapping from locations to values.
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type.
static SVal getValue(SVal val, SValBuilder &svalBuilder)
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.
SymbolRef getAsLocSymbol(bool IncludeBaseRegions=false) const
If this SVal is a location and wraps a symbol, return that SymbolRef.
const FieldRegion * getFieldRegion(const FieldDecl *fd, const SubRegion *superRegion)
getFieldRegion - Retrieve or create the memory region associated with a specified FieldDecl.
virtual ~BindingsHandler()
ASTContext & getContext()
virtual bool isBoundable() const
ASTContext & getContext()
bool HandleBinding(StoreManager &SMgr, Store store, const MemRegion *R, SVal val) override
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
NonLoc makeZeroArrayIndex()
SVal convertToArrayIndex(SVal val)
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
const ElementRegion * getElementRegion(QualType elementType, NonLoc Idx, const SubRegion *superRegion, ASTContext &Ctx)
getElementRegion - Retrieve the memory region associated with the associated element type,...
bool Cast(InterpState &S, CodePtr OpPC)
BasicValueFactory & getBasicValueFactory()
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
bool isDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is derived from the class Base.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
CharUnits getOffset() const
ElementRegion is used to represent both array elements and casts.
bool isObjCObjectPointerType() const
Represents a C++ struct/union/class.
virtual SVal getLValueIvar(const ObjCIvarDecl *decl, SVal base)
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
const typedef CXXBaseSpecifier *const * path_const_iterator
const ElementRegion * MakeElementRegion(const SubRegion *baseRegion, QualType pointeeTy, uint64_t index=0)
QualType getLocalUnqualifiedType() const
Return this type with all of the instance-specific qualifiers removed, but without removing any quali...
SValBuilder & svalBuilder
bool isZero() const
isZero - Test whether the quantity equals zero.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Decl - This represents one declaration (or definition), e.g.
unsigned getSubKind() const
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...
static const CXXRecordDecl * getCXXRecordType(const MemRegion *MR)
Returns the static type of the given region, if it represents a C++ class object.
virtual StoreRef Bind(Store store, Loc loc, SVal val)=0
Return a store with the specified value bound to the given location.
ProgramStateManager & StateMgr
const MemRegion * getRegion() const
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
ObjCIvarDecl - Represents an ObjC instance variable.
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Represents an abstract call to a function or method along a particular path.
NonLoc makeArrayIndex(uint64_t idx)
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
CharUnits - This is an opaque type for sizes expressed in character units.
SubRegion - A region that subsets another larger region.
Optional< SVal > evalBaseToDerived(SVal Base, QualType DerivedPtrType)
Attempts to do a down cast.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
const ElementRegion * GetElementZeroRegion(const SubRegion *R, QualType T)
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
RegionRawOffset getAsArrayOffset() const
Compute the offset within the array. The array might also be a subobject.
const MemRegion * getRegion() const
Get the underlining region.
MemRegionManager & MRMgr
MRMgr - Manages region objects associated with this StoreManager.