16 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_MEMREGION_H
17 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_MEMREGION_H
25 #include "llvm/ADT/FoldingSet.h"
26 #include "llvm/Support/Allocator.h"
27 #include "llvm/Support/ErrorHandling.h"
32 class LocationContext;
33 class StackFrameContext;
38 class MemRegionManager;
133 virtual void Profile(llvm::FoldingSetNodeID&
ID)
const = 0;
186 template<
typename RegionTy>
const RegionTy*
getAs()
const;
209 void Profile(llvm::FoldingSetNodeID &
ID)
const override;
218 virtual void anchor();
243 void Profile(llvm::FoldingSetNodeID &
ID)
const override;
332 virtual void anchor();
347 virtual void anchor();
373 void Profile(llvm::FoldingSetNodeID &
ID)
const override;
383 virtual void anchor();
398 virtual void anchor();
416 virtual void anchor();
463 void Profile(llvm::FoldingSetNodeID&
ID)
const override;
550 assert(isa<ObjCMethodDecl>(fd) || isa<FunctionDecl>(fd));
555 if (
const FunctionDecl *D = dyn_cast<FunctionDecl>(FD)) {
559 assert(isa<ObjCMethodDecl>(FD));
560 assert(
false &&
"Getting the type of ObjCMethod is not supported yet");
573 void Profile(llvm::FoldingSetNodeID&
ID)
const override;
614 void Profile(llvm::FoldingSetNodeID&
ID)
const override;
636 void *ReferencedVars;
643 ReferencedVars(nullptr), OriginalVars(nullptr) {}
658 : R(r), OriginalR(originalR) {}
661 return cast<VarRegion>(*R);
664 return cast<VarRegion>(*OriginalR);
668 assert((R ==
nullptr) == (I.R ==
nullptr));
672 assert((R ==
nullptr) == (I.R ==
nullptr));
691 void Profile(llvm::FoldingSetNodeID&
ID)
const override;
701 void LazyInitializeReferencedVars();
702 std::pair<const VarRegion *, const VarRegion *>
703 getCaptureRegions(
const VarDecl *VD);
727 void Profile(llvm::FoldingSetNodeID&
ID)
const override;
765 void Profile(llvm::FoldingSetNodeID&
ID)
const override {
799 void Profile(llvm::FoldingSetNodeID&
ID)
const override {
821 static void ProfileRegion(llvm::FoldingSetNodeID&
ID,
831 void Profile(llvm::FoldingSetNodeID&
ID)
const override;
854 void Profile(llvm::FoldingSetNodeID&
ID)
const override;
869 static void ProfileRegion(llvm::FoldingSetNodeID&
ID,
const VarDecl *VD,
874 void Profile(llvm::FoldingSetNodeID&
ID)
const override;
906 static void ProfileRegion(llvm::FoldingSetNodeID &
ID,
910 void Profile(llvm::FoldingSetNodeID &
ID)
const override;
966 static void ProfileRegion(llvm::FoldingSetNodeID&
ID,
const ObjCIvarDecl *ivd,
996 : Region(reg),
Offset(offset) {}
1016 ElementType(elementType), Index(Idx) {
1019 "The index must be signed");
1022 static void ProfileRegion(llvm::FoldingSetNodeID&
ID,
QualType elementType,
1041 void Profile(llvm::FoldingSetNodeID&
ID)
const override;
1057 static void ProfileRegion(llvm::FoldingSetNodeID &
ID,
1069 void Profile(llvm::FoldingSetNodeID &
ID)
const override;
1081 llvm::PointerIntPair<const CXXRecordDecl *, 1, bool> Data;
1087 static void ProfileRegion(llvm::FoldingSetNodeID &
ID,
const CXXRecordDecl *RD,
1098 void Profile(llvm::FoldingSetNodeID &
ID)
const override;
1109 template<
typename RegionTy>
1111 if (
const RegionTy* RT = dyn_cast<RegionTy>(
this))
1123 llvm::BumpPtrAllocator& A;
1124 llvm::FoldingSet<MemRegion> Regions;
1131 llvm::DenseMap<const StackFrameContext *, StackLocalsSpaceRegion *>
1132 StackLocalsSpaceRegions;
1133 llvm::DenseMap<const StackFrameContext *, StackArgumentsSpaceRegion *>
1134 StackArgumentsSpaceRegions;
1135 llvm::DenseMap<const CodeTextRegion *, StaticGlobalSpaceRegion *>
1136 StaticsGlobalSpaceRegions;
1144 : C(c), A(a), InternalGlobals(nullptr), SystemGlobals(nullptr),
1145 ImmutableGlobals(nullptr), heap(nullptr), unknown(nullptr),
1275 unsigned blockCount);
1283 template <
typename RegionTy,
typename A1>
1284 RegionTy* getRegion(
const A1 a1);
1286 template <
typename RegionTy,
typename A1>
1287 RegionTy* getSubRegion(
const A1 a1,
const MemRegion* superRegion);
1289 template <
typename RegionTy,
typename A1,
typename A2>
1290 RegionTy* getRegion(
const A1 a1,
const A2 a2);
1292 template <
typename RegionTy,
typename A1,
typename A2>
1293 RegionTy* getSubRegion(
const A1 a1,
const A2 a2,
1296 template <
typename RegionTy,
typename A1,
typename A2,
typename A3>
1297 RegionTy* getSubRegion(
const A1 a1,
const A2 a2,
const A3 a3,
1300 template <
typename REG>
1301 const REG* LazyAllocate(REG*& region);
1303 template <
typename REG,
typename ARG>
1304 const REG* LazyAllocate(REG*& region, ARG a);
1321 typedef unsigned char StorageTypeForKinds;
1322 llvm::DenseMap<const MemRegion *, StorageTypeForKinds> MRTraitsMap;
1323 llvm::DenseMap<SymbolRef, StorageTypeForKinds> SymTraitsMap;
1325 typedef llvm::DenseMap<const MemRegion *, StorageTypeForKinds>::const_iterator
1326 const_region_iterator;
1327 typedef llvm::DenseMap<SymbolRef, StorageTypeForKinds>::const_iterator
1328 const_symbol_iterator;
Suppress pointer-escaping of a region.
bool hasStackStorage() const
RegionOffset(const MemRegion *r, int64_t off)
bool isBoundable() const override
Defines the clang::ASTContext interface.
bool hasTrait(SymbolRef Sym, InvalidationKinds IK)
void dumpToStream(raw_ostream &os) const override
TypedValueRegion - An abstract class representing regions having a typed value.
static bool classof(const MemRegion *R)
void Profile(llvm::FoldingSetNodeID &ID) const override
QualType getValueType() const override
MemRegion - The root abstract class for all memory regions.
virtual DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const
getExtent - Returns the size of the region in bytes.
const FieldRegion * getFieldRegion(const FieldDecl *fd, const MemRegion *superRegion)
virtual bool canPrintPretty() const
Returns true if this region can be printed in a user-friendly way.
SubRegion(const MemRegion *sReg, Kind k)
const Decl * getDecl() const
const CodeTextRegion * getCodeRegion() const
Information about invalidation for a particular region/symbol.
MemRegionManager * getMemRegionManager() const override
const StackFrameContext * getStackFrame() const
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression...
static void ProfileRegion(llvm::FoldingSetNodeID &ID, const FieldDecl *FD, const MemRegion *superRegion)
bool hasGlobalsOrParametersStorage() const
virtual QualType getValueType() const =0
virtual bool isBoundable() const
void dumpToStream(raw_ostream &os) const override
const StringRegion * getStringRegion(const StringLiteral *Str)
AnalysisDeclContext * getAnalysisDeclContext() const
static bool classof(const MemRegion *R)
static bool classof(const MemRegion *R)
const RegionTy * getAs() const
const GlobalsSpaceRegion * getGlobalsRegion(MemRegion::Kind K=MemRegion::GlobalInternalSpaceRegionKind, const CodeTextRegion *R=nullptr)
QualType getLocationType() const override
CharUnits getOffset() const
static bool classof(const MemRegion *region)
static bool classof(const MemRegion *R)
Value representing integer constant.
static bool classof(const MemRegion *R)
const StackArgumentsSpaceRegion * getStackArgumentsRegion(const StackFrameContext *STC)
ASTContext & getContext()
void printPretty(raw_ostream &os) const override
Print the region for use in diagnostics.
referenced_vars_iterator referenced_vars_begin() const
void Profile(llvm::FoldingSetNodeID &ID) const override
const Expr * getExpr() const
void setTrait(SymbolRef Sym, InvalidationKinds IK)
void Profile(llvm::FoldingSetNodeID &ID) const override
QualType getElementType() const
std::string getString() const
Get a string representation of a region for debug use.
const MemSpaceRegion * getCodeRegion()
const ObjCStringRegion * getObjCStringRegion(const ObjCStringLiteral *Str)
const MemRegion * getBaseRegion() const
referenced_vars_iterator referenced_vars_end() const
Symbolic value. These values used to capture symbolic execution of the program.
static void ProfileRegion(llvm::FoldingSetNodeID &ID, const BlockDecl *BD, CanQualType, const AnalysisDeclContext *, const MemRegion *)
const MemSpaceRegion * getMemorySpace() const
DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const override
getExtent - Returns the size of the region in bytes.
AllocaRegion(const Expr *ex, unsigned cnt, const MemRegion *superRegion)
GlobalsSpaceRegion(MemRegionManager *mgr, Kind k)
The region containing globals which can be modified by calls to "internally" defined functions - (for...
const HeapSpaceRegion * getHeapRegion()
The region associated with an ObjCStringLiteral.
void Profile(llvm::FoldingSetNodeID &ID) const override
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const MemRegion * getRegion() const
bool hasStackParametersStorage() const
const BlockDataRegion * getBlockDataRegion(const BlockTextRegion *bc, const LocationContext *lc, unsigned blockCount)
const StackLocalsSpaceRegion * getStackLocalsRegion(const StackFrameContext *STC)
const ObjCIvarRegion * getObjCIvarRegion(const ObjCIvarDecl *ivd, const MemRegion *superRegion)
const CXXBaseObjectRegion * getCXXBaseObjectRegionWithSuper(const CXXBaseObjectRegion *baseReg, const MemRegion *superRegion)
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
const CXXRecordDecl * getDecl() const
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
QualType getValueType() const override
FunctionTextRegion(const NamedDecl *fd, const MemRegion *sreg)
bool isBoundable() const override
The region containing globals which are considered not to be modified or point to data which could be...
const FunctionTextRegion * getFunctionTextRegion(const NamedDecl *FD)
const SymbolicRegion * getSymbolicRegion(SymbolRef Sym)
Retrieve or create a "symbolic" memory region.
void Profile(llvm::FoldingSetNodeID &ID) const override
static bool classof(const MemRegion *R)
void dumpToStream(raw_ostream &os) const override
const VarDecl * getDecl() const
RegionRawOffset getAsArrayOffset() const
Compute the offset within the array. The array might also be a subobject.
CodeTextRegion(const MemRegion *sreg, Kind k)
const BlockTextRegion * getBlockTextRegion(const BlockDecl *BD, CanQualType locTy, AnalysisDeclContext *AC)
ObjCStringRegion(const ObjCStringLiteral *str, const MemRegion *sreg)
const AllocaRegion * getAllocaRegion(const Expr *Ex, unsigned Cnt, const LocationContext *LC)
getAllocaRegion - Retrieve a region associated with a call to alloca().
const SymbolicRegion * getSymbolicBase() const
If this is a symbolic region, returns the region. Otherwise, goes up the base chain looking for the f...
static bool classof(const MemRegion *R)
const ObjCIvarDecl * getDecl() const
void dumpToStream(raw_ostream &os) const override
const StringLiteral * getStringLiteral() const
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
QualType getValueType() const override
referenced_vars_iterator(const MemRegion *const *r, const MemRegion *const *originalR)
SymbolRef getSymbol() const
SymbolicRegion(const SymbolRef s, const MemRegion *sreg)
void Profile(llvm::FoldingSetNodeID &ID) const override
void Profile(llvm::FoldingSetNodeID &ID) const override
void dumpToStream(raw_ostream &os) const override
static bool classof(const MemRegion *R)
static bool classof(const MemRegion *R)
void Profile(llvm::FoldingSetNodeID &ID) const override
static bool classof(const MemRegion *R)
MemSpaceRegion(MemRegionManager *mgr, Kind k=GenericMemSpaceRegionKind)
void dumpToStream(raw_ostream &os) const override
void dumpToStream(raw_ostream &os) const override
bool operator==(const referenced_vars_iterator &I) const
void dumpToStream(raw_ostream &os) const override
static void ProfileRegion(llvm::FoldingSetNodeID &ID, const ObjCStringLiteral *Str, const MemRegion *superRegion)
QualType getValueType() const override
Represent a region's offset within the top level base region.
virtual void printPrettyAsExpr(raw_ostream &os) const
Print the region as expression.
FunctionTextRegion - A region that represents code texts of function.
void Profile(llvm::FoldingSetNodeID &ID) const override
static void ProfileRegion(llvm::FoldingSetNodeID &ID, const Decl *D, const MemRegion *superRegion, Kind k)
bool canPrintPretty() const override
Returns true if this region can be printed in a user-friendly way.
const CXXBaseObjectRegion * getCXXBaseObjectRegion(const CXXRecordDecl *BaseClass, const MemRegion *Super, bool IsVirtual)
const MemRegion * getSuperRegion() const
static bool classof(const MemRegion *R)
void dumpToStream(raw_ostream &os) const override
const StackFrameContext * getStackFrame() const
QualType getValueType() const override
DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const override
getExtent - Returns the size of the region in bytes.
const Expr * getExpr() const
const MemRegion * StripCasts(bool StripBaseCasts=true) const
DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const override
getExtent - Returns the size of the region in bytes.
ID
Defines the set of possible language-specific address spaces.
static bool classof(const MemRegion *R)
const VarRegion * getOriginalRegion(const VarRegion *VR) const
const MemSpaceRegion * getUnknownRegion()
QualType getDesugaredLocationType(ASTContext &Context) const
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression...
const Type * getTypePtrOrNull() const
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
TypedValueRegion(const MemRegion *sReg, Kind k)
virtual bool canPrintPrettyAsExpr() const
Returns true if this region's textual representation can be used as part of a larger expression...
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression...
const VarRegion * getCapturedRegion() const
QualType getDesugaredValueType(ASTContext &Context) const
DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const override
getExtent - Returns the size of the region in bytes.
const ElementRegion * getElementRegion(QualType elementType, NonLoc Idx, const MemRegion *superRegion, ASTContext &Ctx)
bool hasSymbolicOffset() const
void dumpToStream(raw_ostream &os) const override
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
static const int64_t Symbolic
const ElementRegion * getElementRegionWithSuper(const ElementRegion *ER, const MemRegion *superRegion)
llvm::BumpPtrAllocator & getAllocator()
static bool classof(const MemRegion *R)
QualType getDesugaredType(const ASTContext &Context) const
QualType getLocationType() const override
void Profile(llvm::FoldingSetNodeID &ID) const override
StringRegion(const StringLiteral *str, const MemRegion *sreg)
QualType getLocationType() const override
static bool classof(const MemRegion *R)
static bool classof(const MemRegion *R)
static void ProfileRegion(llvm::FoldingSetNodeID &, const BlockTextRegion *, const LocationContext *, unsigned, const MemRegion *)
static void ProfileRegion(llvm::FoldingSetNodeID &ID, const NamedDecl *FD, const MemRegion *)
static bool classof(const MemRegion *R)
TypedRegion(const MemRegion *sReg, Kind k)
The region of the static variables within the current CodeTextRegion scope.
The region for all the non-static global variables.
void dumpToStream(raw_ostream &os) const override
static bool classof(const MemRegion *R)
bool operator!=(const referenced_vars_iterator &I) const
QualType getValueType() const override
static bool classof(const MemRegion *R)
const ObjCStringLiteral * getObjCStringLiteral() const
ASTContext & getContext() const
virtual void dumpToStream(raw_ostream &os) const
bool isBoundable() const override
static bool classof(const MemRegion *R)
const BlockTextRegion * getCodeRegion() const
const FieldDecl * getDecl() const
const CXXTempObjectRegion * getCXXTempObjectRegion(Expr const *Ex, LocationContext const *LC)
bool isSubRegionOf(const MemRegion *R) const override
Check if the region is a subregion of the given region.
void dumpToStream(raw_ostream &os) const override
void dumpToStream(raw_ostream &os) const override
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
const VarRegion * getOriginalRegion() const
bool isBoundable() const override
DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const override
getExtent - Returns the size of the region in bytes.
virtual void printPretty(raw_ostream &os) const
Print the region for use in diagnostics.
const CompoundLiteralRegion * getCompoundLiteralRegion(const CompoundLiteralExpr *CL, const LocationContext *LC)
void Profile(llvm::FoldingSetNodeID &ID) const override
QualType getLocationType() const override
static bool classof(const MemRegion *R)
void dumpToStream(raw_ostream &os) const override
Tells that a region's contents is not changed.
static bool classof(const MemRegion *R)
const CXXThisRegion * getCXXThisRegion(QualType thisPointerTy, const LocationContext *LC)
bool isBoundable() const override
RegionOffset getAsOffset() const
Compute the offset within the top level memory object.
static bool classof(const MemRegion *R)
const SymbolicRegion * getSymbolicHeapRegion(SymbolRef sym)
Return a unique symbolic region belonging to heap memory space.
QualType getValueType() const override
static void ProfileRegion(llvm::FoldingSetNodeID &ID, const Expr *Ex, unsigned Cnt, const MemRegion *superRegion)
QualType getValueType() const override
const VarRegion * getVarRegion(const VarDecl *D, const LocationContext *LC)
InvalidationKinds
Describes different invalidation traits.
const BlockDecl * getDecl() const
static void ProfileRegion(llvm::FoldingSetNodeID &ID, const StringLiteral *Str, const MemRegion *superRegion)
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
bool isBoundable() const override
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
virtual void Profile(llvm::FoldingSetNodeID &ID) const =0
void Profile(llvm::FoldingSetNodeID &ID) const override
const CXXTempObjectRegion * getCXXStaticTempObjectRegion(const Expr *Ex)
void dumpToStream(raw_ostream &os) const override
static bool classof(const MemRegion *R)
virtual MemRegionManager * getMemRegionManager() const =0
void dumpToStream(raw_ostream &os) const override
static bool classof(const MemRegion *R)
bool isBoundable() const override
static bool classof(const MemRegion *R)
The region containing globals which are defined in system/external headers and are considered modifia...
const FieldRegion * getFieldRegionWithSuper(const FieldRegion *FR, const MemRegion *superRegion)
int64_t getOffset() const
StackSpaceRegion(MemRegionManager *mgr, Kind k, const StackFrameContext *sfc)
const CompoundLiteralExpr * getLiteralExpr() const
referenced_vars_iterator & operator++()
static raw_ostream & operator<<(raw_ostream &os, const clang::ento::MemRegion *R)
MemRegionManager * getMemRegionManager() const override
void Profile(llvm::FoldingSetNodeID &ID) const override
void Profile(llvm::FoldingSetNodeID &ID) const override
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression...
void dumpToStream(raw_ostream &os) const
static void ProfileRegion(llvm::FoldingSetNodeID &ID, SymbolRef sym, const MemRegion *superRegion)
Represents a C++ struct/union/class.
void dumpToStream(raw_ostream &os) const override
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
void Profile(llvm::FoldingSetNodeID &ID) const override
QualType getValueType() const override
static bool classof(const MemRegion *R)
static bool classof(const MemRegion *R)
DeclRegion(const Decl *d, const MemRegion *sReg, Kind k)
unsigned kind
All of the diagnostics that can be emitted by the frontend.
void dumpToStream(raw_ostream &os) const override
StringRegion - Region associated with a StringLiteral.
ElementRegin is used to represent both array elements and casts.
QualType getValueType() const override
MemRegionManager(ASTContext &c, llvm::BumpPtrAllocator &a)
static bool classof(const MemRegion *R)
const MemRegion * getRegion() const
virtual bool isSubRegionOf(const MemRegion *R) const
Check if the region is a subregion of the given region.
void dumpToStream(raw_ostream &os) const override
const NamedDecl * getDecl() const
bool hasStackNonParametersStorage() const
static bool classof(const MemRegion *R)
const MemRegion * superRegion
const llvm::APSInt & getValue() const
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
void dumpToStream(raw_ostream &os) const override
static bool classof(const MemRegion *R)
bool isBoundable() const override
void dumpToStream(raw_ostream &os) const override
NonStaticGlobalSpaceRegion(MemRegionManager *mgr, Kind k)
TypedRegion - An abstract class representing regions that are typed.
static bool classof(const MemRegion *R)
void dumpToStream(raw_ostream &os) const override
virtual QualType getLocationType() const =0
void dumpToStream(raw_ostream &os) const override
const BlockDecl * getDecl() const