35 #include "llvm/ADT/APInt.h" 36 #include "llvm/ADT/FoldingSet.h" 37 #include "llvm/ADT/Optional.h" 38 #include "llvm/ADT/PointerUnion.h" 39 #include "llvm/ADT/SmallString.h" 40 #include "llvm/ADT/StringRef.h" 41 #include "llvm/ADT/Twine.h" 42 #include "llvm/Support/Allocator.h" 43 #include "llvm/Support/Casting.h" 44 #include "llvm/Support/CheckedArithmetic.h" 45 #include "llvm/Support/Compiler.h" 46 #include "llvm/Support/Debug.h" 47 #include "llvm/Support/ErrorHandling.h" 48 #include "llvm/Support/raw_ostream.h" 57 using namespace clang;
60 #define DEBUG_TYPE "MemRegion" 66 template <
typename RegionTy,
typename SuperTy,
typename Arg1Ty>
67 RegionTy* MemRegionManager::getSubRegion(
const Arg1Ty arg1,
68 const SuperTy *superRegion) {
69 llvm::FoldingSetNodeID
ID;
70 RegionTy::ProfileRegion(ID, arg1, superRegion);
72 auto *R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, InsertPos));
75 R = A.Allocate<RegionTy>();
76 new (R) RegionTy(arg1, superRegion);
77 Regions.InsertNode(R, InsertPos);
83 template <
typename RegionTy,
typename SuperTy,
typename Arg1Ty,
typename Arg2Ty>
84 RegionTy* MemRegionManager::getSubRegion(
const Arg1Ty arg1,
const Arg2Ty arg2,
85 const SuperTy *superRegion) {
86 llvm::FoldingSetNodeID
ID;
87 RegionTy::ProfileRegion(ID, arg1, arg2, superRegion);
89 auto *R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, InsertPos));
92 R = A.Allocate<RegionTy>();
93 new (R) RegionTy(arg1, arg2, superRegion);
94 Regions.InsertNode(R, InsertPos);
100 template <
typename RegionTy,
typename SuperTy,
101 typename Arg1Ty,
typename Arg2Ty,
typename Arg3Ty>
102 RegionTy* MemRegionManager::getSubRegion(
const Arg1Ty arg1,
const Arg2Ty arg2,
104 const SuperTy *superRegion) {
105 llvm::FoldingSetNodeID
ID;
106 RegionTy::ProfileRegion(ID, arg1, arg2, arg3, superRegion);
108 auto *R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, InsertPos));
111 R = A.Allocate<RegionTy>();
112 new (R) RegionTy(arg1, arg2, arg3, superRegion);
113 Regions.InsertNode(R, InsertPos);
138 if (
const auto *sr = dyn_cast<SubRegion>(r))
139 r = sr->getSuperRegion();
142 }
while (r !=
nullptr);
150 if (
const auto *sr = dyn_cast<SubRegion>(superRegion)) {
169 QualType T = getDesugaredValueType(Ctx);
171 if (isa<VariableArrayType>(T))
183 if (getDecl()->isBitField())
193 if (isa<ConstantArrayType>(T))
209 return svalBuilder.
makeIntVal(getStringLiteral()->getByteLength()+1,
214 :
DeclRegion(ivd, sReg, ObjCIvarRegionKind) {}
217 return cast<ObjCIvarDecl>(D);
221 return getDecl()->getType();
225 return QualType(getDecl()->getTypeForDecl(), 0);
229 return QualType(getDecl()->getTypeForDecl(), 0);
237 ID.AddInteger(static_cast<unsigned>(
getKind()));
241 ID.AddInteger(static_cast<unsigned>(
getKind()));
242 ID.AddPointer(getStackFrame());
246 ID.AddInteger(static_cast<unsigned>(
getKind()));
250 void StringRegion::ProfileRegion(llvm::FoldingSetNodeID &
ID,
253 ID.AddInteger(static_cast<unsigned>(StringRegionKind));
255 ID.AddPointer(superRegion);
258 void ObjCStringRegion::ProfileRegion(llvm::FoldingSetNodeID &
ID,
261 ID.AddInteger(static_cast<unsigned>(ObjCStringRegionKind));
263 ID.AddPointer(superRegion);
266 void AllocaRegion::ProfileRegion(llvm::FoldingSetNodeID&
ID,
267 const Expr *Ex,
unsigned cnt,
269 ID.AddInteger(static_cast<unsigned>(AllocaRegionKind));
272 ID.AddPointer(superRegion);
276 ProfileRegion(ID, Ex, Cnt, superRegion);
280 CompoundLiteralRegion::ProfileRegion(ID, CL, superRegion);
283 void CompoundLiteralRegion::ProfileRegion(llvm::FoldingSetNodeID&
ID,
286 ID.AddInteger(static_cast<unsigned>(CompoundLiteralRegionKind));
288 ID.AddPointer(superRegion);
291 void CXXThisRegion::ProfileRegion(llvm::FoldingSetNodeID &
ID,
294 ID.AddInteger(static_cast<unsigned>(CXXThisRegionKind));
296 ID.AddPointer(sRegion);
300 CXXThisRegion::ProfileRegion(ID, ThisPointerTy, superRegion);
303 void ObjCIvarRegion::ProfileRegion(llvm::FoldingSetNodeID&
ID,
311 ID.AddInteger(static_cast<unsigned>(k));
313 ID.AddPointer(superRegion);
321 VarRegion::ProfileRegion(ID, getDecl(), superRegion);
326 ID.AddInteger(static_cast<unsigned>(MemRegion::SymbolicRegionKind));
335 void ElementRegion::ProfileRegion(llvm::FoldingSetNodeID&
ID,
338 ID.AddInteger(MemRegion::ElementRegionKind);
340 ID.AddPointer(superRegion);
345 ElementRegion::ProfileRegion(ID, ElementType, Index, superRegion);
348 void FunctionCodeRegion::ProfileRegion(llvm::FoldingSetNodeID&
ID,
351 ID.AddInteger(MemRegion::FunctionCodeRegionKind);
356 FunctionCodeRegion::ProfileRegion(ID, FD, superRegion);
359 void BlockCodeRegion::ProfileRegion(llvm::FoldingSetNodeID&
ID,
363 ID.AddInteger(MemRegion::BlockCodeRegionKind);
368 BlockCodeRegion::ProfileRegion(ID, BD, locTy, AC, superRegion);
371 void BlockDataRegion::ProfileRegion(llvm::FoldingSetNodeID&
ID,
376 ID.AddInteger(MemRegion::BlockDataRegionKind);
379 ID.AddInteger(BlkCount);
384 BlockDataRegion::ProfileRegion(ID, BC, LC, BlockCount, getSuperRegion());
387 void CXXTempObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &
ID,
395 ProfileRegion(ID, Ex, getSuperRegion());
398 void CXXBaseObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &
ID,
403 ID.AddBoolean(IsVirtual);
408 ProfileRegion(ID, getDecl(), isVirtual(), superRegion);
411 void CXXDerivedObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &
ID,
419 ProfileRegion(ID, getDecl(), superRegion);
426 void GlobalsSpaceRegion::anchor() {}
428 void NonStaticGlobalSpaceRegion::anchor() {}
430 void StackSpaceRegion::anchor() {}
432 void TypedRegion::anchor() {}
434 void TypedValueRegion::anchor() {}
436 void CodeTextRegion::anchor() {}
438 void SubRegion::anchor() {}
445 dumpToStream(llvm::errs());
450 llvm::raw_string_ostream os(s);
456 os <<
"<Unknown Region>";
464 os <<
"code{" << getDecl()->getDeclName().getAsString() <<
'}';
468 os <<
"block_code{" <<
static_cast<const void *
>(
this) <<
'}';
472 os <<
"block_data{" << BC;
475 I = referenced_vars_begin(),
476 E = referenced_vars_end(); I != E; ++I)
477 os <<
"(" << I.getCapturedRegion() <<
"<-" <<
478 I.getOriginalRegion() <<
") ";
488 os <<
"temp_object{" << getValueType().getAsString() <<
", " 493 os <<
"Base{" << superRegion <<
',' << getDecl()->getName() <<
'}';
497 os <<
"Derived{" << superRegion <<
',' << getDecl()->getName() <<
'}';
505 os <<
"Element{" << superRegion <<
',' 506 << Index <<
',' << getElementType().getAsString() <<
'}';
510 os << superRegion <<
"->" << *getDecl();
514 os <<
"Ivar{" << superRegion <<
',' << *getDecl() <<
'}';
518 assert(Str !=
nullptr &&
"Expecting non-null StringLiteral");
523 assert(Str !=
nullptr &&
"Expecting non-null ObjCStringLiteral");
528 if (isa<HeapSpaceRegion>(getSuperRegion()))
530 os <<
"SymRegion{" << sym <<
'}';
534 const auto *VD = cast<VarDecl>(D);
538 os <<
"VarRegion{D" << VD->getID() <<
'}';
542 dumpToStream(llvm::errs());
546 os <<
"raw_offset{" << getRegion() <<
',' << getOffset().getQuantity() <<
'}';
550 os <<
"CodeSpaceRegion";
554 os <<
"StaticGlobalsMemSpace{" << CR <<
'}';
558 os <<
"GlobalInternalSpaceRegion";
562 os <<
"GlobalSystemSpaceRegion";
566 os <<
"GlobalImmutableSpaceRegion";
570 os <<
"HeapSpaceRegion";
574 os <<
"UnknownSpaceRegion";
578 os <<
"StackArgumentsSpaceRegion";
582 os <<
"StackLocalsSpaceRegion";
586 return canPrintPrettyAsExpr();
594 assert(canPrintPretty() &&
"This region cannot be printed pretty.");
596 printPrettyAsExpr(os);
601 llvm_unreachable(
"This region cannot be printed pretty.");
609 os << getDecl()->getName();
617 os << getDecl()->getName();
629 assert(canPrintPrettyAsExpr());
631 os <<
"." << getDecl()->getName();
635 if (canPrintPrettyAsExpr()) {
637 printPrettyAsExpr(os);
640 os <<
"field " <<
"\'" << getDecl()->getName() <<
"'";
661 std::string VariableName;
662 std::string ArrayIndices;
665 llvm::raw_svector_ostream os(buf);
673 CI->getValue().toString(Idx);
674 ArrayIndices = (llvm::Twine(
"[") + Idx.str() +
"]" + ArrayIndices).
str();
681 ArrayIndices = (llvm::Twine(
"[") + Idx +
"]" + ArrayIndices).
str();
691 return (llvm::Twine(
"'") + os.str() + ArrayIndices +
"'").
str();
693 return (llvm::Twine(os.str()) + ArrayIndices).str();
700 const auto *
const VR = dyn_cast<
VarRegion>(this->getBaseRegion());
701 const auto *
const FR = dyn_cast<
FieldRegion>(
this);
710 return VR->getDecl()->getSourceRange();
721 template <
typename REG>
722 const REG *MemRegionManager::LazyAllocate(REG*& region) {
724 region = A.Allocate<REG>();
725 new (region) REG(
this);
731 template <
typename REG,
typename ARG>
732 const REG *MemRegionManager::LazyAllocate(REG*& region, ARG a) {
734 region = A.Allocate<REG>();
735 new (region) REG(
this, a);
771 if (K == MemRegion::GlobalSystemSpaceRegionKind)
772 return LazyAllocate(SystemGlobals);
773 if (K == MemRegion::GlobalImmutableSpaceRegionKind)
774 return LazyAllocate(ImmutableGlobals);
775 assert(K == MemRegion::GlobalInternalSpaceRegionKind);
776 return LazyAllocate(InternalGlobals);
779 assert(K == MemRegion::StaticGlobalSpaceRegionKind);
790 return LazyAllocate(heap);
794 return LazyAllocate(unknown);
798 return LazyAllocate(code);
806 return getSubRegion<StringRegion>(
812 return getSubRegion<ObjCStringRegion>(
819 static llvm::PointerUnion<const StackFrameContext *, const VarRegion *>
824 if (
const auto *SFC = dyn_cast<StackFrameContext>(LC)) {
825 if (cast<DeclContext>(SFC->getDecl()) == DC)
828 if (
const auto *BC = dyn_cast<BlockInvocationContext>(LC)) {
830 static_cast<const BlockDataRegion *
>(BC->getContextData());
832 for (BlockDataRegion::referenced_vars_iterator
833 I = BR->referenced_vars_begin(),
834 E = BR->referenced_vars_end(); I != E; ++I) {
835 const VarRegion *VR = I.getOriginalRegion();
836 if (VR->getDecl() == VD)
837 return cast<VarRegion>(I.getCapturedRegion());
856 if (D->
getName().find(
"errno") != StringRef::npos)
878 llvm::PointerUnion<const StackFrameContext *, const VarRegion *> V =
892 sReg = isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)
899 if (isa<FunctionDecl>(STCD) || isa<ObjCMethodDecl>(STCD))
902 else if (
const auto *BD = dyn_cast<BlockDecl>(STCD)) {
918 STC->getAnalysisDeclContext());
929 return getSubRegion<VarRegion>(D, sReg);
934 return getSubRegion<VarRegion>(D, superR);
940 unsigned blockCount) {
962 return getSubRegion<BlockDataRegion>(BC, LC, blockCount, sReg);
967 return getSubRegion<CXXTempObjectRegion>(
984 return getSubRegion<CompoundLiteralRegion>(CL, sReg);
993 llvm::FoldingSetNodeID
ID;
994 ElementRegion::ProfileRegion(ID, T, Idx, superRegion);
997 MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
998 auto *R = cast_or_null<ElementRegion>(data);
1003 Regions.InsertNode(R, InsertPos);
1011 return getSubRegion<FunctionCodeRegion>(FD,
getCodeRegion());
1017 return getSubRegion<BlockCodeRegion>(BD, locTy, AC,
getCodeRegion());
1032 return getSubRegion<FieldRegion>(d, superRegion);
1038 return getSubRegion<ObjCIvarRegion>(d, superRegion);
1052 const TypedValueRegion *Super,
1056 const CXXRecordDecl *Class = Super->getValueType()->getAsCXXRecordDecl();
1063 for (
const auto &I : Class->
bases()) {
1064 if (I.getType()->getAsCXXRecordDecl()->getCanonicalDecl() == BaseClass)
1071 const CXXBaseObjectRegion *
1075 if (isa<TypedValueRegion>(Super)) {
1076 assert(
isValidBaseClass(RD, dyn_cast<TypedValueRegion>(Super), IsVirtual));
1082 while (
const auto *
Base = dyn_cast<CXXBaseObjectRegion>(Super))
1083 Super = cast<SubRegion>(
Base->getSuperRegion());
1084 assert(Super && !isa<MemSpaceRegion>(Super));
1088 return getSubRegion<CXXBaseObjectRegion>(RD, IsVirtual, Super);
1094 return getSubRegion<CXXDerivedObjectRegion>(RD, Super);
1108 while (!LC->
inTopFrame() && (!D || D->isStatic() ||
1128 const auto *SR = dyn_cast<
SubRegion>(
this);
1131 R = SR->getSuperRegion();
1139 return isa<StackSpaceRegion>(getMemorySpace());
1143 return isa<StackLocalsSpaceRegion>(getMemorySpace());
1147 return isa<StackArgumentsSpaceRegion>(getMemorySpace());
1152 return isa<StackArgumentsSpaceRegion>(MS) ||
1153 isa<GlobalsSpaceRegion>(MS);
1162 case MemRegion::ElementRegionKind:
1163 case MemRegion::FieldRegionKind:
1164 case MemRegion::ObjCIvarRegionKind:
1165 case MemRegion::CXXBaseObjectRegionKind:
1166 case MemRegion::CXXDerivedObjectRegionKind:
1167 R = cast<SubRegion>(R)->getSuperRegion();
1181 while (
const auto *BR = dyn_cast<CXXBaseObjectRegion>(R))
1182 R = BR->getSuperRegion();
1198 case ElementRegionKind: {
1199 const auto *ER = cast<ElementRegion>(R);
1200 if (!ER->getIndex().isZeroConstant())
1202 R = ER->getSuperRegion();
1205 case CXXBaseObjectRegionKind:
1206 case CXXDerivedObjectRegionKind:
1207 if (!StripBaseAndDerivedCasts)
1209 R = cast<TypedValueRegion>(R)->getSuperRegion();
1218 const auto *SubR = dyn_cast<
SubRegion>(
this);
1221 if (
const auto *SymR = dyn_cast<SymbolicRegion>(SubR))
1223 SubR = dyn_cast<
SubRegion>(SubR->getSuperRegion());
1243 int64_t i = CI->getValue().getSExtValue();
1255 if (
auto NewOffset = llvm::checkedMulAdd(i, size, offset)) {
1256 offset = *NewOffset;
1258 LLVM_DEBUG(llvm::dbgs() <<
"MemRegion::getAsArrayOffset: " 1259 <<
"offset overflowing, returning unknown\n");
1273 assert(superR &&
"super region cannot be NULL");
1280 assert(Child &&
"Child must not be null");
1284 for (
const auto &I : Child->
bases()) {
1285 if (I.getType()->getAsCXXRecordDecl() == Base)
1293 const MemRegion *SymbolicOffsetBase =
nullptr;
1297 switch (R->getKind()) {
1298 case MemRegion::CodeSpaceRegionKind:
1299 case MemRegion::StackLocalsSpaceRegionKind:
1300 case MemRegion::StackArgumentsSpaceRegionKind:
1301 case MemRegion::HeapSpaceRegionKind:
1302 case MemRegion::UnknownSpaceRegionKind:
1303 case MemRegion::StaticGlobalSpaceRegionKind:
1304 case MemRegion::GlobalInternalSpaceRegionKind:
1305 case MemRegion::GlobalSystemSpaceRegionKind:
1306 case MemRegion::GlobalImmutableSpaceRegionKind:
1308 assert(Offset == 0 && !SymbolicOffsetBase);
1311 case MemRegion::FunctionCodeRegionKind:
1312 case MemRegion::BlockCodeRegionKind:
1313 case MemRegion::BlockDataRegionKind:
1317 SymbolicOffsetBase = R;
1320 case MemRegion::SymbolicRegionKind:
1321 case MemRegion::AllocaRegionKind:
1322 case MemRegion::CompoundLiteralRegionKind:
1323 case MemRegion::CXXThisRegionKind:
1324 case MemRegion::StringRegionKind:
1325 case MemRegion::ObjCStringRegionKind:
1326 case MemRegion::VarRegionKind:
1327 case MemRegion::CXXTempObjectRegionKind:
1331 case MemRegion::ObjCIvarRegionKind:
1339 case MemRegion::CXXBaseObjectRegionKind: {
1340 const auto *BOR = cast<CXXBaseObjectRegion>(R);
1341 R = BOR->getSuperRegion();
1344 bool RootIsSymbolic =
false;
1345 if (
const auto *TVR = dyn_cast<TypedValueRegion>(R)) {
1346 Ty = TVR->getDesugaredValueType(R->getContext());
1347 }
else if (
const auto *SR = dyn_cast<SymbolicRegion>(R)) {
1352 RootIsSymbolic =
true;
1358 SymbolicOffsetBase = R;
1360 if (RootIsSymbolic) {
1364 if (BOR->isVirtual()) {
1366 SymbolicOffsetBase = R;
1369 SymbolicOffsetBase = R;
1376 if (SymbolicOffsetBase)
1380 const ASTRecordLayout &Layout = R->getContext().getASTRecordLayout(Child);
1381 if (BOR->isVirtual())
1387 Offset += BaseOffset.
getQuantity() * R->getContext().getCharWidth();
1391 case MemRegion::CXXDerivedObjectRegionKind: {
1396 case MemRegion::ElementRegionKind: {
1397 const auto *ER = cast<ElementRegion>(R);
1398 R = ER->getSuperRegion();
1400 QualType EleTy = ER->getValueType();
1403 SymbolicOffsetBase = R;
1407 SVal Index = ER->getIndex();
1409 Index.getAs<nonloc::ConcreteInt>()) {
1412 if (SymbolicOffsetBase)
1415 int64_t i = CI->getValue().getSExtValue();
1417 Offset += i * R->getContext().getTypeSize(EleTy);
1420 SymbolicOffsetBase = R;
1424 case MemRegion::FieldRegionKind: {
1425 const auto *FR = cast<FieldRegion>(R);
1426 R = FR->getSuperRegion();
1435 SymbolicOffsetBase = R;
1440 if (SymbolicOffsetBase)
1446 FE = RD->
field_end(); FI != FE; ++FI, ++idx) {
1447 if (FR->getDecl() == *FI)
1450 const ASTRecordLayout &Layout = R->getContext().getASTRecordLayout(RD);
1459 if (SymbolicOffsetBase)
1461 return RegionOffset(R, Offset);
1467 return *cachedOffset;
1474 std::pair<const VarRegion *, const VarRegion *>
1475 BlockDataRegion::getCaptureRegions(
const VarDecl *VD) {
1494 return std::make_pair(VR, OriginalVR);
1497 void BlockDataRegion::LazyInitializeReferencedVars() {
1504 std::distance(ReferencedBlockVars.begin(), ReferencedBlockVars.end());
1506 if (NumBlockVars == 0) {
1507 ReferencedVars = (
void*) 0x1;
1517 auto *BV = A.Allocate<VarVec>();
1518 new (BV) VarVec(BC, NumBlockVars);
1519 auto *BVOriginal = A.Allocate<VarVec>();
1520 new (BVOriginal) VarVec(BC, NumBlockVars);
1522 for (
const auto *VD : ReferencedBlockVars) {
1525 std::tie(VR, OriginalVR) = getCaptureRegions(VD);
1528 BV->push_back(VR, BC);
1529 BVOriginal->push_back(OriginalVR, BC);
1532 ReferencedVars = BV;
1533 OriginalVars = BVOriginal;
1542 if (Vec == (
void*) 0x1)
1549 VecOriginal->begin());
1558 if (Vec == (
void*) 0x1)
1565 VecOriginal->end());
1570 E = referenced_vars_end();
1572 if (I.getCapturedRegion() == R)
1573 return I.getOriginalRegion();
1584 SymTraitsMap[Sym] |= IK;
1590 if (
const auto *SR = dyn_cast<SymbolicRegion>(MR))
1591 setTrait(SR->getSymbol(), IK);
1593 MRTraitsMap[MR] |= IK;
1598 const_symbol_iterator I = SymTraitsMap.find(Sym);
1599 if (I != SymTraitsMap.end())
1600 return I->second & IK;
1610 if (
const auto *SR = dyn_cast<SymbolicRegion>(MR))
1611 return hasTrait(SR->getSymbol(), IK);
1613 const_region_iterator I = MRTraitsMap.find(MR);
1614 if (I != MRTraitsMap.end())
1615 return I->second & IK;
Defines the clang::ASTContext interface.
void dumpToStream(raw_ostream &os) const override
nonloc::ConcreteInt makeIntVal(const IntegerLiteral *integer)
CompoundLiteralRegion - A memory region representing a compound literal.
void dumpToStream(raw_ostream &os) const override
const ObjCIvarDecl * getDecl() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getArrayIndexType() const
SymbolManager & getSymbolManager()
A (possibly-)qualified type.
MemRegion - The root abstract class for all memory regions.
bool hasTrait(SymbolRef Sym, InvalidationKinds IK) const
bool hasCaptures() const
True if this block (or its nested blocks) captures anything of local storage from its enclosing scope...
std::string getString() const
Get a string representation of a region for debug use.
bool isArithmeticType() const
FunctionType - C99 6.7.5.3 - Function Declarators.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
C Language Family Type Representation.
Defines the SourceManager interface.
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression...
virtual void dumpToStream(raw_ostream &os) const
BlockCodeRegion - A region that represents code texts of blocks (closures).
Decl - This represents one declaration (or definition), e.g.
void dumpToStream(raw_ostream &os) const override
const StringRegion * getStringRegion(const StringLiteral *Str)
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
const GlobalsSpaceRegion * getGlobalsRegion(MemRegion::Kind K=MemRegion::GlobalInternalSpaceRegionKind, const CodeTextRegion *R=nullptr)
getGlobalsRegion - Retrieve the memory region associated with global variables.
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
The base class of the type hierarchy.
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
MemSpaceRegion - A memory region that represents a "memory space"; for example, the set of global var...
A container of type source information.
Value representing integer constant.
const ObjCIvarRegion * getObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *superRegion)
getObjCIvarRegion - Retrieve or create the memory region associated with a specified Objective-c inst...
float __ovld __cnfn distance(float p0, float p1)
Returns the distance between p0 and p1.
AllocaRegion - A region that represents an untyped blob of bytes created by a call to 'alloca'...
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
CodeSpaceRegion - The memory space that holds the executable code of functions and blocks...
const StackArgumentsSpaceRegion * getStackArgumentsRegion(const StackFrameContext *STC)
getStackArgumentsRegion - Retrieve the memory region associated with function/method arguments of the...
ASTContext & getContext()
Represents a variable declaration or definition.
void printPretty(raw_ostream &os) const override
Print the region for use in diagnostics.
CompoundLiteralExpr - [C99 6.5.2.5].
void Profile(llvm::FoldingSetNodeID &ID) const override
const T * getAs() const
Member-template getAs<specific type>'.
void setTrait(SymbolRef Sym, InvalidationKinds IK)
QualType getElementType() const
void Profile(llvm::FoldingSetNodeID &ID) const override
const ObjCStringRegion * getObjCStringRegion(const ObjCStringLiteral *Str)
static bool isValidBaseClass(const CXXRecordDecl *BaseClass, const TypedValueRegion *Super, bool IsVirtual)
Checks whether BaseClass is a valid virtual or direct non-virtual base class of the type of Super...
Describes how types, statements, expressions, and declarations should be printed. ...
QualType getValueType() const override
CXXThisRegion - Represents the region for the implicit 'this' parameter in a call to a C++ method...
const MemRegion * getSuperRegion() const
Represents a struct/union/class.
const SymbolicRegion * getSymbolicBase() const
If this is a symbolic region, returns the region.
One of these records is kept for each identifier that is lexed.
DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const override
getExtent - Returns the size of the region in bytes.
const HeapSpaceRegion * getHeapRegion()
getHeapRegion - Retrieve the memory region associated with the generic "heap".
The region associated with an ObjCStringLiteral.
void dumpToStream(raw_ostream &os) const
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 FieldDecl * getDecl() const
Represents a member of a struct/union/class.
AnalysisDeclContext contains the context data for the function or method under analysis.
const StackLocalsSpaceRegion * getStackLocalsRegion(const StackFrameContext *STC)
getStackLocalsRegion - Retrieve the memory region associated with the specified stack frame...
void Profile(llvm::FoldingSetNodeID &ID) const override
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
CharUnits getVBaseClassOffset(const CXXRecordDecl *VBase) const
getVBaseClassOffset - Get the offset, in chars, for the given base class.
TypeSourceInfo * getSignatureAsWritten() const
const SymbolicRegion * getSymbolicRegion(SymbolRef Sym)
Retrieve or create a "symbolic" memory region.
void Profile(llvm::FoldingSetNodeID &ID) const override
BlockDataRegion - A region that represents a block instance.
const AllocaRegion * getAllocaRegion(const Expr *Ex, unsigned Cnt, const LocationContext *LC)
getAllocaRegion - Retrieve a region associated with a call to alloca().
const UnknownSpaceRegion * getUnknownRegion()
getUnknownRegion - Retrieve the memory region associated with unknown memory space.
CharUnits - This is an opaque type for sizes expressed in character units.
void dumpToStream(raw_ostream &os) const override
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
QualType getValueType() const override
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression...
virtual bool inTopFrame() const
Return true if the current LocationContext has no caller context.
const LocationContext * getParent() const
bool hasStackParametersStorage() const
void Profile(llvm::FoldingSetNodeID &ID) const override
void Profile(llvm::FoldingSetNodeID &ID) const override
void dumpToStream(raw_ostream &os) const override
ObjCStringLiteral, used for Objective-C string literals i.e.
void Profile(llvm::FoldingSetNodeID &ID) const override
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
field_iterator field_begin() const
void dumpToStream(raw_ostream &os) const override
void dumpToStream(raw_ostream &os) const override
referenced_vars_iterator referenced_vars_end() const
void dumpToStream(raw_ostream &os) const override
Represent a region's offset within the top level base region.
const MemSpaceRegion * getMemorySpace() const
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 BlockCodeRegion * getBlockCodeRegion(const BlockDecl *BD, CanQualType locTy, AnalysisDeclContext *AC)
void dumpToStream(raw_ostream &os) const override
const CodeSpaceRegion * getCodeRegion()
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const override
getExtent - Returns the size of the region in bytes.
SourceRange sourceRange() const
Retrieve source range from memory region.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const override
getExtent - Returns the size of the region in bytes.
const RegionTy * getAs() const
SymbolicRegion - A special, "non-concrete" region.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression...
Pepresents a block literal declaration, which is like an unnamed FunctionDecl.
This represents one expression.
void Profile(llvm::FoldingSetNodeID &ID) const override
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression...
DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const override
getExtent - Returns the size of the region in bytes.
void dumpToStream(raw_ostream &os) const override
field_iterator field_end() const
static const int64_t Symbolic
DeclContext * getDeclContext()
llvm::BumpPtrAllocator & getAllocator()
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
void Profile(llvm::FoldingSetNodeID &ID) const override
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const StackFrameContext * getStackFrame() const
The region of the static variables within the current CodeTextRegion scope.
const VarDecl * getDecl() const
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
bool isConstQualified() const
Determine whether this type is const-qualified.
void dumpToStream(raw_ostream &os) const override
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
void Profile(llvm::FoldingSetNodeID &ID) const
const BlockDecl * getDecl() const
const MemRegion * getMostDerivedObjectRegion() const
Recursively retrieve the region of the most derived class instance of regions of C++ base class insta...
FunctionCodeRegion - A region that represents code texts of function.
virtual bool canPrintPretty() const
Returns true if this region can be printed in a user-friendly way.
static bool isImmediateBase(const CXXRecordDecl *Child, const CXXRecordDecl *Base)
Returns true if Base is an immediate base class of Child.
void dumpToStream(raw_ostream &os) const override
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
Represents a static or instance method of a struct/union/class.
ASTContext & getContext()
void dumpToStream(raw_ostream &os) const override
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
int64_t getID(const ASTContext &Context) const
void dumpToStream(raw_ostream &os) const override
const StackFrameContext * getStackFrame() const
const CXXDerivedObjectRegion * getCXXDerivedObjectRegion(const CXXRecordDecl *BaseClass, const SubRegion *Super)
Create a CXXDerivedObjectRegion with the given derived class for region Super.
DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const override
getExtent - Returns the size of the region in bytes.
virtual void printPrettyAsExpr(raw_ostream &os) const
Print the region as expression.
const CompoundLiteralRegion * getCompoundLiteralRegion(const CompoundLiteralExpr *CL, const LocationContext *LC)
getCompoundLiteralRegion - Retrieve the region associated with a given CompoundLiteral.
void Profile(llvm::FoldingSetNodeID &ID) const override
referenced_vars_iterator referenced_vars_begin() const
void dumpToStream(raw_ostream &os) const override
std::string getDescriptiveName(bool UseQuotes=true) const
Get descriptive name for memory region.
const CXXThisRegion * getCXXThisRegion(QualType thisPointerTy, const LocationContext *LC)
getCXXThisRegion - Retrieve the [artificial] region associated with the parameter 'this'...
RegionRawOffset getAsArrayOffset() const
Compute the offset within the array. The array might also be a subobject.
virtual void printPretty(raw_ostream &os) const
Print the region for use in diagnostics.
const CXXBaseObjectRegion * getCXXBaseObjectRegion(const CXXRecordDecl *BaseClass, const SubRegion *Super, bool IsVirtual)
Create a CXXBaseObjectRegion with the given base class for region Super.
bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is virtually derived from the class Base.
const SymbolicRegion * getSymbolicHeapRegion(SymbolRef sym)
Return a unique symbolic region belonging to heap memory space.
Dataflow Directional Tag Classes.
QualType getValueType() const override
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool isZeroConstant() const
llvm::iterator_range< referenced_decls_iterator > getReferencedBlockVars(const BlockDecl *BD)
const VarRegion * getVarRegion(const VarDecl *D, const LocationContext *LC)
getVarRegion - Retrieve or create the memory region associated with a specified VarDecl and LocationC...
InvalidationKinds
Describes different invalidation traits.
const ElementRegion * getElementRegion(QualType elementType, NonLoc Idx, const SubRegion *superRegion, ASTContext &Ctx)
getElementRegion - Retrieve the memory region associated with the associated element type...
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
const MemRegion * StripCasts(bool StripBaseAndDerivedCasts=true) const
Represents symbolic expression that isn't a location.
const VarRegion * getOriginalRegion(const VarRegion *VR) const
Return the original region for a captured region, if one exists.
void Profile(llvm::FoldingSetNodeID &ID) const override
static llvm::PointerUnion< const StackFrameContext *, const VarRegion * > getStackOrCaptureRegionForDeclContext(const LocationContext *LC, const DeclContext *DC, const VarDecl *VD)
Look through a chain of LocationContexts to either find the StackFrameContext that matches a DeclCont...
void dumpToStream(raw_ostream &os) const override
const FunctionCodeRegion * getFunctionCodeRegion(const NamedDecl *FD)
virtual bool canPrintPrettyAsExpr() const
Returns true if this region's textual representation can be used as part of a larger expression...
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
const Decl * getDecl() const
const CXXTempObjectRegion * getCXXStaticTempObjectRegion(const Expr *Ex)
Create a CXXTempObjectRegion for temporaries which are lifetime-extended by static references...
void dumpToStream(raw_ostream &os) const override
virtual MemRegionManager * getMemRegionManager() const =0
void dumpToStream(raw_ostream &os) const override
SubRegion - A region that subsets another larger region.
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
RegionOffset getAsOffset() const
Compute the offset within the top level memory object.
bool hasStackStorage() const
const StackFrameContext * getStackFrame() const
void Profile(llvm::FoldingSetNodeID &ID) const override
const Type * getTypePtrOrNull() const
SourceManager & getSourceManager()
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
const BlockDataRegion * getBlockDataRegion(const BlockCodeRegion *bc, const LocationContext *lc, unsigned blockCount)
getBlockDataRegion - Get the memory region associated with an instance of a block.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
MemRegionManager * getMemRegionManager() const override
void Profile(llvm::FoldingSetNodeID &ID) const override
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression...
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\, const ASTContext *Context=nullptr) const
const SymbolExtent * getExtentSymbol(const SubRegion *R)
static void ProfileRegion(llvm::FoldingSetNodeID &ID, SymbolRef sym, const MemRegion *superRegion)
Represents a C++ struct/union/class.
void dumpToStream(raw_ostream &os) const override
static RegionOffset calculateOffset(const MemRegion *R)
virtual bool isSubRegionOf(const MemRegion *R) const
Check if the region is a subregion of the given region.
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
ObjCIvarDecl - Represents an ObjC instance variable.
const MemRegion * getBaseRegion() const
StringLiteral - This represents a string literal expression, e.g.
void dumpToStream(raw_ostream &os) const override
StringRegion - Region associated with a StringLiteral.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
void Profile(llvm::FoldingSetNodeID &ID) const override
ElementRegion is used to represent both array elements and casts.
static Decl::Kind getKind(const Decl *D)
void dumpToStream(raw_ostream &os) const override
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
bool hasStackNonParametersStorage() const
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
bool hasGlobalsOrParametersStorage() const
void dumpToStream(raw_ostream &os) const override
const FieldRegion * getFieldRegion(const FieldDecl *fd, const SubRegion *superRegion)
getFieldRegion - Retrieve or create the memory region associated with a specified FieldDecl...
void dumpToStream(raw_ostream &os) const override
SourceLocation getLocation() const
void dumpToStream(raw_ostream &os) const override