36#include "llvm/ADT/APInt.h"
37#include "llvm/ADT/FoldingSet.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"
61#define DEBUG_TYPE "MemRegion"
67template <
typename RegionTy,
typename SuperTy,
typename Arg1Ty>
68RegionTy* MemRegionManager::getSubRegion(
const Arg1Ty arg1,
69 const SuperTy *superRegion) {
70 llvm::FoldingSetNodeID ID;
71 RegionTy::ProfileRegion(ID, arg1, superRegion);
73 auto *R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, InsertPos));
76 R = A.Allocate<RegionTy>();
77 new (R) RegionTy(arg1, superRegion);
78 Regions.InsertNode(R, InsertPos);
84template <
typename RegionTy,
typename SuperTy,
typename Arg1Ty,
typename Arg2Ty>
85RegionTy* MemRegionManager::getSubRegion(
const Arg1Ty arg1,
const Arg2Ty arg2,
86 const SuperTy *superRegion) {
87 llvm::FoldingSetNodeID
ID;
88 RegionTy::ProfileRegion(ID, arg1, arg2, superRegion);
90 auto *R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, InsertPos));
93 R = A.Allocate<RegionTy>();
94 new (R) RegionTy(arg1, arg2, superRegion);
95 Regions.InsertNode(R, InsertPos);
101template <
typename RegionTy,
typename SuperTy,
102 typename Arg1Ty,
typename Arg2Ty,
typename Arg3Ty>
103RegionTy* MemRegionManager::getSubRegion(
const Arg1Ty arg1,
const Arg2Ty arg2,
105 const SuperTy *superRegion) {
106 llvm::FoldingSetNodeID
ID;
107 RegionTy::ProfileRegion(ID, arg1, arg2, arg3, superRegion);
109 auto *R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, InsertPos));
112 R = A.Allocate<RegionTy>();
113 new (R) RegionTy(arg1, arg2, arg3, superRegion);
114 Regions.InsertNode(R, InsertPos);
139 if (
const auto *sr = dyn_cast<SubRegion>(r))
140 r = sr->getSuperRegion();
143 }
while (r !=
nullptr);
151 if (
const auto *sr = dyn_cast<SubRegion>(
superRegion)) {
161 return SSR ? SSR->getStackFrame() :
nullptr;
165 :
DeclRegion(sReg, ObjCIvarRegionKind), IVD(ivd) {
185 "`ParamVarRegion` support functions without `Decl` not implemented"
193 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
194 assert(Index < FD->param_size());
195 return FD->parameters()[Index];
196 }
else if (
const auto *BD = dyn_cast<BlockDecl>(D)) {
197 assert(Index < BD->param_size());
198 return BD->parameters()[Index];
199 }
else if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
200 assert(Index < MD->param_size());
201 return MD->parameters()[Index];
202 }
else if (
const auto *CD = dyn_cast<CXXConstructorDecl>(D)) {
203 assert(Index < CD->param_size());
204 return CD->parameters()[Index];
206 llvm_unreachable(
"Unexpected Decl kind!");
215 ID.AddInteger(
static_cast<unsigned>(
getKind()));
219 ID.AddInteger(
static_cast<unsigned>(
getKind()));
224 ID.AddInteger(
static_cast<unsigned>(
getKind()));
228void StringRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
231 ID.AddInteger(
static_cast<unsigned>(StringRegionKind));
236void ObjCStringRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
239 ID.AddInteger(
static_cast<unsigned>(ObjCStringRegionKind));
244void AllocaRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
245 const Expr *Ex,
unsigned cnt,
247 ID.AddInteger(
static_cast<unsigned>(AllocaRegionKind));
258 CompoundLiteralRegion::ProfileRegion(ID, CL,
superRegion);
261void CompoundLiteralRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
264 ID.AddInteger(
static_cast<unsigned>(CompoundLiteralRegionKind));
269void CXXThisRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
272 ID.AddInteger(
static_cast<unsigned>(CXXThisRegionKind));
274 ID.AddPointer(sRegion);
278 CXXThisRegion::ProfileRegion(ID, ThisPointerTy,
superRegion);
285void ObjCIvarRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
288 ID.AddInteger(
static_cast<unsigned>(ObjCIvarRegionKind));
297void NonParamVarRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
300 ID.AddInteger(
static_cast<unsigned>(NonParamVarRegionKind));
309void ParamVarRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
const Expr *OE,
311 ID.AddInteger(
static_cast<unsigned>(ParamVarRegionKind));
323 ID.AddInteger(
static_cast<unsigned>(MemRegion::SymbolicRegionKind));
332void ElementRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
335 ID.AddInteger(MemRegion::ElementRegionKind);
342 ElementRegion::ProfileRegion(ID, ElementType, Index,
superRegion);
345void FunctionCodeRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
348 ID.AddInteger(MemRegion::FunctionCodeRegionKind);
353 FunctionCodeRegion::ProfileRegion(ID, FD,
superRegion);
356void BlockCodeRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
360 ID.AddInteger(MemRegion::BlockCodeRegionKind);
365 BlockCodeRegion::ProfileRegion(ID, BD, locTy, AC,
superRegion);
368void BlockDataRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
373 ID.AddInteger(MemRegion::BlockDataRegionKind);
376 ID.AddInteger(BlkCount);
381 BlockDataRegion::ProfileRegion(ID, BC, LC, BlockCount,
getSuperRegion());
384void CXXTempObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
395void CXXBaseObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
400 ID.AddBoolean(IsVirtual);
408void CXXDerivedObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
423void GlobalsSpaceRegion::anchor() {}
425void NonStaticGlobalSpaceRegion::anchor() {}
427void StackSpaceRegion::anchor() {}
429void TypedRegion::anchor() {}
431void TypedValueRegion::anchor() {}
433void CodeTextRegion::anchor() {}
435void SubRegion::anchor() {}
447 llvm::raw_string_ostream os(
s);
453 os <<
"<Unknown Region>";
465 os <<
"block_code{" <<
static_cast<const void *
>(
this) <<
'}';
469 os <<
"block_data{" << BC;
474 os <<
"(" << I.getCapturedRegion() <<
"<-" <<
475 I.getOriginalRegion() <<
") ";
515 assert(Str !=
nullptr &&
"Expecting non-null StringLiteral");
520 assert(Str !=
nullptr &&
"Expecting non-null ObjCStringLiteral");
527 os <<
"SymRegion{" << sym <<
'}';
534 os <<
"NonParamVarRegion{D" << VD->
getID() <<
'}';
546 os <<
"CodeSpaceRegion";
550 os <<
"StaticGlobalsMemSpace{" << CR <<
'}';
554 os <<
"GlobalInternalSpaceRegion";
558 os <<
"GlobalSystemSpaceRegion";
562 os <<
"GlobalImmutableSpaceRegion";
566 os <<
"HeapSpaceRegion";
570 os <<
"UnknownSpaceRegion";
574 os <<
"StackArgumentsSpaceRegion";
578 os <<
"StackLocalsSpaceRegion";
584 "`ParamVarRegion` support functions without `Decl` not implemented"
589 os <<
"ParamVarRegion{P" << PVD->
getID() <<
'}';
602 assert(
canPrintPretty() &&
"This region cannot be printed pretty.");
609 llvm_unreachable(
"This region cannot be printed pretty.");
622 "`ParamVarRegion` support functions without `Decl` not implemented"
676 std::string VariableName;
677 std::string ArrayIndices;
680 llvm::raw_svector_ostream os(buf);
688 CI->getValue().toString(Idx);
689 ArrayIndices = (llvm::Twine(
"[") + Idx.str() +
"]" + ArrayIndices).str();
696 ArrayIndices = (llvm::Twine(
"[") + Idx +
"]" + ArrayIndices).str();
706 return (llvm::Twine(
"'") + os.str() + ArrayIndices +
"'").str();
708 return (llvm::Twine(os.str()) + ArrayIndices).str();
715 const auto *
const VR = dyn_cast<VarRegion>(this->
getBaseRegion());
716 const auto *
const FR = dyn_cast<FieldRegion>(
this);
721 return FR->getDecl()->getSourceRange();
725 return VR->getDecl()->getSourceRange();
738 const auto *SR = cast<SubRegion>(MR);
741 switch (SR->getKind()) {
742 case MemRegion::AllocaRegionKind:
743 case MemRegion::SymbolicRegionKind:
745 case MemRegion::StringRegionKind:
747 cast<StringRegion>(SR)->getStringLiteral()->getByteLength() + 1,
749 case MemRegion::CompoundLiteralRegionKind:
750 case MemRegion::CXXBaseObjectRegionKind:
751 case MemRegion::CXXDerivedObjectRegionKind:
752 case MemRegion::CXXTempObjectRegionKind:
753 case MemRegion::CXXThisRegionKind:
754 case MemRegion::ObjCIvarRegionKind:
755 case MemRegion::NonParamVarRegionKind:
756 case MemRegion::ParamVarRegionKind:
757 case MemRegion::ElementRegionKind:
758 case MemRegion::ObjCStringRegionKind: {
759 QualType Ty = cast<TypedValueRegion>(SR)->getDesugaredValueType(Ctx);
760 if (isa<VariableArrayType>(Ty))
768 case MemRegion::FieldRegionKind: {
770 if (cast<FieldRegion>(SR)->getDecl()->isBitField())
773 QualType Ty = cast<TypedValueRegion>(SR)->getDesugaredValueType(Ctx);
784 const auto isFlexibleArrayMemberCandidate = [
this,
789 if (isa<IncompleteArrayType>(AT))
792 if (
const auto *CAT = dyn_cast<ConstantArrayType>(AT)) {
794 const FAMKind StrictFlexArraysLevel =
797 const llvm::APInt &Size = CAT->getSize();
799 if (StrictFlexArraysLevel <= FAMKind::ZeroOrIncomplete && Size.isZero())
805 if (StrictFlexArraysLevel == FAMKind::Default) {
807 if (Opts.ShouldConsiderSingleElementArraysAsFlexibleArrayMembers &&
813 if (StrictFlexArraysLevel <= FAMKind::OneZeroOrIncomplete &&
821 if (isFlexibleArrayMemberCandidate(Ty))
829 case MemRegion::BlockDataRegionKind:
830 case MemRegion::BlockCodeRegionKind:
831 case MemRegion::FunctionCodeRegionKind:
834 llvm_unreachable(
"Unhandled region");
838template <
typename REG>
839const REG *MemRegionManager::LazyAllocate(REG*& region) {
841 region = A.Allocate<REG>();
842 new (region) REG(*
this);
848template <
typename REG,
typename ARG>
849const REG *MemRegionManager::LazyAllocate(REG*& region, ARG a) {
851 region = A.Allocate<REG>();
852 new (region) REG(
this, a);
888 if (K == MemRegion::GlobalSystemSpaceRegionKind)
889 return LazyAllocate(SystemGlobals);
890 if (K == MemRegion::GlobalImmutableSpaceRegionKind)
891 return LazyAllocate(ImmutableGlobals);
892 assert(K == MemRegion::GlobalInternalSpaceRegionKind);
893 return LazyAllocate(InternalGlobals);
896 assert(K == MemRegion::StaticGlobalSpaceRegionKind);
907 return LazyAllocate(heap);
911 return LazyAllocate(unknown);
915 return LazyAllocate(code);
923 return getSubRegion<StringRegion>(
929 return getSubRegion<ObjCStringRegion>(
936static llvm::PointerUnion<const StackFrameContext *, const VarRegion *>
941 if (
const auto *SFC = dyn_cast<StackFrameContext>(LC)) {
942 if (cast<DeclContext>(SFC->getDecl()) == DC)
945 if (
const auto *BC = dyn_cast<BlockInvocationContext>(LC)) {
949 I = BR->referenced_vars_begin(),
950 E = BR->referenced_vars_end(); I != E; ++I) {
952 if (
const auto *VR = dyn_cast<VarRegion>(OrigR)) {
953 if (VR->getDecl() == VD)
954 return cast<VarRegion>(I.getCapturedRegion());
966 const auto *PVD = dyn_cast<ParmVarDecl>(D);
968 unsigned Index = PVD->getFunctionScopeIndex();
973 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
974 if (Index < FD->param_size() && FD->parameters()[Index] == PVD)
975 return getSubRegion<ParamVarRegion>(cast<Expr>(CallSite), Index,
977 }
else if (
const auto *BD = dyn_cast<BlockDecl>(D)) {
978 if (Index < BD->param_size() && BD->
parameters()[Index] == PVD)
979 return getSubRegion<ParamVarRegion>(cast<Expr>(CallSite), Index,
982 return getSubRegion<ParamVarRegion>(cast<Expr>(CallSite), Index,
1007 llvm::PointerUnion<const StackFrameContext *, const VarRegion *>
V =
1022 isa<ParmVarDecl, ImplicitParamDecl>(D)
1029 if (isa<FunctionDecl, ObjCMethodDecl>(STCD))
1032 else if (
const auto *BD = dyn_cast<BlockDecl>(STCD)) {
1050 STC->getAnalysisDeclContext());
1061 return getSubRegion<NonParamVarRegion>(D, sReg);
1068 return getSubRegion<NonParamVarRegion>(D, superR);
1076 return getSubRegion<ParamVarRegion>(OriginExpr, Index,
1083 unsigned blockCount) {
1091 bool IsArcManagedBlock = Ctx.
getLangOpts().ObjCAutoRefCount;
1096 if (!IsArcManagedBlock && LC) {
1109 return getSubRegion<BlockDataRegion>(BC, LC, blockCount, sReg);
1114 return getSubRegion<CXXTempObjectRegion>(
1131 return getSubRegion<CompoundLiteralRegion>(CL, sReg);
1140 llvm::FoldingSetNodeID ID;
1141 ElementRegion::ProfileRegion(ID, T, Idx, superRegion);
1144 MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
1145 auto *R = cast_or_null<ElementRegion>(data);
1150 Regions.InsertNode(R, InsertPos);
1159 return getSubRegion<FunctionCodeRegion>(FD,
getCodeRegion());
1165 return getSubRegion<BlockCodeRegion>(BD, locTy, AC,
getCodeRegion());
1171 if (MemSpace ==
nullptr)
1173 return getSubRegion<SymbolicRegion>(sym, MemSpace);
1183 return getSubRegion<FieldRegion>(d, superRegion);
1189 return getSubRegion<ObjCIvarRegion>(d, superRegion);
1212 return Class->isVirtuallyDerivedFrom(BaseClass);
1214 for (
const auto &I : Class->bases()) {
1215 if (I.getType()->getAsCXXRecordDecl()->getCanonicalDecl() == BaseClass)
1226 if (isa<TypedValueRegion>(Super)) {
1233 while (
const auto *
Base = dyn_cast<CXXBaseObjectRegion>(Super))
1234 Super = cast<SubRegion>(
Base->getSuperRegion());
1235 assert(Super && !isa<MemSpaceRegion>(Super));
1239 return getSubRegion<CXXBaseObjectRegion>(RD, IsVirtual, Super);
1245 return getSubRegion<CXXDerivedObjectRegion>(RD, Super);
1255 const auto *D = dyn_cast<CXXMethodDecl>(LC->
getDecl());
1259 while (!LC->
inTopFrame() && (!D || D->isStatic() ||
1262 D = dyn_cast<CXXMethodDecl>(LC->
getDecl());
1279 const auto *SR = dyn_cast<SubRegion>(
this);
1282 R = SR->getSuperRegion();
1283 SR = dyn_cast<SubRegion>(R);
1286 return dyn_cast<MemSpaceRegion>(R);
1302 return isa<StackArgumentsSpaceRegion, GlobalsSpaceRegion>(
getMemorySpace());
1311 case MemRegion::ElementRegionKind:
1312 case MemRegion::FieldRegionKind:
1313 case MemRegion::ObjCIvarRegionKind:
1314 case MemRegion::CXXBaseObjectRegionKind:
1315 case MemRegion::CXXDerivedObjectRegionKind:
1316 R = cast<SubRegion>(R)->getSuperRegion();
1329 while (
const auto *BR = dyn_cast<CXXBaseObjectRegion>(R))
1330 R = BR->getSuperRegion();
1346 case ElementRegionKind: {
1347 const auto *ER = cast<ElementRegion>(R);
1348 if (!ER->getIndex().isZeroConstant())
1350 R = ER->getSuperRegion();
1353 case CXXBaseObjectRegionKind:
1354 case CXXDerivedObjectRegionKind:
1355 if (!StripBaseAndDerivedCasts)
1357 R = cast<TypedValueRegion>(R)->getSuperRegion();
1366 const auto *SubR = dyn_cast<SubRegion>(
this);
1369 if (
const auto *SymR = dyn_cast<SymbolicRegion>(SubR))
1371 SubR = dyn_cast<SubRegion>(SubR->getSuperRegion());
1391 int64_t i = CI->getValue().getSExtValue();
1402 int64_t size =
C.getTypeSizeInChars(elemType).getQuantity();
1403 if (
auto NewOffset = llvm::checkedMulAdd(i, size, offset)) {
1404 offset = *NewOffset;
1406 LLVM_DEBUG(llvm::dbgs() <<
"MemRegion::getAsArrayOffset: "
1407 <<
"offset overflowing, returning unknown\n");
1414 ER = dyn_cast<ElementRegion>(superR);
1421 assert(superR &&
"super region cannot be NULL");
1428 assert(Child &&
"Child must not be null");
1432 for (
const auto &I : Child->bases()) {
1433 if (I.getType()->getAsCXXRecordDecl() ==
Base)
1441 const MemRegion *SymbolicOffsetBase =
nullptr;
1446 case MemRegion::CodeSpaceRegionKind:
1447 case MemRegion::StackLocalsSpaceRegionKind:
1448 case MemRegion::StackArgumentsSpaceRegionKind:
1449 case MemRegion::HeapSpaceRegionKind:
1450 case MemRegion::UnknownSpaceRegionKind:
1451 case MemRegion::StaticGlobalSpaceRegionKind:
1452 case MemRegion::GlobalInternalSpaceRegionKind:
1453 case MemRegion::GlobalSystemSpaceRegionKind:
1454 case MemRegion::GlobalImmutableSpaceRegionKind:
1456 assert(
Offset == 0 && !SymbolicOffsetBase);
1459 case MemRegion::FunctionCodeRegionKind:
1460 case MemRegion::BlockCodeRegionKind:
1461 case MemRegion::BlockDataRegionKind:
1465 SymbolicOffsetBase = R;
1468 case MemRegion::SymbolicRegionKind:
1469 case MemRegion::AllocaRegionKind:
1470 case MemRegion::CompoundLiteralRegionKind:
1471 case MemRegion::CXXThisRegionKind:
1472 case MemRegion::StringRegionKind:
1473 case MemRegion::ObjCStringRegionKind:
1474 case MemRegion::NonParamVarRegionKind:
1475 case MemRegion::ParamVarRegionKind:
1476 case MemRegion::CXXTempObjectRegionKind:
1480 case MemRegion::ObjCIvarRegionKind:
1488 case MemRegion::CXXBaseObjectRegionKind: {
1489 const auto *BOR = cast<CXXBaseObjectRegion>(R);
1490 R = BOR->getSuperRegion();
1493 bool RootIsSymbolic =
false;
1494 if (
const auto *TVR = dyn_cast<TypedValueRegion>(R)) {
1495 Ty = TVR->getDesugaredValueType(R->
getContext());
1496 }
else if (
const auto *SR = dyn_cast<SymbolicRegion>(R)) {
1500 Ty = SR->getPointeeStaticType();
1501 RootIsSymbolic =
true;
1507 SymbolicOffsetBase = R;
1509 if (RootIsSymbolic) {
1513 if (BOR->isVirtual()) {
1514 if (!Child->isVirtuallyDerivedFrom(BOR->getDecl()))
1515 SymbolicOffsetBase = R;
1518 SymbolicOffsetBase = R;
1525 if (SymbolicOffsetBase)
1530 if (BOR->isVirtual())
1540 case MemRegion::CXXDerivedObjectRegionKind: {
1545 case MemRegion::ElementRegionKind: {
1546 const auto *ER = cast<ElementRegion>(R);
1547 R = ER->getSuperRegion();
1549 QualType EleTy = ER->getValueType();
1552 SymbolicOffsetBase = R;
1556 SVal Index = ER->getIndex();
1557 if (std::optional<nonloc::ConcreteInt> CI =
1561 if (SymbolicOffsetBase)
1564 int64_t i = CI->getValue().getSExtValue();
1569 SymbolicOffsetBase = R;
1573 case MemRegion::FieldRegionKind: {
1574 const auto *FR = cast<FieldRegion>(R);
1575 R = FR->getSuperRegion();
1585 SymbolicOffsetBase = R;
1590 if (SymbolicOffsetBase)
1596 FE = RD->
field_end(); FI != FE; ++FI, ++idx) {
1597 if (FR->getDecl() == *FI)
1609 if (SymbolicOffsetBase)
1617 return *cachedOffset;
1624std::pair<const VarRegion *, const VarRegion *>
1625BlockDataRegion::getCaptureRegions(
const VarDecl *VD) {
1644 return std::make_pair(VR, OriginalVR);
1647void BlockDataRegion::LazyInitializeReferencedVars() {
1654 std::distance(ReferencedBlockVars.begin(), ReferencedBlockVars.end());
1656 if (NumBlockVars == 0) {
1657 ReferencedVars = (
void*) 0x1;
1667 auto *BV = A.Allocate<VarVec>();
1668 new (BV) VarVec(BC, NumBlockVars);
1669 auto *BVOriginal = A.Allocate<VarVec>();
1670 new (BVOriginal) VarVec(BC, NumBlockVars);
1672 for (
const auto *VD : ReferencedBlockVars) {
1675 std::tie(VR, OriginalVR) = getCaptureRegions(VD);
1678 BV->push_back(VR, BC);
1679 BVOriginal->push_back(OriginalVR, BC);
1682 ReferencedVars = BV;
1683 OriginalVars = BVOriginal;
1692 if (Vec == (
void*) 0x1)
1699 VecOriginal->begin());
1708 if (Vec == (
void*) 0x1)
1715 VecOriginal->end());
1722 if (I.getCapturedRegion() == R)
1723 return I.getOriginalRegion();
1734 SymTraitsMap[Sym] |= IK;
1740 if (
const auto *SR = dyn_cast<SymbolicRegion>(MR))
1743 MRTraitsMap[MR] |= IK;
1748 const_symbol_iterator I = SymTraitsMap.find(Sym);
1749 if (I != SymTraitsMap.end())
1750 return I->second & IK;
1760 if (
const auto *SR = dyn_cast<SymbolicRegion>(MR))
1761 return hasTrait(SR->getSymbol(), IK);
1763 const_region_iterator I = MRTraitsMap.find(MR);
1764 if (I != MRTraitsMap.end())
1765 return I->second & IK;
Defines the clang::ASTContext interface.
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
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...
static bool isImmediateBase(const CXXRecordDecl *Child, const CXXRecordDecl *Base)
Returns true if Base is an immediate base class of Child.
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.
static RegionOffset calculateOffset(const MemRegion *R)
Defines the SourceManager interface.
C Language Family Type Representation.
__device__ __2f16 float bool s
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
const LangOptions & getLangOpts() const
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
uint64_t getCharWidth() const
Return the size of the character type, in bits.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
CharUnits getVBaseClassOffset(const CXXRecordDecl *VBase) const
getVBaseClassOffset - Get the offset, in chars, for the given base class.
AnalysisDeclContext contains the context data for the function, method or block under analysis.
llvm::iterator_range< referenced_decls_iterator > getReferencedBlockVars(const BlockDecl *BD)
Stores options for the analyzer from the command line.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
bool hasCaptures() const
True if this block (or its nested blocks) captures anything of local storage from its enclosing scope...
ArrayRef< ParmVarDecl * > parameters() const
TypeSourceInfo * getSignatureAsWritten() const
Represents a C++ struct/union/class.
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
CharUnits - This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
CompoundLiteralExpr - [C99 6.5.2.5].
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Decl - This represents one declaration (or definition), e.g.
SourceLocation getLocation() const
DeclContext * getDeclContext()
std::string getAsString() const
Retrieve the human-readable string for this name.
This represents one expression.
Represents a member of a struct/union/class.
FunctionType - C99 6.7.5.3 - Function Declarators.
One of these records is kept for each identifier that is lexed.
StrictFlexArraysLevelKind
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
const Decl * getDecl() const
const LocationContext * getParent() const
It might return null.
const StackFrameContext * getStackFrame() const
virtual bool inTopFrame() const
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
ObjCIvarDecl - Represents an ObjC instance variable.
ObjCStringLiteral, used for Objective-C string literals i.e.
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
bool isConstQualified() const
Determine whether this type is const-qualified.
Represents a struct/union/class.
field_iterator field_end() const
field_iterator field_begin() const
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
A trivial tuple used to represent a source range.
It represents a stack frame of the call stack (based on CallEvent).
const Stmt * getCallSite() const
Stmt - This represents one statement.
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
int64_t getID(const ASTContext &Context) const
StringLiteral - This represents a string literal expression, e.g.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
A container of type source information.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
const T * getAs() const
Member-template getAs<specific type>'.
Represents a variable declaration or definition.
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
AllocaRegion - A region that represents an untyped blob of bytes created by a call to 'alloca'.
void dumpToStream(raw_ostream &os) const override
void Profile(llvm::FoldingSetNodeID &ID) const override
BlockCodeRegion - A region that represents code texts of blocks (closures).
LLVM_ATTRIBUTE_RETURNS_NONNULL AnalysisDeclContext * getAnalysisDeclContext() const
void dumpToStream(raw_ostream &os) const override
LLVM_ATTRIBUTE_RETURNS_NONNULL const BlockDecl * getDecl() const
void Profile(llvm::FoldingSetNodeID &ID) const override
BlockDataRegion - A region that represents a block instance.
const VarRegion * getOriginalRegion(const VarRegion *VR) const
Return the original region for a captured region, if one exists.
referenced_vars_iterator referenced_vars_begin() const
LLVM_ATTRIBUTE_RETURNS_NONNULL const BlockCodeRegion * getCodeRegion() const
void Profile(llvm::FoldingSetNodeID &ID) const override
referenced_vars_iterator referenced_vars_end() const
void dumpToStream(raw_ostream &os) const override
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
LLVM_ATTRIBUTE_RETURNS_NONNULL const CXXRecordDecl * getDecl() const
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression.
void Profile(llvm::FoldingSetNodeID &ID) const override
void dumpToStream(raw_ostream &os) const override
QualType getValueType() 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
void dumpToStream(raw_ostream &os) const override
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression.
LLVM_ATTRIBUTE_RETURNS_NONNULL const CXXRecordDecl * getDecl() const
QualType getValueType() const override
void Profile(llvm::FoldingSetNodeID &ID) const override
void dumpToStream(raw_ostream &os) const override
CXXThisRegion - Represents the region for the implicit 'this' parameter in a call to a C++ method.
void Profile(llvm::FoldingSetNodeID &ID) const override
void dumpToStream(raw_ostream &os) const override
CodeSpaceRegion - The memory space that holds the executable code of functions and blocks.
void dumpToStream(raw_ostream &os) const override
CompoundLiteralRegion - A memory region representing a compound literal.
void Profile(llvm::FoldingSetNodeID &ID) const override
void dumpToStream(raw_ostream &os) const override
ElementRegion is used to represent both array elements and casts.
QualType getElementType() const
void Profile(llvm::FoldingSetNodeID &ID) const override
RegionRawOffset getAsArrayOffset() const
Compute the offset within the array. The array might also be a subobject.
void dumpToStream(raw_ostream &os) const override
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
bool canPrintPretty() const override
Returns true if this region can be printed in a user-friendly way.
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 override
void printPretty(raw_ostream &os) const override
Print the region for use in diagnostics.
void Profile(llvm::FoldingSetNodeID &ID) const override
LLVM_ATTRIBUTE_RETURNS_NONNULL const FieldDecl * getDecl() const override
FunctionCodeRegion - A region that represents code texts of function.
const NamedDecl * getDecl() const
void dumpToStream(raw_ostream &os) const override
void Profile(llvm::FoldingSetNodeID &ID) const override
void dumpToStream(raw_ostream &os) const override
void dumpToStream(raw_ostream &os) const override
void dumpToStream(raw_ostream &os) const override
void dumpToStream(raw_ostream &os) const override
const HeapSpaceRegion * getHeapRegion()
getHeapRegion - Retrieve the memory region associated with the generic "heap".
const StackArgumentsSpaceRegion * getStackArgumentsRegion(const StackFrameContext *STC)
getStackArgumentsRegion - Retrieve the memory region associated with function/method arguments of the...
const CXXThisRegion * getCXXThisRegion(QualType thisPointerTy, const LocationContext *LC)
getCXXThisRegion - Retrieve the [artificial] region associated with the parameter 'this'.
llvm::BumpPtrAllocator & getAllocator()
const BlockCodeRegion * getBlockCodeRegion(const BlockDecl *BD, CanQualType locTy, AnalysisDeclContext *AC)
const UnknownSpaceRegion * getUnknownRegion()
getUnknownRegion - Retrieve the memory region associated with unknown memory space.
const CXXDerivedObjectRegion * getCXXDerivedObjectRegion(const CXXRecordDecl *BaseClass, const SubRegion *Super)
Create a CXXDerivedObjectRegion with the given derived class for region Super.
const CompoundLiteralRegion * getCompoundLiteralRegion(const CompoundLiteralExpr *CL, const LocationContext *LC)
getCompoundLiteralRegion - Retrieve the region associated with a given CompoundLiteral.
const FieldRegion * getFieldRegion(const FieldDecl *fd, const SubRegion *superRegion)
getFieldRegion - Retrieve or create the memory region associated with a specified FieldDecl.
const AllocaRegion * getAllocaRegion(const Expr *Ex, unsigned Cnt, const LocationContext *LC)
getAllocaRegion - Retrieve a region associated with a call to alloca().
const VarRegion * getVarRegion(const VarDecl *VD, const LocationContext *LC)
getVarRegion - Retrieve or create the memory region associated with a specified VarDecl and LocationC...
const NonParamVarRegion * getNonParamVarRegion(const VarDecl *VD, const MemRegion *superR)
getVarRegion - Retrieve or create the memory region associated with a specified VarDecl and LocationC...
const StackLocalsSpaceRegion * getStackLocalsRegion(const StackFrameContext *STC)
getStackLocalsRegion - Retrieve the memory region associated with the specified stack frame.
const ObjCIvarRegion * getObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *superRegion)
getObjCIvarRegion - Retrieve or create the memory region associated with a specified Objective-c inst...
const CXXTempObjectRegion * getCXXStaticTempObjectRegion(const Expr *Ex)
Create a CXXTempObjectRegion for temporaries which are lifetime-extended by static references.
const SymbolicRegion * getSymbolicHeapRegion(SymbolRef sym)
Return a unique symbolic region belonging to heap memory space.
const ObjCStringRegion * getObjCStringRegion(const ObjCStringLiteral *Str)
const StringRegion * getStringRegion(const StringLiteral *Str)
ASTContext & getContext()
DefinedOrUnknownSVal getStaticSize(const MemRegion *MR, SValBuilder &SVB) const
const ParamVarRegion * getParamVarRegion(const Expr *OriginExpr, unsigned Index, const LocationContext *LC)
getParamVarRegion - Retrieve or create the memory region associated with a specified CallExpr,...
const CodeSpaceRegion * getCodeRegion()
const ElementRegion * getElementRegion(QualType elementType, NonLoc Idx, const SubRegion *superRegion, ASTContext &Ctx)
getElementRegion - Retrieve the memory region associated with the associated element type,...
const CXXTempObjectRegion * getCXXTempObjectRegion(Expr const *Ex, LocationContext const *LC)
const GlobalsSpaceRegion * getGlobalsRegion(MemRegion::Kind K=MemRegion::GlobalInternalSpaceRegionKind, const CodeTextRegion *R=nullptr)
getGlobalsRegion - Retrieve the memory region associated with global variables.
const SymbolicRegion * getSymbolicRegion(SymbolRef Sym, const MemSpaceRegion *MemSpace=nullptr)
Retrieve or create a "symbolic" memory region.
const FunctionCodeRegion * getFunctionCodeRegion(const NamedDecl *FD)
const BlockDataRegion * getBlockDataRegion(const BlockCodeRegion *bc, const LocationContext *lc, unsigned blockCount)
getBlockDataRegion - Get the memory region associated with an instance of a block.
const CXXBaseObjectRegion * getCXXBaseObjectRegion(const CXXRecordDecl *BaseClass, const SubRegion *Super, bool IsVirtual)
Create a CXXBaseObjectRegion with the given base class for region Super.
MemRegion - The root abstract class for all memory regions.
bool hasGlobalsOrParametersStorage() const
virtual bool canPrintPrettyAsExpr() const
Returns true if this region's textual representation can be used as part of a larger expression.
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemSpaceRegion * getMemorySpace() const
bool hasStackParametersStorage() const
RegionOffset getAsOffset() const
Compute the offset within the top level memory object.
bool hasStackStorage() const
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * StripCasts(bool StripBaseAndDerivedCasts=true) const
ASTContext & getContext() const
std::string getDescriptiveName(bool UseQuotes=true) const
Get descriptive name for memory region.
virtual bool isSubRegionOf(const MemRegion *R) const
Check if the region is a subregion of the given region.
virtual void dumpToStream(raw_ostream &os) const
const SymbolicRegion * getSymbolicBase() const
If this is a symbolic region, returns the region.
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * getBaseRegion() const
virtual void printPretty(raw_ostream &os) const
Print the region for use in diagnostics.
virtual void printPrettyAsExpr(raw_ostream &os) const
Print the region as expression.
bool hasStackNonParametersStorage() const
std::string getString() const
Get a string representation of a region for debug use.
const RegionTy * getAs() 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 insta...
virtual MemRegionManager & getMemRegionManager() const =0
virtual bool canPrintPretty() const
Returns true if this region can be printed in a user-friendly way.
SourceRange sourceRange() const
Retrieve source range from memory region.
MemSpaceRegion - A memory region that represents a "memory space"; for example, the set of global var...
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 Profile(llvm::FoldingSetNodeID &ID) const override
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
void dumpToStream(raw_ostream &os) const override
LLVM_ATTRIBUTE_RETURNS_NONNULL const VarDecl * getDecl() const override
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression.
void Profile(llvm::FoldingSetNodeID &ID) const override
QualType getValueType() const override
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
LLVM_ATTRIBUTE_RETURNS_NONNULL const ObjCIvarDecl * getDecl() const override
void dumpToStream(raw_ostream &os) const override
The region associated with an ObjCStringLiteral.
void dumpToStream(raw_ostream &os) const override
ParamVarRegion - Represents a region for paremters.
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression.
LLVM_ATTRIBUTE_RETURNS_NONNULL const Expr * getOriginExpr() const
const ParmVarDecl * getDecl() const override
TODO: What does this return?
unsigned getIndex() const
void Profile(llvm::FoldingSetNodeID &ID) const override
QualType getValueType() const override
void dumpToStream(raw_ostream &os) const override
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
InvalidationKinds
Describes different invalidation traits.
bool hasTrait(SymbolRef Sym, InvalidationKinds IK) const
void setTrait(SymbolRef Sym, InvalidationKinds IK)
Represent a region's offset within the top level base region.
static const int64_t Symbolic
CharUnits getOffset() const
void dumpToStream(raw_ostream &os) const
const MemRegion * getRegion() const
nonloc::ConcreteInt makeIntVal(const IntegerLiteral *integer)
QualType getArrayIndexType() const
const AnalyzerOptions & getAnalyzerOptions() const
SymbolManager & getSymbolManager()
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
void Profile(llvm::FoldingSetNodeID &ID) const
std::optional< T > getAs() const
Convert to the specified SVal type, returning std::nullopt if this SVal is not of the desired type.
void dumpToStream(raw_ostream &os) const override
void dumpToStream(raw_ostream &os) const override
LLVM_ATTRIBUTE_RETURNS_NONNULL const StackFrameContext * getStackFrame() const
void Profile(llvm::FoldingSetNodeID &ID) const override
The region of the static variables within the current CodeTextRegion scope.
void Profile(llvm::FoldingSetNodeID &ID) const override
void dumpToStream(raw_ostream &os) const override
LLVM_ATTRIBUTE_RETURNS_NONNULL const CodeTextRegion * getCodeRegion() const
StringRegion - Region associated with a StringLiteral.
void dumpToStream(raw_ostream &os) const override
SubRegion - A region that subsets another larger region.
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * getSuperRegion() const
bool isSubRegionOf(const MemRegion *R) const override
Check if the region is a subregion of the given region.
const MemRegion * superRegion
MemRegionManager & getMemRegionManager() const override
const SymbolExtent * getExtentSymbol(const SubRegion *R)
SymbolicRegion - A special, "non-concrete" region.
void dumpToStream(raw_ostream &os) const override
void Profile(llvm::FoldingSetNodeID &ID) const override
static void ProfileRegion(llvm::FoldingSetNodeID &ID, SymbolRef sym, const MemRegion *superRegion)
TypedValueRegion - An abstract class representing regions having a typed value.
virtual QualType getValueType() const =0
void dumpToStream(raw_ostream &os) const override
const VarDecl * getDecl() const override=0
const StackFrameContext * getStackFrame() const
It might return null.
Value representing integer constant.
Represents symbolic expression that isn't a location.
DefinedOrUnknownSVal getElementExtent(QualType Ty, SValBuilder &SVB)
@ C
Languages that the frontend can parse and compile.
Extra information about a function prototype.
Describes how types, statements, expressions, and declarations should be printed.