31#include "llvm/ADT/APSInt.h"
32#include "llvm/ADT/STLExtras.h"
33#include "llvm/Support/ErrorHandling.h"
50 Call.getInitialStackFrameContents(LCtx, InitialBindings);
52 for (
const auto &[Location, Val] : InitialBindings) {
73 return MRMgr.getElementRegion(
T, idx, R,
Ctx);
100 QualType CanonPointeeTy =
Ctx.getCanonicalType(PointeeTy);
104 if (CanonPointeeTy ==
Ctx.VoidTy)
108 if (
const auto *TR = dyn_cast<TypedValueRegion>(R)) {
109 QualType ObjTy =
Ctx.getCanonicalType(TR->getValueType());
117 if (R->
isBoundable() && IsSameRegionType(R, CanonPointeeTy))
122 case MemRegion::CXXThisRegionKind:
123 case MemRegion::CodeSpaceRegionKind:
124 case MemRegion::StackLocalsSpaceRegionKind:
125 case MemRegion::StackArgumentsSpaceRegionKind:
126 case MemRegion::HeapSpaceRegionKind:
127 case MemRegion::UnknownSpaceRegionKind:
128 case MemRegion::StaticGlobalSpaceRegionKind:
129 case MemRegion::GlobalInternalSpaceRegionKind:
130 case MemRegion::GlobalSystemSpaceRegionKind:
131 case MemRegion::GlobalImmutableSpaceRegionKind: {
132 llvm_unreachable(
"Invalid region cast");
135 case MemRegion::FunctionCodeRegionKind:
136 case MemRegion::BlockCodeRegionKind:
137 case MemRegion::BlockDataRegionKind:
138 case MemRegion::StringRegionKind:
140 case MemRegion::SymbolicRegionKind:
141 case MemRegion::AllocaRegionKind:
142 case MemRegion::CompoundLiteralRegionKind:
143 case MemRegion::FieldRegionKind:
144 case MemRegion::ObjCIvarRegionKind:
145 case MemRegion::ObjCStringRegionKind:
146 case MemRegion::NonParamVarRegionKind:
147 case MemRegion::ParamVarRegionKind:
148 case MemRegion::CXXTempObjectRegionKind:
149 case MemRegion::CXXLifetimeExtendedObjectRegionKind:
150 case MemRegion::CXXBaseObjectRegionKind:
151 case MemRegion::CXXDerivedObjectRegionKind:
154 case MemRegion::ElementRegionKind: {
189 if (IsSameRegionType(baseR, CanonPointeeTy))
202 int64_t newIndex = 0;
208 CharUnits pointeeTySize =
Ctx.getTypeSizeInChars(PointeeTy);
209 if (!pointeeTySize.
isZero()) {
213 if (off % pointeeTySize == 0) {
214 newIndex = off / pointeeTySize;
231 llvm_unreachable(
"unreachable");
239 const auto *TVR = dyn_cast<TypedValueRegion>(MR);
243 const CXXRecordDecl *RD = TVR->getValueType()->getAsCXXRecordDecl();
271 for (
const auto &I : Path)
273 I.Base->isVirtual());
283 const CXXRecordDecl *BaseDecl = BaseType->getPointeeCXXRecordDecl();
285 BaseDecl = BaseType->getAsCXXRecordDecl();
286 assert(BaseDecl &&
"not a C++ object?");
288 if (
const auto *AlreadyDerivedReg =
289 dyn_cast<CXXDerivedObjectRegion>(DerivedReg)) {
291 dyn_cast<SymbolicRegion>(AlreadyDerivedReg->getSuperRegion()))
292 if (SR->getSymbol()->getType()->getPointeeCXXRecordDecl() == BaseDecl)
295 DerivedReg = AlreadyDerivedReg->getSuperRegion();
311 if (
const auto *TVR = dyn_cast<TypedValueRegion>(MR))
312 return TVR->getValueType()->getAsCXXRecordDecl();
313 if (
const auto *SR = dyn_cast<SymbolicRegion>(MR))
314 return SR->getSymbol()->getType()->getPointeeCXXRecordDecl();
326 assert(!TargetType.
isNull());
328 if (!TargetClass && !TargetType->
isVoidType())
335 if (MRClass == TargetClass)
341 if (!TargetType->
isVoidType() && MRClass->hasDefinition()) {
346 if (MRClass->isDerivedFrom(TargetClass, Paths))
350 if (
const auto *BaseR = dyn_cast<CXXBaseObjectRegion>(MR)) {
352 MR = BaseR->getSuperRegion();
369 if (Uncasted == MR) {
384 if (
const auto *SR = dyn_cast<SymbolicRegion>(MR)) {
387 if (TargetClass && SourceClass && TargetClass->
isDerivedFrom(SourceClass))
389 MRMgr.getCXXDerivedObjectRegion(TargetClass, SR));
401 if (
Base.isUnknownOrUndef())
408 case loc::MemRegionValKind:
412 case loc::GotoLabelKind:
416 case loc::ConcreteIntKind:
430 llvm_unreachable(
"Unhandled Base.");
435 if (
const auto *ID = dyn_cast<ObjCIvarDecl>(D))
442 return getLValueFieldOrIvar(
decl, base);
450 if (Offset.isZeroConstant()) {
454 if (!PointeeTy.
isNull() &&
474 const auto *ElemR = dyn_cast<ElementRegion>(BaseRegion);
487 Offset = Off.value();
501 SVal BaseIdx = ElemR->getIndex();
506 const llvm::APSInt &BaseIdxI =
517 assert(BaseIdxI.isSigned());
536 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 ...
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).
bool isBlockPointerType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
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 FieldRegion * getFieldRegion(const FieldDecl *FD, const SubRegion *SuperRegion)
getFieldRegion - Retrieve or create the memory region associated with a specified FieldDecl.
const ObjCIvarRegion * getObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *superRegion)
getObjCIvarRegion - Retrieve or create the memory region associated with a specified Objective-c inst...
MemRegion - The root abstract class for all memory regions.
virtual bool isBoundable() const
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * StripCasts(bool StripBaseAndDerivedCasts=true) const
CharUnits getOffset() const
const MemRegion * getRegion() const
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
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
SValBuilder & getSValBuilder()
MemRegionManager & getRegionManager()
getRegionManager - Returns the internal RegionManager object that is used to query and manipulate Mem...
std::optional< SVal > evalBaseToDerived(SVal Base, QualType DerivedPtrType)
Attempts to do a down cast.
BindResult enterStackFrame(Store store, const CallEvent &Call, const StackFrameContext *CalleeCtx)
enterStackFrame - Let the StoreManager to do something when execution engine is about to execute into...
const ElementRegion * MakeElementRegion(const SubRegion *baseRegion, QualType pointeeTy, uint64_t index=0)
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 SymExpr * SymbolRef
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.
bool isa(CodeGen::Address addr)
@ Bind
'bind' clause, allowed on routine constructs.
@ Result
The result type of a method or function.
const FunctionProtoType * T
U cast(CodeGen::Address addr)
llvm::SmallVector< SVal, 0 > FailedToBindValues