clang 22.0.0git
|
MemRegion - The root abstract class for all memory regions. More...
#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
Public Types | |
enum | Kind |
Public Member Functions | |
ASTContext & | getContext () const |
virtual void | Profile (llvm::FoldingSetNodeID &ID) const =0 |
virtual MemRegionManager & | getMemRegionManager () const =0 |
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemSpaceRegion * | getRawMemorySpace () const |
Deprecated. | |
template<class MemSpace> | |
const MemSpace * | getRawMemorySpaceAs () const |
Deprecated. Use getMemorySpace(ProgramStateRef) instead. | |
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemSpaceRegion * | getMemorySpace (ProgramStateRef State) const |
Returns the most specific memory space for this memory region in the given ProgramStateRef. | |
template<class MemSpace> | |
const MemSpace * | getMemorySpaceAs (ProgramStateRef State) const |
template<typename... MemorySpaces> | |
bool | hasMemorySpace (ProgramStateRef State) const |
ProgramStateRef | setMemorySpace (ProgramStateRef State, const MemSpaceRegion *Space) const |
Set the dynamically deduced memory space of a MemRegion that currently has UnknownSpaceRegion. | |
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * | getBaseRegion () const |
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * | getMostDerivedObjectRegion () const |
Recursively retrieve the region of the most derived class instance of regions of C++ base class instances. | |
virtual bool | isSubRegionOf (const MemRegion *R) const |
Check if the region is a subregion of the given region. | |
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * | StripCasts (bool StripBaseAndDerivedCasts=true) const |
const SymbolicRegion * | getSymbolicBase () const |
If this is a symbolic region, returns the region. | |
RegionOffset | getAsOffset () const |
Compute the offset within the top level memory object. | |
std::string | getString () const |
Get a string representation of a region for debug use. | |
virtual void | dumpToStream (raw_ostream &os) const |
void | dump () const |
virtual bool | canPrintPretty () const |
Returns true if this region can be printed in a user-friendly way. | |
virtual void | printPretty (raw_ostream &os) const |
Print the region for use in diagnostics. | |
virtual bool | canPrintPrettyAsExpr () const |
Returns true if this region's textual representation can be used as part of a larger expression. | |
virtual void | printPrettyAsExpr (raw_ostream &os) const |
Print the region as expression. | |
Kind | getKind () const |
StringRef | getKindStr () const |
template<typename RegionTy> | |
const RegionTy * | getAs () const |
template<typename RegionTy> | |
LLVM_ATTRIBUTE_RETURNS_NONNULL const RegionTy * | castAs () const |
virtual bool | isBoundable () const |
std::string | getDescriptiveName (bool UseQuotes=true) const |
Get descriptive name for memory region. | |
SourceRange | sourceRange () const |
Retrieve source range from memory region. |
Protected Member Functions | |
MemRegion (Kind k) | |
virtual | ~MemRegion () |
MemRegion - The root abstract class for all memory regions.
Definition at line 98 of file MemRegion.h.
Definition at line 100 of file MemRegion.h.
|
inlineprotected |
Definition at line 113 of file MemRegion.h.
Referenced by clang::ento::MemSpaceRegion::classof(), clang::ento::SubRegion::classof(), getBaseRegion(), getDescriptiveName(), getMemorySpace(), clang::ento::SubRegion::getMemRegionManager(), getMostDerivedObjectRegion(), getRawMemorySpace(), clang::ento::SubRegion::getSuperRegion(), isSubRegionOf(), clang::ento::SubRegion::isSubRegionOf(), clang::ento::MemSpaceRegion::MemSpaceRegion(), setMemorySpace(), StripCasts(), and clang::ento::SubRegion::SubRegion().
|
protectedvirtualdefault |
|
virtual |
Returns true if this region can be printed in a user-friendly way.
Reimplemented in clang::ento::FieldRegion.
Definition at line 634 of file MemRegion.cpp.
References canPrintPrettyAsExpr().
Referenced by checkAndPrettyPrintRegion(), printPretty(), printReferrer(), showBRDefaultDiagnostics(), showBRDiagnostics(), and showBRParamDiagnostics().
|
virtual |
Returns true if this region's textual representation can be used as part of a larger expression.
Reimplemented in clang::ento::CXXBaseObjectRegion, clang::ento::CXXDerivedObjectRegion, clang::ento::FieldRegion, clang::ento::NonParamVarRegion, clang::ento::ObjCIvarRegion, and clang::ento::ParamVarRegion.
Definition at line 638 of file MemRegion.cpp.
Referenced by canPrintPretty(), and getDescriptiveName().
LLVM_ATTRIBUTE_RETURNS_NONNULL const RegionTy * clang::ento::MemRegion::castAs | ( | ) | const |
Definition at line 1424 of file MemRegion.h.
References clang::cast().
LLVM_DUMP_METHOD void MemRegion::dump | ( | ) | const |
Definition at line 474 of file MemRegion.cpp.
References dumpToStream().
|
virtual |
Reimplemented in clang::ento::AllocaRegion, clang::ento::BlockCodeRegion, clang::ento::BlockDataRegion, clang::ento::CodeSpaceRegion, clang::ento::CompoundLiteralRegion, clang::ento::CXXBaseObjectRegion, clang::ento::CXXDerivedObjectRegion, clang::ento::CXXLifetimeExtendedObjectRegion, clang::ento::CXXTempObjectRegion, clang::ento::CXXThisRegion, clang::ento::ElementRegion, clang::ento::FieldRegion, clang::ento::FunctionCodeRegion, clang::ento::GlobalImmutableSpaceRegion, clang::ento::GlobalInternalSpaceRegion, clang::ento::GlobalSystemSpaceRegion, clang::ento::HeapSpaceRegion, clang::ento::NonParamVarRegion, clang::ento::ObjCIvarRegion, clang::ento::ObjCStringRegion, clang::ento::ParamVarRegion, clang::ento::StackArgumentsSpaceRegion, clang::ento::StackLocalsSpaceRegion, clang::ento::StaticGlobalSpaceRegion, clang::ento::StringRegion, clang::ento::SymbolicRegion, and clang::ento::UnknownSpaceRegion.
Definition at line 485 of file MemRegion.cpp.
Referenced by dump(), getString(), and clang::ento::operator<<().
const RegionTy * clang::ento::MemRegion::getAs | ( | ) | const |
Definition at line 1416 of file MemRegion.h.
Referenced by clang::ento::retaincountchecker::RetainCountChecker::checkRegionChanges(), computeOffset(), dereference(), clang::ento::SVal::getAsFunctionDecl(), getConstructedRegion(), getDescriptiveName(), getRegionName(), getStackOrGlobalSpaceRegion(), isInvalidatedSymbolRegion(), parameterTypeFromSVal(), and FindStackRegionsSymbolVisitor::VisitMemRegion().
RegionOffset MemRegion::getAsOffset | ( | ) | const |
Compute the offset within the top level memory object.
Definition at line 1735 of file MemRegion.cpp.
References calculateOffset().
const MemRegion * MemRegion::getBaseRegion | ( | ) | const |
Definition at line 1422 of file MemRegion.cpp.
References clang::cast(), getKind(), and MemRegion().
Referenced by clang::ento::taint::addPartialTaint(), getExistingLazyBinding(), clang::ento::CXXInstanceCall::getExtraInvalidatedValues(), clang::ento::PathSensitiveBugReport::getInterestingnessKind(), getMemorySpace(), getOriginBaseRegion(), getStackOrGlobalSpaceRegion(), clang::ento::SymbolReaper::isLiveRegion(), clang::ento::PathSensitiveBugReport::markInteresting(), clang::ento::SymbolReaper::markLazilyCopied(), clang::ento::SymbolReaper::markLive(), clang::ento::PathSensitiveBugReport::markNotInteresting(), printReferrer(), clang::ento::ExprEngine::ProcessAutomaticObjDtor(), clang::ento::ExprEngine::processPointerEscapedOnBind(), clang::ento::ScanReachableSymbols::scan(), setMemorySpace(), and sourceRange().
|
inline |
Definition at line 1648 of file MemRegion.h.
References clang::ento::MemRegionManager::getContext(), and getMemRegionManager().
Referenced by calculateOffset(), clang::ento::AllocaRegion::dumpToStream(), clang::ento::CompoundLiteralRegion::dumpToStream(), clang::ento::CXXLifetimeExtendedObjectRegion::dumpToStream(), clang::ento::CXXTempObjectRegion::dumpToStream(), clang::ento::ObjCStringRegion::dumpToStream(), clang::ento::StringRegion::dumpToStream(), clang::ento::ElementRegion::getAsArrayOffset(), clang::ento::MemRegionManager::getElementRegionWithSuper(), clang::ento::FunctionCodeRegion::getLocationType(), clang::ento::TypedValueRegion::getLocationType(), clang::ento::CXXBaseObjectRegion::getValueType(), and clang::ento::CXXDerivedObjectRegion::getValueType().
Get descriptive name for memory region.
The name is obtained from the variable/field declaration retrieved from the memory region. Regions that point to an element of an array are returned as: "arr[0]". Regions that point to a struct are returned as: "st.var".
UseQuotes | Set if the name should be quoted. |
Definition at line 727 of file MemRegion.cpp.
References canPrintPrettyAsExpr(), getAs(), clang::ento::SVal::getAs(), getDescriptiveName(), clang::ento::ElementRegion::getIndex(), clang::ento::SubRegion::getSuperRegion(), MemRegion(), and printPrettyAsExpr().
Referenced by getDescriptiveName(), getRegionName(), clang::ento::mpi::MPIBugReporter::reportDoubleNonblocking(), clang::ento::mpi::MPIBugReporter::reportMissingWait(), and clang::ento::mpi::MPIBugReporter::reportUnmatchedWait().
|
inline |
Definition at line 203 of file MemRegion.h.
Referenced by calculateOffset(), clang::ento::StoreManager::castRegion(), clang::ento::AllocaRegion::classof(), clang::ento::BlockCodeRegion::classof(), clang::ento::BlockDataRegion::classof(), clang::ento::CodeSpaceRegion::classof(), clang::ento::CodeTextRegion::classof(), clang::ento::CompoundLiteralRegion::classof(), clang::ento::CXXBaseObjectRegion::classof(), clang::ento::CXXDerivedObjectRegion::classof(), clang::ento::CXXLifetimeExtendedObjectRegion::classof(), clang::ento::CXXTempObjectRegion::classof(), clang::ento::CXXThisRegion::classof(), clang::ento::DeclRegion::classof(), clang::ento::ElementRegion::classof(), clang::ento::FieldRegion::classof(), clang::ento::FunctionCodeRegion::classof(), clang::ento::GlobalImmutableSpaceRegion::classof(), clang::ento::GlobalInternalSpaceRegion::classof(), clang::ento::GlobalsSpaceRegion::classof(), clang::ento::GlobalSystemSpaceRegion::classof(), clang::ento::HeapSpaceRegion::classof(), clang::ento::MemSpaceRegion::classof(), clang::ento::NonParamVarRegion::classof(), clang::ento::NonStaticGlobalSpaceRegion::classof(), clang::ento::ObjCIvarRegion::classof(), clang::ento::ObjCStringRegion::classof(), clang::ento::ParamVarRegion::classof(), clang::ento::StackArgumentsSpaceRegion::classof(), clang::ento::StackLocalsSpaceRegion::classof(), clang::ento::StackSpaceRegion::classof(), clang::ento::StaticGlobalSpaceRegion::classof(), clang::ento::StringRegion::classof(), clang::ento::SubRegion::classof(), clang::ento::SymbolicRegion::classof(), clang::ento::TypedRegion::classof(), clang::ento::TypedValueRegion::classof(), clang::ento::UnknownSpaceRegion::classof(), clang::ento::VarRegion::classof(), getBaseRegion(), getKindStr(), clang::ento::MemSpaceRegion::Profile(), clang::ento::StackSpaceRegion::Profile(), clang::ento::StaticGlobalSpaceRegion::Profile(), StripCasts(), and clang::ento::MemRegionVisitor< ImplClass, RetTy >::Visit().
StringRef MemRegion::getKindStr | ( | ) | const |
Definition at line 642 of file MemRegion.cpp.
References getKind().
|
nodiscard |
Returns the most specific memory space for this memory region in the given ProgramStateRef.
We may infer a more accurate memory space for unknown space regions and associate this in the State.
Definition at line 1397 of file MemRegion.cpp.
References getBaseRegion(), getRawMemorySpace(), clang::isa(), and MemRegion().
Referenced by getMemorySpaceAs(), getStackOrGlobalSpaceRegion(), hasMemorySpace(), and clang::ento::ExprEngine::processPointerEscapedOnBind().
|
inlinenodiscard |
Definition at line 143 of file MemRegion.h.
References getMemorySpace().
Referenced by GetAllocationSite(), and isInitializationOfVar().
|
pure virtual |
Implemented in clang::ento::MemSpaceRegion, and clang::ento::SubRegion.
Referenced by getContext().
const MemRegion * MemRegion::getMostDerivedObjectRegion | ( | ) | const |
Recursively retrieve the region of the most derived class instance of regions of C++ base class instances.
Definition at line 1442 of file MemRegion.cpp.
References MemRegion().
|
nodiscard |
Deprecated.
Gets the 'raw' memory space of a memory region's base region. If the MemRegion is originally associated with Unknown memspace, then the State may have a more accurate memspace for this region. Use getMemorySpace(ProgramStateRef) instead.
Definition at line 1385 of file MemRegion.cpp.
References clang::cast(), and MemRegion().
Referenced by getMemorySpace(), getRawMemorySpaceAs(), clang::ento::CXXLifetimeExtendedObjectRegion::getStackFrame(), clang::ento::CXXTempObjectRegion::getStackFrame(), and clang::ento::VarRegion::getStackFrame().
|
inlinenodiscard |
Deprecated. Use getMemorySpace(ProgramStateRef) instead.
Definition at line 132 of file MemRegion.h.
References getRawMemorySpace().
std::string MemRegion::getString | ( | ) | const |
Get a string representation of a region for debug use.
Definition at line 478 of file MemRegion.cpp.
References dumpToStream(), and s.
Referenced by clang::ento::SValExplainer::VisitStringRegion().
const SymbolicRegion * MemRegion::getSymbolicBase | ( | ) | const |
If this is a symbolic region, returns the region.
Otherwise, goes up the base chain looking for the first symbolic base region. It might return null.
Definition at line 1480 of file MemRegion.cpp.
|
inlinenodiscard |
Definition at line 148 of file MemRegion.h.
References getMemorySpace(), and clang::isa().
Referenced by shouldEscapeRegion(), and clang::ento::SValExplainer::VisitSymbolicRegion().
|
inlinevirtual |
Reimplemented in clang::ento::AllocaRegion, clang::ento::CodeTextRegion, clang::ento::CompoundLiteralRegion, clang::ento::MemSpaceRegion, clang::ento::ObjCStringRegion, clang::ento::StringRegion, clang::ento::SymbolicRegion, and clang::ento::TypedRegion.
Definition at line 211 of file MemRegion.h.
Referenced by clang::ento::StoreManager::castRegion(), clang::ento::ProgramState::getSValAsScalarOrLoc(), and isObjCPointer().
Check if the region is a subregion of the given region.
Each region is a subregion of itself.
Reimplemented in clang::ento::SubRegion.
Definition at line 1449 of file MemRegion.cpp.
References MemRegion().
Referenced by isAnyBaseRegionReported(), and clang::ento::UndefOrNullArgVisitor::VisitNode().
|
virtual |
Print the region for use in diagnostics.
Reimplemented in clang::ento::FieldRegion.
Definition at line 653 of file MemRegion.cpp.
References canPrintPretty(), and printPrettyAsExpr().
Referenced by checkAndPrettyPrintRegion(), printReferrer(), showBRDefaultDiagnostics(), showBRDiagnostics(), and showBRParamDiagnostics().
|
virtual |
Print the region as expression.
When this region represents a subexpression, the method is for printing an expression containing it.
Reimplemented in clang::ento::CXXBaseObjectRegion, clang::ento::CXXDerivedObjectRegion, clang::ento::FieldRegion, clang::ento::NonParamVarRegion, clang::ento::ObjCIvarRegion, and clang::ento::ParamVarRegion.
Definition at line 660 of file MemRegion.cpp.
Referenced by getDescriptiveName(), and printPretty().
|
pure virtual |
Implemented in clang::ento::AllocaRegion, clang::ento::BlockCodeRegion, clang::ento::BlockDataRegion, clang::ento::CompoundLiteralRegion, clang::ento::CXXBaseObjectRegion, clang::ento::CXXDerivedObjectRegion, clang::ento::CXXLifetimeExtendedObjectRegion, clang::ento::CXXTempObjectRegion, clang::ento::CXXThisRegion, clang::ento::ElementRegion, clang::ento::FieldRegion, clang::ento::FunctionCodeRegion, clang::ento::MemSpaceRegion, clang::ento::NonParamVarRegion, clang::ento::ObjCIvarRegion, clang::ento::ObjCStringRegion, clang::ento::ParamVarRegion, clang::ento::StackSpaceRegion, clang::ento::StaticGlobalSpaceRegion, clang::ento::StringRegion, and clang::ento::SymbolicRegion.
|
nodiscard |
Set the dynamically deduced memory space of a MemRegion that currently has UnknownSpaceRegion.
Space
shouldn't be UnknownSpaceRegion.
Definition at line 1408 of file MemRegion.cpp.
References getBaseRegion(), clang::isa(), and MemRegion().
SourceRange MemRegion::sourceRange | ( | ) | const |
Retrieve source range from memory region.
The range retrieval is based on the decl obtained from the memory region. For a VarRegion the range of the base region is returned. For a FieldRegion the range of the field is returned. If no declaration is found, an empty source range is returned. The client is responsible for checking if the returned range is valid.
Definition at line 789 of file MemRegion.cpp.
References getBaseRegion().
Referenced by clang::ento::mpi::MPIBugReporter::reportDoubleNonblocking(), clang::ento::mpi::MPIBugReporter::reportMissingWait(), and clang::ento::mpi::MPIBugReporter::reportUnmatchedWait().
Definition at line 1457 of file MemRegion.cpp.
References clang::cast(), getKind(), and MemRegion().
Referenced by clang::ento::ExprEngine::bindReturnValue(), clang::ento::StoreManager::castRegion(), clang::ento::retaincountchecker::RetainCountChecker::checkRegionChanges(), clang::ento::StoreManager::evalBaseToDerived(), clang::ento::loc::MemRegionVal::stripCasts(), and clang::ento::UndefOrNullArgVisitor::VisitNode().