34 #include "llvm/ADT/APInt.h" 35 #include "llvm/ADT/FoldingSet.h" 36 #include "llvm/ADT/Optional.h" 37 #include "llvm/ADT/PointerUnion.h" 38 #include "llvm/ADT/SmallString.h" 39 #include "llvm/ADT/StringRef.h" 40 #include "llvm/ADT/Twine.h" 41 #include "llvm/Support/Allocator.h" 42 #include "llvm/Support/Casting.h" 43 #include "llvm/Support/CheckedArithmetic.h" 44 #include "llvm/Support/Compiler.h" 45 #include "llvm/Support/Debug.h" 46 #include "llvm/Support/ErrorHandling.h" 47 #include "llvm/Support/raw_ostream.h" 56 using namespace clang;
59 #define DEBUG_TYPE "MemRegion" 65 template <
typename RegionTy,
typename SuperTy,
typename Arg1Ty>
66 RegionTy* MemRegionManager::getSubRegion(
const Arg1Ty arg1,
67 const SuperTy *superRegion) {
68 llvm::FoldingSetNodeID
ID;
69 RegionTy::ProfileRegion(ID, arg1, superRegion);
71 auto *R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, InsertPos));
74 R = A.Allocate<RegionTy>();
75 new (R) RegionTy(arg1, superRegion);
76 Regions.InsertNode(R, InsertPos);
82 template <
typename RegionTy,
typename SuperTy,
typename Arg1Ty,
typename Arg2Ty>
83 RegionTy* MemRegionManager::getSubRegion(
const Arg1Ty arg1,
const Arg2Ty arg2,
84 const SuperTy *superRegion) {
85 llvm::FoldingSetNodeID
ID;
86 RegionTy::ProfileRegion(ID, arg1, arg2, superRegion);
88 auto *R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, InsertPos));
91 R = A.Allocate<RegionTy>();
92 new (R) RegionTy(arg1, arg2, superRegion);
93 Regions.InsertNode(R, InsertPos);
99 template <
typename RegionTy,
typename SuperTy,
100 typename Arg1Ty,
typename Arg2Ty,
typename Arg3Ty>
101 RegionTy* MemRegionManager::getSubRegion(
const Arg1Ty arg1,
const Arg2Ty arg2,
103 const SuperTy *superRegion) {
104 llvm::FoldingSetNodeID
ID;
105 RegionTy::ProfileRegion(ID, arg1, arg2, arg3, superRegion);
107 auto *R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, InsertPos));
110 R = A.Allocate<RegionTy>();
111 new (R) RegionTy(arg1, arg2, arg3, superRegion);
112 Regions.InsertNode(R, InsertPos);
137 if (
const auto *sr = dyn_cast<SubRegion>(r))
138 r = sr->getSuperRegion();
141 }
while (r !=
nullptr);
149 if (
const auto *sr = dyn_cast<SubRegion>(superRegion)) {
168 QualType T = getDesugaredValueType(Ctx);
170 if (isa<VariableArrayType>(T))
182 if (getDecl()->isBitField())
192 if (isa<ConstantArrayType>(T))
208 return svalBuilder.
makeIntVal(getStringLiteral()->getByteLength()+1,
213 :
DeclRegion(ivd, sReg, ObjCIvarRegionKind) {}
216 return cast<ObjCIvarDecl>(D);
220 return getDecl()->getType();
224 return QualType(getDecl()->getTypeForDecl(), 0);
228 return QualType(getDecl()->getTypeForDecl(), 0);
236 ID.AddInteger(static_cast<unsigned>(
getKind()));
240 ID.AddInteger(static_cast<unsigned>(
getKind()));
241 ID.AddPointer(getStackFrame());
245 ID.AddInteger(static_cast<unsigned>(
getKind()));
249 void StringRegion::ProfileRegion(llvm::FoldingSetNodeID &
ID,
252 ID.AddInteger(static_cast<unsigned>(StringRegionKind));
254 ID.AddPointer(superRegion);
257 void ObjCStringRegion::ProfileRegion(llvm::FoldingSetNodeID &
ID,
260 ID.AddInteger(static_cast<unsigned>(ObjCStringRegionKind));
262 ID.AddPointer(superRegion);
265 void AllocaRegion::ProfileRegion(llvm::FoldingSetNodeID&
ID,
266 const Expr *Ex,
unsigned cnt,
268 ID.AddInteger(static_cast<unsigned>(AllocaRegionKind));
271 ID.AddPointer(superRegion);
275 ProfileRegion(ID, Ex, Cnt, superRegion);
279 CompoundLiteralRegion::ProfileRegion(ID, CL, superRegion);
282 void CompoundLiteralRegion::ProfileRegion(llvm::FoldingSetNodeID&
ID,
285 ID.AddInteger(static_cast<unsigned>(CompoundLiteralRegionKind));
287 ID.AddPointer(superRegion);
290 void CXXThisRegion::ProfileRegion(llvm::FoldingSetNodeID &
ID,
293 ID.AddInteger(static_cast<unsigned>(CXXThisRegionKind));
295 ID.AddPointer(sRegion);
299 CXXThisRegion::ProfileRegion(ID, ThisPointerTy, superRegion);
302 void ObjCIvarRegion::ProfileRegion(llvm::FoldingSetNodeID&
ID,
310 ID.AddInteger(static_cast<unsigned>(k));
312 ID.AddPointer(superRegion);
320 VarRegion::ProfileRegion(ID, getDecl(), superRegion);
325 ID.AddInteger(static_cast<unsigned>(MemRegion::SymbolicRegionKind));
334 void ElementRegion::ProfileRegion(llvm::FoldingSetNodeID&
ID,
337 ID.AddInteger(MemRegion::ElementRegionKind);
339 ID.AddPointer(superRegion);
344 ElementRegion::ProfileRegion(ID, ElementType, Index, superRegion);
347 void FunctionCodeRegion::ProfileRegion(llvm::FoldingSetNodeID&
ID,
350 ID.AddInteger(MemRegion::FunctionCodeRegionKind);
355 FunctionCodeRegion::ProfileRegion(ID, FD, superRegion);
358 void BlockCodeRegion::ProfileRegion(llvm::FoldingSetNodeID&
ID,
362 ID.AddInteger(MemRegion::BlockCodeRegionKind);
367 BlockCodeRegion::ProfileRegion(ID, BD, locTy, AC, superRegion);
370 void BlockDataRegion::ProfileRegion(llvm::FoldingSetNodeID&
ID,
375 ID.AddInteger(MemRegion::BlockDataRegionKind);
378 ID.AddInteger(BlkCount);
383 BlockDataRegion::ProfileRegion(ID, BC, LC, BlockCount, getSuperRegion());
386 void CXXTempObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &
ID,
394 ProfileRegion(ID, Ex, getSuperRegion());
397 void CXXBaseObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &
ID,
402 ID.AddBoolean(IsVirtual);
407 ProfileRegion(ID, getDecl(), isVirtual(), superRegion);
410 void CXXDerivedObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &
ID,
418 ProfileRegion(ID, getDecl(), superRegion);
425 void GlobalsSpaceRegion::anchor() {}
427 void NonStaticGlobalSpaceRegion::anchor() {}
429 void StackSpaceRegion::anchor() {}
431 void TypedRegion::anchor() {}
433 void TypedValueRegion::anchor() {}
435 void CodeTextRegion::anchor() {}
437 void SubRegion::anchor() {}
444 dumpToStream(llvm::errs());
449 llvm::raw_string_ostream os(s);
455 os <<
"<Unknown Region>";
463 os <<
"code{" << getDecl()->getDeclName().getAsString() <<
'}';
467 os <<
"block_code{" <<
static_cast<const void *
>(
this) <<
'}';
471 os <<
"block_data{" << BC;
474 I = referenced_vars_begin(),
475 E = referenced_vars_end(); I != E; ++I)
476 os <<
"(" << I.getCapturedRegion() <<
"<-" <<
477 I.getOriginalRegion() <<
") ";
487 os <<
"temp_object{" << getValueType().getAsString() <<
", " 492 os <<
"Base{" << superRegion <<
',' << getDecl()->getName() <<
'}';
496 os <<
"Derived{" << superRegion <<
',' << getDecl()->getName() <<
'}';
504 os <<
"Element{" << superRegion <<
',' 505 << Index <<
',' << getElementType().getAsString() <<
'}';
509 os << superRegion <<
"->" << *getDecl();
513 os <<
"Ivar{" << superRegion <<
',' << *getDecl() <<
'}';
517 assert(Str !=
nullptr &&
"Expecting non-null StringLiteral");
522 assert(Str !=
nullptr &&
"Expecting non-null ObjCStringLiteral");
527 if (isa<HeapSpaceRegion>(getSuperRegion()))
529 os <<
"SymRegion{" << sym <<
'}';
533 const auto *VD = cast<VarDecl>(D);
537 os <<
"VarRegion{D" << VD->getID() <<
'}';
541 dumpToStream(llvm::errs());
545 os <<
"raw_offset{" << getRegion() <<
',' << getOffset().getQuantity() <<
'}';
549 os <<
"CodeSpaceRegion";
553 os <<
"StaticGlobalsMemSpace{" << CR <<
'}';
557 os <<
"GlobalInternalSpaceRegion";
561 os <<
"GlobalSystemSpaceRegion";
565 os <<
"GlobalImmutableSpaceRegion";
569 os <<
"HeapSpaceRegion";
573 os <<
"UnknownSpaceRegion";
577 os <<
"StackArgumentsSpaceRegion";
581 os <<
"StackLocalsSpaceRegion";
585 return canPrintPrettyAsExpr();
593 assert(canPrintPretty() &&
"This region cannot be printed pretty.");
595 printPrettyAsExpr(os);
600 llvm_unreachable(
"This region cannot be printed pretty.");
608 os << getDecl()->getName();
616 os << getDecl()->getName();
628 assert(canPrintPrettyAsExpr());
630 os <<
"." << getDecl()->getName();
634 if (canPrintPrettyAsExpr()) {
636 printPrettyAsExpr(os);
639 os <<
"field " <<
"\'" << getDecl()->getName() <<
"'";
660 std::string VariableName;
661 std::string ArrayIndices;
664 llvm::raw_svector_ostream os(buf);
672 CI->getValue().toString(Idx);
673 ArrayIndices = (llvm::Twine(
"[") + Idx.str() +
"]" + ArrayIndices).str();
680 ArrayIndices = (llvm::Twine(
"[") + Idx +
"]" + ArrayIndices).str();
690 return (llvm::Twine(
"'") + os.str() + ArrayIndices +
"'").str();
692 return (llvm::Twine(os.str()) + ArrayIndices).str();
699 const auto *
const VR = dyn_cast<
VarRegion>(this->getBaseRegion());
700 const auto *
const FR = dyn_cast<
FieldRegion>(
this);
709 return VR->getDecl()->getSourceRange();
720 template <
typename REG>
721 const REG *MemRegionManager::LazyAllocate(REG*& region) {
723 region = A.Allocate<REG>();
724 new (region) REG(
this);
730 template <
typename REG,
typename ARG>
731 const REG *MemRegionManager::LazyAllocate(REG*& region, ARG
a) {
733 region = A.Allocate<REG>();
734 new (region) REG(
this, a);
770 if (K == MemRegion::GlobalSystemSpaceRegionKind)
771 return LazyAllocate(SystemGlobals);
772 if (K == MemRegion::GlobalImmutableSpaceRegionKind)
773 return LazyAllocate(ImmutableGlobals);
774 assert(K == MemRegion::GlobalInternalSpaceRegionKind);
775 return LazyAllocate(InternalGlobals);
778 assert(K == MemRegion::StaticGlobalSpaceRegionKind);
789 return LazyAllocate(heap);
793 return LazyAllocate(unknown);
797 return LazyAllocate(code);
805 return getSubRegion<StringRegion>(
811 return getSubRegion<ObjCStringRegion>(
818 static llvm::PointerUnion<const StackFrameContext *, const VarRegion *>
823 if (
const auto *SFC = dyn_cast<StackFrameContext>(LC)) {
824 if (cast<DeclContext>(SFC->getDecl()) == DC)
827 if (
const auto *BC = dyn_cast<BlockInvocationContext>(LC)) {
829 static_cast<const BlockDataRegion *
>(BC->getContextData());
831 for (BlockDataRegion::referenced_vars_iterator
832 I = BR->referenced_vars_begin(),
833 E = BR->referenced_vars_end(); I != E; ++I) {
834 const VarRegion *VR = I.getOriginalRegion();
835 if (VR->getDecl() == VD)
836 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);
935 return getSubRegion<VarRegion>(D, superR);
941 unsigned blockCount) {
963 return getSubRegion<BlockDataRegion>(BC, LC, blockCount, sReg);
968 return getSubRegion<CXXTempObjectRegion>(
985 return getSubRegion<CompoundLiteralRegion>(CL, sReg);
994 llvm::FoldingSetNodeID
ID;
995 ElementRegion::ProfileRegion(ID, T, Idx, superRegion);
998 MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
999 auto *R = cast_or_null<ElementRegion>(data);
1004 Regions.InsertNode(R, InsertPos);
1013 return getSubRegion<FunctionCodeRegion>(FD,
getCodeRegion());
1019 return getSubRegion<BlockCodeRegion>(BD, locTy, AC,
getCodeRegion());
1034 return getSubRegion<FieldRegion>(
d, superRegion);
1040 return getSubRegion<ObjCIvarRegion>(
d, superRegion);
1054 const TypedValueRegion *Super,
1058 const CXXRecordDecl *Class = Super->getValueType()->getAsCXXRecordDecl();
1065 for (
const auto &I : Class->
bases()) {
1066 if (I.getType()->getAsCXXRecordDecl()->getCanonicalDecl() == BaseClass)
1073 const CXXBaseObjectRegion *
1077 if (isa<TypedValueRegion>(Super)) {
1078 assert(
isValidBaseClass(RD, dyn_cast<TypedValueRegion>(Super), IsVirtual));
1084 while (
const auto *
Base = dyn_cast<CXXBaseObjectRegion>(Super))
1085 Super = cast<SubRegion>(
Base->getSuperRegion());
1086 assert(Super && !isa<MemSpaceRegion>(Super));
1090 return getSubRegion<CXXBaseObjectRegion>(RD, IsVirtual, Super);
1096 return getSubRegion<CXXDerivedObjectRegion>(RD, Super);
1110 while (!LC->
inTopFrame() && (!D || D->isStatic() ||
1130 const auto *SR = dyn_cast<
SubRegion>(
this);
1133 R = SR->getSuperRegion();
1141 return isa<StackSpaceRegion>(getMemorySpace());
1145 return isa<StackLocalsSpaceRegion>(getMemorySpace());
1149 return isa<StackArgumentsSpaceRegion>(getMemorySpace());
1154 return isa<StackArgumentsSpaceRegion>(MS) ||
1155 isa<GlobalsSpaceRegion>(MS);
1164 case MemRegion::ElementRegionKind:
1165 case MemRegion::FieldRegionKind:
1166 case MemRegion::ObjCIvarRegionKind:
1167 case MemRegion::CXXBaseObjectRegionKind:
1168 case MemRegion::CXXDerivedObjectRegionKind:
1169 R = cast<SubRegion>(R)->getSuperRegion();
1183 while (
const auto *BR = dyn_cast<CXXBaseObjectRegion>(R))
1184 R = BR->getSuperRegion();
1200 case ElementRegionKind: {
1201 const auto *ER = cast<ElementRegion>(R);
1202 if (!ER->getIndex().isZeroConstant())
1204 R = ER->getSuperRegion();
1207 case CXXBaseObjectRegionKind:
1208 case CXXDerivedObjectRegionKind:
1209 if (!StripBaseAndDerivedCasts)
1211 R = cast<TypedValueRegion>(R)->getSuperRegion();
1220 const auto *SubR = dyn_cast<
SubRegion>(
this);
1223 if (
const auto *SymR = dyn_cast<SymbolicRegion>(SubR))
1225 SubR = dyn_cast<
SubRegion>(SubR->getSuperRegion());
1245 int64_t
i = CI->getValue().getSExtValue();
1257 if (
auto NewOffset = llvm::checkedMulAdd(i, size, offset)) {
1258 offset = *NewOffset;
1260 LLVM_DEBUG(llvm::dbgs() <<
"MemRegion::getAsArrayOffset: " 1261 <<
"offset overflowing, returning unknown\n");
1275 assert(superR &&
"super region cannot be NULL");
1282 assert(Child &&
"Child must not be null");
1286 for (
const auto &I : Child->
bases()) {
1287 if (I.getType()->getAsCXXRecordDecl() == Base)
1295 const MemRegion *SymbolicOffsetBase =
nullptr;
1299 switch (R->getKind()) {
1300 case MemRegion::CodeSpaceRegionKind:
1301 case MemRegion::StackLocalsSpaceRegionKind:
1302 case MemRegion::StackArgumentsSpaceRegionKind:
1303 case MemRegion::HeapSpaceRegionKind:
1304 case MemRegion::UnknownSpaceRegionKind:
1305 case MemRegion::StaticGlobalSpaceRegionKind:
1306 case MemRegion::GlobalInternalSpaceRegionKind:
1307 case MemRegion::GlobalSystemSpaceRegionKind:
1308 case MemRegion::GlobalImmutableSpaceRegionKind:
1310 assert(Offset == 0 && !SymbolicOffsetBase);
1313 case MemRegion::FunctionCodeRegionKind:
1314 case MemRegion::BlockCodeRegionKind:
1315 case MemRegion::BlockDataRegionKind:
1319 SymbolicOffsetBase = R;
1322 case MemRegion::SymbolicRegionKind:
1323 case MemRegion::AllocaRegionKind:
1324 case MemRegion::CompoundLiteralRegionKind:
1325 case MemRegion::CXXThisRegionKind:
1326 case MemRegion::StringRegionKind:
1327 case MemRegion::ObjCStringRegionKind:
1328 case MemRegion::VarRegionKind:
1329 case MemRegion::CXXTempObjectRegionKind:
1333 case MemRegion::ObjCIvarRegionKind:
1341 case MemRegion::CXXBaseObjectRegionKind: {
1342 const auto *BOR = cast<CXXBaseObjectRegion>(R);
1343 R = BOR->getSuperRegion();
1346 bool RootIsSymbolic =
false;
1347 if (
const auto *TVR = dyn_cast<TypedValueRegion>(R)) {
1348 Ty = TVR->getDesugaredValueType(R->getContext());
1349 }
else if (
const auto *SR = dyn_cast<SymbolicRegion>(R)) {
1354 RootIsSymbolic =
true;
1360 SymbolicOffsetBase = R;
1362 if (RootIsSymbolic) {
1366 if (BOR->isVirtual()) {
1368 SymbolicOffsetBase = R;
1371 SymbolicOffsetBase = R;
1378 if (SymbolicOffsetBase)
1382 const ASTRecordLayout &Layout = R->getContext().getASTRecordLayout(Child);
1383 if (BOR->isVirtual())
1389 Offset += BaseOffset.
getQuantity() * R->getContext().getCharWidth();
1393 case MemRegion::CXXDerivedObjectRegionKind: {
1398 case MemRegion::ElementRegionKind: {
1399 const auto *ER = cast<ElementRegion>(R);
1400 R = ER->getSuperRegion();
1402 QualType EleTy = ER->getValueType();
1405 SymbolicOffsetBase = R;
1409 SVal Index = ER->getIndex();
1411 Index.getAs<nonloc::ConcreteInt>()) {
1414 if (SymbolicOffsetBase)
1417 int64_t
i = CI->getValue().getSExtValue();
1419 Offset += i * R->getContext().getTypeSize(EleTy);
1422 SymbolicOffsetBase = R;
1426 case MemRegion::FieldRegionKind: {
1427 const auto *FR = cast<FieldRegion>(R);
1428 R = FR->getSuperRegion();
1437 SymbolicOffsetBase = R;
1442 if (SymbolicOffsetBase)
1448 FE = RD->
field_end(); FI != FE; ++FI, ++idx) {
1449 if (FR->getDecl() == *FI)
1452 const ASTRecordLayout &Layout = R->getContext().getASTRecordLayout(RD);
1461 if (SymbolicOffsetBase)
1463 return RegionOffset(R, Offset);
1469 return *cachedOffset;
1476 std::pair<const VarRegion *, const VarRegion *>
1477 BlockDataRegion::getCaptureRegions(
const VarDecl *VD) {
1496 return std::make_pair(VR, OriginalVR);
1499 void BlockDataRegion::LazyInitializeReferencedVars() {
1506 std::distance(ReferencedBlockVars.begin(), ReferencedBlockVars.end());
1508 if (NumBlockVars == 0) {
1509 ReferencedVars = (
void*) 0x1;
1519 auto *BV = A.Allocate<VarVec>();
1520 new (BV) VarVec(BC, NumBlockVars);
1521 auto *BVOriginal = A.Allocate<VarVec>();
1522 new (BVOriginal) VarVec(BC, NumBlockVars);
1524 for (
const auto *VD : ReferencedBlockVars) {
1527 std::tie(VR, OriginalVR) = getCaptureRegions(VD);
1530 BV->push_back(VR, BC);
1531 BVOriginal->push_back(OriginalVR, BC);
1534 ReferencedVars = BV;
1535 OriginalVars = BVOriginal;
1544 if (Vec == (
void*) 0x1)
1551 VecOriginal->begin());
1560 if (Vec == (
void*) 0x1)
1567 VecOriginal->end());
1572 E = referenced_vars_end();
1574 if (I.getCapturedRegion() == R)
1575 return I.getOriginalRegion();
1586 SymTraitsMap[Sym] |= IK;
1592 if (
const auto *SR = dyn_cast<SymbolicRegion>(MR))
1593 setTrait(SR->getSymbol(), IK);
1595 MRTraitsMap[MR] |= IK;
1600 const_symbol_iterator I = SymTraitsMap.find(Sym);
1601 if (I != SymTraitsMap.end())
1602 return I->second & IK;
1612 if (
const auto *SR = dyn_cast<SymbolicRegion>(MR))
1613 return hasTrait(SR->getSymbol(), IK);
1615 const_region_iterator I = MRTraitsMap.find(MR);
1616 if (I != MRTraitsMap.end())
1617 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...
Represents 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.
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
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