clang: lib/StaticAnalyzer/Core/MemRegion.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
35#include "llvm/ADT/APInt.h"
36#include "llvm/ADT/FoldingSet.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/ADT/iterator_range.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"
49#include
50#include
51#include
52#include
53#include
54#include
55#include
56
57using namespace clang;
58using namespace ento;
59
60#define DEBUG_TYPE "MemRegion"
61
64
65
66
67
68
69[[maybe_unused]] static bool isAReferenceTypedValueRegion(const MemRegion *R) {
70 const auto *TyReg = llvm::dyn_cast(R);
71 return TyReg && TyReg->getValueType()->isReferenceType();
72}
73
74template <typename RegionTy, typename SuperTy, typename Arg1Ty>
75RegionTy* MemRegionManager::getSubRegion(const Arg1Ty arg1,
76 const SuperTy *superRegion) {
77 llvm::FoldingSetNodeID ID;
78 RegionTy::ProfileRegion(ID, arg1, superRegion);
79 void *InsertPos;
80 auto *R = cast_or_null(Regions.FindNodeOrInsertPos(ID, InsertPos));
81
82 if (!R) {
83 R = new (A) RegionTy(arg1, superRegion);
84 Regions.InsertNode(R, InsertPos);
85 assert(!isAReferenceTypedValueRegion(superRegion));
86 }
87
88 return R;
89}
90
91template <typename RegionTy, typename SuperTy, typename Arg1Ty, typename Arg2Ty>
92RegionTy* MemRegionManager::getSubRegion(const Arg1Ty arg1, const Arg2Ty arg2,
93 const SuperTy *superRegion) {
94 llvm::FoldingSetNodeID ID;
95 RegionTy::ProfileRegion(ID, arg1, arg2, superRegion);
96 void *InsertPos;
97 auto *R = cast_or_null(Regions.FindNodeOrInsertPos(ID, InsertPos));
98
99 if (!R) {
100 R = new (A) RegionTy(arg1, arg2, superRegion);
101 Regions.InsertNode(R, InsertPos);
102 assert(!isAReferenceTypedValueRegion(superRegion));
103 }
104
105 return R;
106}
107
108template <typename RegionTy, typename SuperTy,
109 typename Arg1Ty, typename Arg2Ty, typename Arg3Ty>
110RegionTy* MemRegionManager::getSubRegion(const Arg1Ty arg1, const Arg2Ty arg2,
111 const Arg3Ty arg3,
112 const SuperTy *superRegion) {
113 llvm::FoldingSetNodeID ID;
114 RegionTy::ProfileRegion(ID, arg1, arg2, arg3, superRegion);
115 void *InsertPos;
116 auto *R = cast_or_null(Regions.FindNodeOrInsertPos(ID, InsertPos));
117
118 if (!R) {
119 R = new (A) RegionTy(arg1, arg2, arg3, superRegion);
120 Regions.InsertNode(R, InsertPos);
121 assert(!isAReferenceTypedValueRegion(superRegion));
122 }
123
124 return R;
125}
126
127
128
129
130
132
133
134
136
137
138
139
140
143 do {
144 if (r == R)
145 return true;
146 if (const auto *sr = dyn_cast(r))
147 r = sr->getSuperRegion();
148 else
149 break;
150 } while (r != nullptr);
151 return false;
152}
153
156 do {
158 if (const auto *sr = dyn_cast(superRegion)) {
159 r = sr;
160 continue;
161 }
162 return superRegion->getMemRegionManager();
163 } while (true);
164}
165
167 const auto *SSR = dyn_cast(getRawMemorySpace());
168 return SSR ? SSR->getStackFrame() : nullptr;
169}
170
173 const auto *SSR = dyn_cast(getRawMemorySpace());
174 return SSR ? SSR->getStackFrame() : nullptr;
175}
176
179 "A temporary object can only be allocated on the stack");
181}
182
184 : DeclRegion(sReg, ObjCIvarRegionKind), IVD(ivd) {
185 assert(IVD);
186}
187
189
193
197
201
204 "`ParamVarRegion` support functions without `Decl` not implemented"
205 " yet.");
207}
208
211
212 if (const auto *FD = dyn_cast(D)) {
213 assert(Index < FD->param_size());
214 return FD->parameters()[Index];
215 } else if (const auto *BD = dyn_cast(D)) {
216 assert(Index < BD->param_size());
217 return BD->parameters()[Index];
218 } else if (const auto *MD = dyn_cast(D)) {
219 assert(Index < MD->param_size());
220 return MD->parameters()[Index];
221 } else if (const auto *CD = dyn_cast(D)) {
222 assert(Index < CD->param_size());
223 return CD->parameters()[Index];
224 } else {
225 llvm_unreachable("Unexpected Decl kind!");
226 }
227}
228
229
230
231
232
234 ID.AddInteger(static_cast<unsigned>(getKind()));
235}
236
238 ID.AddInteger(static_cast<unsigned>(getKind()));
240}
241
243 ID.AddInteger(static_cast<unsigned>(getKind()));
245}
246
247void StringRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
250 ID.AddInteger(static_cast<unsigned>(StringRegionKind));
251 ID.AddPointer(Str);
253}
254
255void ObjCStringRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
258 ID.AddInteger(static_cast<unsigned>(ObjCStringRegionKind));
259 ID.AddPointer(Str);
261}
262
263void AllocaRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
264 const Expr *Ex, unsigned cnt,
266 ID.AddInteger(static_cast<unsigned>(AllocaRegionKind));
267 ID.AddPointer(Ex);
268 ID.AddInteger(cnt);
270}
271
275
277 CompoundLiteralRegion::ProfileRegion(ID, CL, superRegion);
278}
279
280void CompoundLiteralRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
283 ID.AddInteger(static_cast<unsigned>(CompoundLiteralRegionKind));
284 ID.AddPointer(CL);
286}
287
288void CXXThisRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
291 ID.AddInteger(static_cast<unsigned>(CXXThisRegionKind));
292 ID.AddPointer(PT);
293 ID.AddPointer(sRegion);
294}
295
297 CXXThisRegion::ProfileRegion(ID, ThisPointerTy, superRegion);
298}
299
303
304void ObjCIvarRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
307 ID.AddInteger(static_cast<unsigned>(ObjCIvarRegionKind));
308 ID.AddPointer(ivd);
310}
311
315
316void NonParamVarRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
319 ID.AddInteger(static_cast<unsigned>(NonParamVarRegionKind));
320 ID.AddPointer(VD);
322}
323
327
328void ParamVarRegion::ProfileRegion(llvm::FoldingSetNodeID &ID, const Expr *OE,
329 unsigned Idx, const MemRegion *SReg) {
330 ID.AddInteger(static_cast<unsigned>(ParamVarRegionKind));
331 ID.AddPointer(OE);
332 ID.AddInteger(Idx);
333 ID.AddPointer(SReg);
334}
335
339
342 ID.AddInteger(static_cast<unsigned>(MemRegion::SymbolicRegionKind));
343 ID.Add(sym);
344 ID.AddPointer(sreg);
345}
346
350
351void ElementRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
354 ID.AddInteger(MemRegion::ElementRegionKind);
355 ID.Add(ElementType);
358}
359
361 ElementRegion::ProfileRegion(ID, ElementType, Index, superRegion);
362}
363
364void FunctionCodeRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
367 ID.AddInteger(MemRegion::FunctionCodeRegionKind);
368 ID.AddPointer(FD);
369}
370
372 FunctionCodeRegion::ProfileRegion(ID, FD, superRegion);
373}
374
375void BlockCodeRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
379 ID.AddInteger(MemRegion::BlockCodeRegionKind);
380 ID.AddPointer(BD);
381}
382
384 BlockCodeRegion::ProfileRegion(ID, BD, locTy, AC, superRegion);
385}
386
387void BlockDataRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
390 unsigned BlkCount,
392 ID.AddInteger(MemRegion::BlockDataRegionKind);
393 ID.AddPointer(BC);
394 ID.AddPointer(LC);
395 ID.AddInteger(BlkCount);
396 ID.AddPointer(sReg);
397}
398
400 BlockDataRegion::ProfileRegion(ID, BC, LC, BlockCount, getSuperRegion());
401}
402
403void CXXTempObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
404 Expr const *Ex,
406 ID.AddPointer(Ex);
407 ID.AddPointer(sReg);
408}
409
413
414void CXXLifetimeExtendedObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
415 const Expr *E,
418 ID.AddPointer(E);
419 ID.AddPointer(D);
420 ID.AddPointer(sReg);
421}
422
424 llvm::FoldingSetNodeID &ID) const {
426}
427
428void CXXBaseObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
430 bool IsVirtual,
432 ID.AddPointer(RD);
433 ID.AddBoolean(IsVirtual);
434 ID.AddPointer(SReg);
435}
436
440
441void CXXDerivedObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
444 ID.AddPointer(RD);
445 ID.AddPointer(SReg);
446}
447
451
452
453
454
455
456void GlobalsSpaceRegion::anchor() {}
457
458void NonStaticGlobalSpaceRegion::anchor() {}
459
460void StackSpaceRegion::anchor() {}
461
462void TypedRegion::anchor() {}
463
464void TypedValueRegion::anchor() {}
465
466void CodeTextRegion::anchor() {}
467
468void SubRegion::anchor() {}
469
470
471
472
473
477
479 std::string s;
480 llvm::raw_string_ostream os(s);
482 return s;
483}
484
486 os << "";
487}
488
490 os << "alloca{S" << Ex->getID(getContext()) << ',' << Cnt << '}';
491}
492
496
498 os << "block_code{" << static_cast<const void *>(this) << '}';
499}
500
502 os << "block_data{" << BC;
503 os << "; ";
505 os << "(" << Var.getCapturedRegion() << "<-" << Var.getOriginalRegion()
506 << ") ";
507 os << '}';
508}
509
511
512 os << "{ S" << CL->getID(getContext()) << " }";
513}
514
519
521 os << "lifetime_extended_object{" << getValueType() << ", ";
523 os << ID->getName();
524 else
525 os << "D" << ExD->getID();
526 os << ", "
527 << "S" << Ex->getID(getContext()) << '}';
528}
529
533
537
541
546
550
554
556 assert(Str != nullptr && "Expecting non-null StringLiteral");
558}
559
561 assert(Str != nullptr && "Expecting non-null ObjCStringLiteral");
563}
564
567 os << "Heap";
568 os << "SymRegion{" << sym << '}';
569}
570
573 os << ID->getName();
574 else
575 os << "NonParamVarRegion{D" << VD->getID() << '}';
576}
577
581
585
587 os << "CodeSpaceRegion";
588}
589
591 os << "StaticGlobalsMemSpace{" << CR << '}';
592}
593
595 os << "GlobalInternalSpaceRegion";
596}
597
599 os << "GlobalSystemSpaceRegion";
600}
601
603 os << "GlobalImmutableSpaceRegion";
604}
605
607 os << "HeapSpaceRegion";
608}
609
611 os << "UnknownSpaceRegion";
612}
613
615 os << "StackArgumentsSpaceRegion";
616}
617
619 os << "StackLocalsSpaceRegion";
620}
621
624 assert(PVD &&
625 "`ParamVarRegion` support functions without `Decl` not implemented"
626 " yet.");
628 os << ID->getName();
629 } else {
630 os << "ParamVarRegion{P" << PVD->getID() << '}';
631 }
632}
633
637
641
644#define REGION(Id, Parent) \
645 case Id##Kind: \
646 return #Id;
647#include "clang/StaticAnalyzer/Core/PathSensitive/Regions.def"
648#undef REGION
649 }
650 llvm_unreachable("Unkown kind!");
651}
652
654 assert(canPrintPretty() && "This region cannot be printed pretty.");
655 os << "'";
657 os << "'";
658}
659
661 llvm_unreachable("This region cannot be printed pretty.");
662}
663
665
669
671
674 "`ParamVarRegion` support functions without `Decl` not implemented"
675 " yet.");
677}
678
682
686
690
694
700
703 os << "\'";
705 os << "'";
706 } else {
707 os << "field " << "\'" << getDecl()->getName() << "'";
708 }
709}
710
714
718
722
726
728 std::string VariableName;
729 std::string ArrayIndices;
732 llvm::raw_svector_ostream os(buf);
733
734
735 auto QuoteIfNeeded = [UseQuotes](const Twine &Subject) -> std::string {
736 if (UseQuotes)
737 return ("'" + Subject + "'").str();
738 return Subject.str();
739 };
740
741
744
747 CI->getValue()->toString(Idx);
748 ArrayIndices = (llvm::Twine("[") + Idx.str() + "]" + ArrayIndices).str();
749 }
750
751 else {
753 if (!SI)
754 return "";
755
756 const MemRegion *OR = SI->getAsSymbol()->getOriginRegion();
757 if (!OR)
758 return "";
759
761 if (Idx.empty())
762 return "";
763
764 ArrayIndices = (llvm::Twine("[") + Idx + "]" + ArrayIndices).str();
765 }
767 }
768
769
770 if (R) {
771
774 return QuoteIfNeeded(llvm::Twine(os.str()) + ArrayIndices);
775 }
776
777
779 std::string Super = FR->getSuperRegion()->getDescriptiveName(false);
780 if (Super.empty())
781 return "";
782 return QuoteIfNeeded(Super + "." + FR->getDecl()->getName());
783 }
784 }
785
786 return VariableName;
787}
788
790
791 if (auto *FR = dyn_cast(this)) {
792 return FR->getDecl()->getSourceRange();
793 }
794
795 if (auto *VR = dyn_cast(this->getBaseRegion())) {
796 return VR->getDecl()->getSourceRange();
797 }
798
799
800 return {};
801}
802
803
804
805
806
811
812 switch (SR->getKind()) {
813 case MemRegion::AllocaRegionKind:
814 case MemRegion::SymbolicRegionKind:
816 case MemRegion::StringRegionKind:
820 case MemRegion::CompoundLiteralRegionKind:
821 case MemRegion::CXXBaseObjectRegionKind:
822 case MemRegion::CXXDerivedObjectRegionKind:
823 case MemRegion::CXXTempObjectRegionKind:
824 case MemRegion::CXXLifetimeExtendedObjectRegionKind:
825 case MemRegion::CXXThisRegionKind:
826 case MemRegion::ObjCIvarRegionKind:
827 case MemRegion::NonParamVarRegionKind:
828 case MemRegion::ParamVarRegionKind:
829 case MemRegion::ElementRegionKind:
830 case MemRegion::ObjCStringRegionKind: {
834
837
839 }
840 case MemRegion::FieldRegionKind: {
841
844
847
848
849
850
851
852
853 const auto isFlexibleArrayMemberCandidate =
854 [this](const ArrayType *AT) -> bool {
855 if (!AT)
856 return false;
857
858 auto IsIncompleteArray = [](const ArrayType *AT) {
860 };
861 auto IsArrayOfZero = [](const ArrayType *AT) {
862 const auto *CAT = dyn_cast(AT);
863 return CAT && CAT->isZeroSize();
864 };
865 auto IsArrayOfOne = [](const ArrayType *AT) {
866 const auto *CAT = dyn_cast(AT);
867 return CAT && CAT->getSize() == 1;
868 };
869
871 const FAMKind StrictFlexArraysLevel =
872 Ctx.getLangOpts().getStrictFlexArraysLevel();
873
874
875
876
877 if (StrictFlexArraysLevel == FAMKind::Default)
878 return IsArrayOfOne(AT) || IsArrayOfZero(AT) || IsIncompleteArray(AT);
879
880 if (StrictFlexArraysLevel == FAMKind::OneZeroOrIncomplete)
881 return IsArrayOfOne(AT) || IsArrayOfZero(AT) || IsIncompleteArray(AT);
882
883 if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete)
884 return IsArrayOfZero(AT) || IsIncompleteArray(AT);
885
886 assert(StrictFlexArraysLevel == FAMKind::IncompleteOnly);
887 return IsIncompleteArray(AT);
888 };
889
890 if (isFlexibleArrayMemberCandidate(Ctx.getAsArrayType(Ty)))
892
893 return Size;
894 }
895
896
897 case MemRegion::BlockDataRegionKind:
898 case MemRegion::BlockCodeRegionKind:
899 case MemRegion::FunctionCodeRegionKind:
901 default:
902 llvm_unreachable("Unhandled region");
903 }
904}
905
906template
907const REG *MemRegionManager::LazyAllocate(REG*& region) {
908 if (!region) {
909 region = new (A) REG(*this);
910 }
911
912 return region;
913}
914
915template <typename REG, typename ARG>
916const REG *MemRegionManager::LazyAllocate(REG*& region, ARG a) {
917 if (!region) {
918 region = new (A) REG(this, a);
919 }
920
921 return region;
922}
923
926 assert(STC);
928
929 if (R)
930 return R;
931
933 return R;
934}
935
938 assert(STC);
940
941 if (R)
942 return R;
943
945 return R;
946}
947
951 if (!CR) {
952 if (K == MemRegion::GlobalSystemSpaceRegionKind)
953 return LazyAllocate(SystemGlobals);
954 if (K == MemRegion::GlobalImmutableSpaceRegionKind)
955 return LazyAllocate(ImmutableGlobals);
956 assert(K == MemRegion::GlobalInternalSpaceRegionKind);
957 return LazyAllocate(InternalGlobals);
958 }
959
960 assert(K == MemRegion::StaticGlobalSpaceRegionKind);
962 if (R)
963 return R;
964
966 return R;
967}
968
970 return LazyAllocate(heap);
971}
972
974 return LazyAllocate(unknown);
975}
976
978 return LazyAllocate(code);
979}
980
981
982
983
984
986 return getSubRegion(
988}
989
992 return getSubRegion(
994}
995
996
997
998
999static llvm::PointerUnion<const StackFrameContext *, const VarRegion *>
1003 while (LC) {
1004 if (const auto *SFC = dyn_cast(LC)) {
1006 return SFC;
1007 }
1008 if (const auto *BC = dyn_cast(LC)) {
1009 const auto *BR = static_cast<const BlockDataRegion *>(BC->getData());
1010
1011 for (auto Var : BR->referenced_vars()) {
1013 if (const auto *VR = dyn_cast(OrigR)) {
1014 if (VR->getDecl() == VD)
1016 }
1017 }
1018 }
1019
1021 }
1023}
1024
1027 if (!II)
1028 return false;
1030 return false;
1031 StringRef N = II->getName();
1033 if (FILETy.isNull())
1034 return false;
1038 (N == "stdin" || N == "stdout" || N == "stderr");
1039}
1040
1043 const auto *PVD = dyn_cast(D);
1044 if (PVD) {
1045 unsigned Index = PVD->getFunctionScopeIndex();
1048 if (CallSite) {
1050 if (const auto *FD = dyn_cast(D)) {
1051 if (Index < FD->param_size() && FD->parameters()[Index] == PVD)
1052 return getSubRegion(cast(CallSite), Index,
1054 } else if (const auto *BD = dyn_cast(D)) {
1055 if (Index < BD->param_size() && BD->parameters()[Index] == PVD)
1056 return getSubRegion(cast(CallSite), Index,
1058 } else {
1059 return getSubRegion(cast(CallSite), Index,
1061 }
1062 }
1063 }
1064
1066 const MemRegion *sReg = nullptr;
1067
1070 assert(!Ty.isNull());
1072 sReg = getGlobalsRegion(MemRegion::GlobalImmutableSpaceRegionKind);
1073 } else {
1074
1075
1076
1077
1078
1079 if (Ctx.getSourceManager().isInSystemHeader(D->getLocation()) &&
1081 sReg = getGlobalsRegion(MemRegion::GlobalSystemSpaceRegionKind);
1082 } else {
1083 sReg = getGlobalsRegion(MemRegion::GlobalInternalSpaceRegionKind);
1084 }
1085 }
1086
1087
1088 } else {
1089
1090
1092 llvm::PointerUnion<const StackFrameContext *, const VarRegion *> V =
1094
1095 if (const auto *VR = dyn_cast_if_present<const VarRegion *>(V))
1096 return VR;
1097
1099
1100 if (!STC) {
1101
1102
1104 } else {
1106 sReg =
1110 }
1111 else {
1113 const Decl *STCD = STC->getDecl();
1115 sReg = getGlobalsRegion(MemRegion::StaticGlobalSpaceRegionKind,
1117 else if (const auto *BD = dyn_cast(STCD)) {
1118
1119
1120
1121
1124 T = TSI->getType();
1125 if (T.isNull())
1130 }
1132
1135 STC->getAnalysisDeclContext());
1136 sReg = getGlobalsRegion(MemRegion::StaticGlobalSpaceRegionKind,
1137 BTR);
1138 }
1139 else {
1141 }
1142 }
1143 }
1144 }
1145
1147}
1148
1152
1155 D = Def;
1156 return getSubRegion(D, superR);
1157}
1158
1163 assert(SFC);
1164 return getSubRegion(OriginExpr, Index,
1166}
1167
1171 unsigned blockCount) {
1175
1176 sReg = getGlobalsRegion(MemRegion::GlobalImmutableSpaceRegionKind);
1177 }
1178 else {
1179 bool IsArcManagedBlock = Ctx.getLangOpts().ObjCAutoRefCount;
1180
1181
1182
1183
1184 if (!IsArcManagedBlock && LC) {
1185
1186
1188 assert(STC);
1190 } else {
1191
1192
1194 }
1195 }
1196
1197 return getSubRegion(BC, LC, blockCount, sReg);
1198}
1199
1204
1205 if (CL->isFileScope())
1207 else {
1209 assert(STC);
1211 }
1212
1213 return getSubRegion(CL, sReg);
1214}
1215
1220 QualType T = Ctx.getCanonicalType(elementType).getUnqualifiedType();
1221
1222
1223
1224
1229 T = Ctx.getQualifiedType(T, Quals);
1230 }
1231
1232 llvm::FoldingSetNodeID ID;
1233 ElementRegion::ProfileRegion(ID, T, Idx, superRegion);
1234
1235 void *InsertPos;
1236 MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
1237 auto *R = cast_or_null(data);
1238
1239 if (!R) {
1241 Regions.InsertNode(R, InsertPos);
1242 }
1243
1244 return R;
1245}
1246
1249
1250 return getSubRegion(FD, getCodeRegion());
1251}
1252
1256 return getSubRegion(BD, locTy, AC, getCodeRegion());
1257}
1258
1262 if (MemSpace == nullptr)
1264 return getSubRegion(sym, MemSpace);
1265}
1266
1268 return getSubRegion(Sym, getHeapRegion());
1269}
1270
1274 return getSubRegion(FD->getCanonicalDecl(), SuperRegion);
1275}
1276
1280 return getSubRegion(d, superRegion);
1281}
1282
1290
1295 assert(SFC);
1296 return getSubRegion(
1298}
1299
1303 return getSubRegion(
1304 Ex, VD,
1305 getGlobalsRegion(MemRegion::GlobalInternalSpaceRegionKind, nullptr));
1306}
1307
1308
1309
1312 bool IsVirtual) {
1313 BaseClass = BaseClass->getCanonicalDecl();
1314
1316 if (!Class)
1317 return true;
1318
1319 if (IsVirtual)
1321
1322 for (const auto &I : Class->bases()) {
1323 if (I.getType()->getAsCXXRecordDecl()->getCanonicalDecl() == BaseClass)
1324 return true;
1325 }
1326
1327 return false;
1328}
1329
1333 bool IsVirtual) {
1337
1338 if (IsVirtual) {
1339
1340
1341 while (const auto *Base = dyn_cast(Super))
1344 }
1345 }
1346
1347 return getSubRegion(RD, IsVirtual, Super);
1348}
1349
1353 return getSubRegion(RD, Super);
1354}
1355
1360 assert(PT);
1361
1362
1363 const auto *D = dyn_cast(LC->getDecl());
1364
1365
1366
1367 while (!LC->inTopFrame() && (!D || D->isStatic() ||
1368 PT != D->getThisType()->getAs<PointerType>())) {
1370 D = dyn_cast(LC->getDecl());
1371 }
1373 assert(STC);
1375}
1376
1384
1387 const auto *SR = dyn_cast(this);
1388
1389 while (SR) {
1390 R = SR->getSuperRegion();
1391 SR = dyn_cast(R);
1392 }
1393
1395}
1396
1399
1402 return RawSpace;
1403
1404 const MemSpaceRegion *const *AssociatedSpace = State->get(MR);
1405 return AssociatedSpace ? *AssociatedSpace : RawSpace;
1406}
1407
1411
1412
1414
1415
1417 return State->set(Base, Space);
1418}
1419
1420
1421
1424 while (true) {
1426 case MemRegion::ElementRegionKind:
1427 case MemRegion::FieldRegionKind:
1428 case MemRegion::ObjCIvarRegionKind:
1429 case MemRegion::CXXBaseObjectRegionKind:
1430 case MemRegion::CXXDerivedObjectRegionKind:
1432 continue;
1433 default:
1434 break;
1435 }
1436 break;
1437 }
1438 return R;
1439}
1440
1441
1444 while (const auto *BR = dyn_cast(R))
1445 R = BR->getSuperRegion();
1446 return R;
1447}
1448
1452
1453
1454
1455
1456
1459 while (true) {
1461 case ElementRegionKind: {
1463 if (!ER->getIndex().isZeroConstant())
1464 return R;
1465 R = ER->getSuperRegion();
1466 break;
1467 }
1468 case CXXBaseObjectRegionKind:
1469 case CXXDerivedObjectRegionKind:
1470 if (!StripBaseAndDerivedCasts)
1471 return R;
1473 break;
1474 default:
1475 return R;
1476 }
1477 }
1478}
1479
1481 const auto *SubR = dyn_cast(this);
1482
1483 while (SubR) {
1484 if (const auto *SymR = dyn_cast(SubR))
1485 return SymR;
1486 SubR = dyn_cast(SubR->getSuperRegion());
1487 }
1488 return nullptr;
1489}
1490
1492 int64_t offset = 0;
1493 const ElementRegion *ER = this;
1494 const MemRegion *superR = nullptr;
1496
1497
1498
1499 while (ER) {
1501
1502
1505
1506 if (int64_t i = CI->getValue()->getSExtValue(); i != 0) {
1508
1509
1511 superR = ER;
1512 break;
1513 }
1514
1515 int64_t size = C.getTypeSizeInChars(elemType).getQuantity();
1516 if (auto NewOffset = llvm::checkedMulAdd(i, size, offset)) {
1517 offset = *NewOffset;
1518 } else {
1519 LLVM_DEBUG(llvm::dbgs() << "MemRegion::getAsArrayOffset: "
1520 << "offset overflowing, returning unknown\n");
1521
1522 return nullptr;
1523 }
1524 }
1525
1526
1527 ER = dyn_cast(superR);
1528 continue;
1529 }
1530
1531 return nullptr;
1532 }
1533
1534 assert(superR && "super region cannot be NULL");
1536}
1537
1538
1541 assert(Child && "Child must not be null");
1542
1543
1544
1545 for (const auto &I : Child->bases()) {
1546 if (I.getType()->getAsCXXRecordDecl() == Base)
1547 return true;
1548 }
1549
1550 return false;
1551}
1552
1554 const MemRegion *SymbolicOffsetBase = nullptr;
1555 int64_t Offset = 0;
1556
1557 while (true) {
1559 case MemRegion::CodeSpaceRegionKind:
1560 case MemRegion::StackLocalsSpaceRegionKind:
1561 case MemRegion::StackArgumentsSpaceRegionKind:
1562 case MemRegion::HeapSpaceRegionKind:
1563 case MemRegion::UnknownSpaceRegionKind:
1564 case MemRegion::StaticGlobalSpaceRegionKind:
1565 case MemRegion::GlobalInternalSpaceRegionKind:
1566 case MemRegion::GlobalSystemSpaceRegionKind:
1567 case MemRegion::GlobalImmutableSpaceRegionKind:
1568
1569 assert(Offset == 0 && !SymbolicOffsetBase);
1570 goto Finish;
1571
1572 case MemRegion::FunctionCodeRegionKind:
1573 case MemRegion::BlockCodeRegionKind:
1574 case MemRegion::BlockDataRegionKind:
1575
1576
1577 if (Offset != 0)
1578 SymbolicOffsetBase = R;
1579 goto Finish;
1580
1581 case MemRegion::SymbolicRegionKind:
1582 case MemRegion::AllocaRegionKind:
1583 case MemRegion::CompoundLiteralRegionKind:
1584 case MemRegion::CXXThisRegionKind:
1585 case MemRegion::StringRegionKind:
1586 case MemRegion::ObjCStringRegionKind:
1587 case MemRegion::NonParamVarRegionKind:
1588 case MemRegion::ParamVarRegionKind:
1589 case MemRegion::CXXTempObjectRegionKind:
1590 case MemRegion::CXXLifetimeExtendedObjectRegionKind:
1591
1592 goto Finish;
1593
1594 case MemRegion::ObjCIvarRegionKind:
1595
1596
1597
1598
1599
1600 goto Finish;
1601
1602 case MemRegion::CXXBaseObjectRegionKind: {
1604 R = BOR->getSuperRegion();
1605
1607 bool RootIsSymbolic = false;
1608 if (const auto *TVR = dyn_cast(R)) {
1609 Ty = TVR->getDesugaredValueType(R->getContext());
1610 } else if (const auto *SR = dyn_cast(R)) {
1611
1612
1613
1614 Ty = SR->getPointeeStaticType();
1615 RootIsSymbolic = true;
1616 }
1617
1619 if (!Child) {
1620
1621 SymbolicOffsetBase = R;
1622 } else {
1623 if (RootIsSymbolic) {
1624
1625
1626
1627 if (BOR->isVirtual()) {
1628 if (!Child->isVirtuallyDerivedFrom(BOR->getDecl()))
1629 SymbolicOffsetBase = R;
1630 } else {
1632 SymbolicOffsetBase = R;
1633 }
1634 }
1635 }
1636
1637
1638
1639 if (SymbolicOffsetBase)
1640 continue;
1641
1644 if (BOR->isVirtual())
1646 else
1648
1649
1651 break;
1652 }
1653
1654 case MemRegion::CXXDerivedObjectRegionKind: {
1655
1656 goto Finish;
1657 }
1658
1659 case MemRegion::ElementRegionKind: {
1661 R = ER->getSuperRegion();
1662
1663 QualType EleTy = ER->getValueType();
1665
1666 SymbolicOffsetBase = R;
1667 continue;
1668 }
1669
1670 SVal Index = ER->getIndex();
1671 if (std::optionalnonloc::ConcreteInt CI =
1673
1674
1675 if (SymbolicOffsetBase)
1676 continue;
1677
1678 int64_t i = CI->getValue()->getSExtValue();
1679
1681 } else {
1682
1683 SymbolicOffsetBase = R;
1684 }
1685 break;
1686 }
1687 case MemRegion::FieldRegionKind: {
1689 R = FR->getSuperRegion();
1690 assert(R);
1691
1694
1695
1696
1697
1698
1699 SymbolicOffsetBase = R;
1700 }
1701
1702
1703
1704 if (SymbolicOffsetBase)
1705 continue;
1706
1707 assert(FR->getDecl()->getCanonicalDecl() == FR->getDecl());
1708 auto MaybeFieldIdx = [FR, RD]() -> std::optional {
1709 for (auto [Idx, Field] : llvm::enumerate(RD->fields())) {
1710 if (FR->getDecl() == Field->getCanonicalDecl())
1711 return Idx;
1712 }
1713 return std::nullopt;
1714 }();
1715
1716 if (!MaybeFieldIdx.has_value()) {
1717 assert(false && "Field not found");
1718 goto Finish;
1719 }
1720
1722
1723 Offset += Layout.getFieldOffset(MaybeFieldIdx.value());
1724 break;
1725 }
1726 }
1727 }
1728
1729 Finish:
1730 if (SymbolicOffsetBase)
1733}
1734
1736 if (!cachedOffset)
1738 return *cachedOffset;
1739}
1740
1741
1742
1743
1744
1745std::pair<const VarRegion *, const VarRegion *>
1746BlockDataRegion::getCaptureRegions(const VarDecl *VD) {
1749 const VarRegion *OriginalVR = nullptr;
1750
1754 }
1755 else {
1756 if (LC) {
1758 OriginalVR = VR;
1759 }
1760 else {
1763 }
1764 }
1765 return std::make_pair(VR, OriginalVR);
1766}
1767
1768void BlockDataRegion::LazyInitializeReferencedVars() {
1769 if (ReferencedVars)
1770 return;
1771
1774 auto NumBlockVars =
1775 std::distance(ReferencedBlockVars.begin(), ReferencedBlockVars.end());
1776
1777 if (NumBlockVars == 0) {
1778 ReferencedVars = (void*) 0x1;
1779 return;
1780 }
1781
1783 llvm::BumpPtrAllocator &A = MemMgr.getAllocator();
1784 BumpVectorContext BC(A);
1785
1786 using VarVec = BumpVector<const MemRegion *>;
1787
1788 auto *BV = new (A) VarVec(BC, NumBlockVars);
1789 auto *BVOriginal = new (A) VarVec(BC, NumBlockVars);
1790
1791 for (const auto *VD : ReferencedBlockVars) {
1792 const VarRegion *VR = nullptr;
1793 const VarRegion *OriginalVR = nullptr;
1794 std::tie(VR, OriginalVR) = getCaptureRegions(VD);
1795 assert(VR);
1796 assert(OriginalVR);
1797 BV->push_back(VR, BC);
1798 BVOriginal->push_back(OriginalVR, BC);
1799 }
1800
1801 ReferencedVars = BV;
1802 OriginalVars = BVOriginal;
1803}
1804
1807 const_cast<BlockDataRegion*>(this)->LazyInitializeReferencedVars();
1808
1810
1811 if (Vec == (void*) 0x1)
1813
1814 auto *VecOriginal =
1816
1818 VecOriginal->begin());
1819}
1820
1823 const_cast<BlockDataRegion*>(this)->LazyInitializeReferencedVars();
1824
1826
1827 if (Vec == (void*) 0x1)
1829
1830 auto *VecOriginal =
1832
1834 VecOriginal->end());
1835}
1836
1837llvm::iterator_rangeBlockDataRegion::referenced\_vars\_iterator
1841
1844 if (I.getCapturedRegion() == R)
1845 return I.getOriginalRegion();
1846 }
1847 return nullptr;
1848}
1849
1850
1851
1852
1853
1856 SymTraitsMap[Sym] |= IK;
1857}
1858
1861 assert(MR);
1862 if (const auto *SR = dyn_cast(MR))
1863 setTrait(SR->getSymbol(), IK);
1864 else
1865 MRTraitsMap[MR] |= IK;
1866}
1867
1870 const_symbol_iterator I = SymTraitsMap.find(Sym);
1871 if (I != SymTraitsMap.end())
1872 return I->second & IK;
1873
1874 return false;
1875}
1876
1879 if (!MR)
1880 return false;
1881
1882 if (const auto *SR = dyn_cast(MR))
1883 return hasTrait(SR->getSymbol(), IK);
1884
1885 const_region_iterator I = MRTraitsMap.find(MR);
1886 if (I != MRTraitsMap.end())
1887 return I->second & IK;
1888
1889 return false;
1890}
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 bool isStdStreamVar(const VarDecl *D)
Definition MemRegion.cpp:1025
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...
Definition MemRegion.cpp:1000
static bool isImmediateBase(const CXXRecordDecl *Child, const CXXRecordDecl *Base)
Returns true if Base is an immediate base class of Child.
Definition MemRegion.cpp:1539
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.
Definition MemRegion.cpp:1310
static RegionOffset calculateOffset(const MemRegion *R)
Definition MemRegion.cpp:1553
#define REGISTER_MAP_WITH_PROGRAMSTATE(Name, Key, Value)
Declares an immutable map of type NameTy, suitable for placement into the ProgramState.
Defines the SourceManager interface.
C Language Family Type Representation.
__device__ __2f16 float __ockl_bool s
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
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,...
QualType getFILEType() const
Retrieve the C FILE type.
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.
CanQualType getCanonicalTagType(const TagDecl *TD) const
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)
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.
bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const
Determine whether this class is virtually derived from the class Base.
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].
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.
bool isTranslationUnit() const
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
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.
FieldDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this field.
FunctionType - C99 6.7.5.3 - Function Declarators.
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
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.
LangAS getAddressSpace() const
Return the address space of this type.
QualType getCanonicalType() const
bool isConstQualified() const
Determine whether this type is const-qualified.
The collection of all-type qualifiers we support.
void setAddressSpace(LangAS space)
Represents a struct/union/class.
field_range fields() const
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.
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 isPointerType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
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'.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
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.
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
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
Definition MemRegion.cpp:489
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:272
BlockCodeRegion - A region that represents code texts of blocks (closures).
LLVM_ATTRIBUTE_RETURNS_NONNULL AnalysisDeclContext * getAnalysisDeclContext() const
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:497
LLVM_ATTRIBUTE_RETURNS_NONNULL const BlockDecl * getDecl() const
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:383
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.
Definition MemRegion.cpp:1842
referenced_vars_iterator referenced_vars_begin() const
Definition MemRegion.cpp:1806
LLVM_ATTRIBUTE_RETURNS_NONNULL const BlockCodeRegion * getCodeRegion() const
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:399
referenced_vars_iterator referenced_vars_end() const
Definition MemRegion.cpp:1822
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:501
friend class MemRegionManager
llvm::iterator_range< referenced_vars_iterator > referenced_vars() const
Definition MemRegion.cpp:1838
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
Definition MemRegion.cpp:715
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.
Definition MemRegion.cpp:711
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:437
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:530
QualType getValueType() const override
Definition MemRegion.cpp:194
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
Definition MemRegion.cpp:723
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:448
QualType getValueType() const override
Definition MemRegion.cpp:198
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:534
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression.
Definition MemRegion.cpp:719
LLVM_ATTRIBUTE_RETURNS_NONNULL const CXXRecordDecl * getDecl() const
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:423
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:520
const StackFrameContext * getStackFrame() const
It might return null.
Definition MemRegion.cpp:172
QualType getValueType() const override
QualType getValueType() const override
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:410
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:515
LLVM_ATTRIBUTE_RETURNS_NONNULL const StackFrameContext * getStackFrame() const
Definition MemRegion.cpp:177
CXXThisRegion - Represents the region for the implicit 'this' parameter in a call to a C++ method.
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:296
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:538
CodeSpaceRegion - The memory space that holds the executable code of functions and blocks.
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:586
CompoundLiteralRegion - A memory region representing a compound literal.
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:276
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:510
ElementRegion is used to represent both array elements and casts.
QualType getElementType() const
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:360
RegionRawOffset getAsArrayOffset() const
Compute the offset within the array. The array might also be a subobject.
Definition MemRegion.cpp:1491
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:542
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
Definition MemRegion.cpp:695
bool canPrintPretty() const override
Returns true if this region can be printed in a user-friendly way.
Definition MemRegion.cpp:687
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression.
Definition MemRegion.cpp:691
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:547
void printPretty(raw_ostream &os) const override
Print the region for use in diagnostics.
Definition MemRegion.cpp:701
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:300
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
Definition MemRegion.cpp:493
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:371
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:602
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:594
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:598
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:606
const HeapSpaceRegion * getHeapRegion()
getHeapRegion - Retrieve the memory region associated with the generic "heap".
Definition MemRegion.cpp:969
const StackArgumentsSpaceRegion * getStackArgumentsRegion(const StackFrameContext *STC)
getStackArgumentsRegion - Retrieve the memory region associated with function/method arguments of the...
Definition MemRegion.cpp:937
const CXXThisRegion * getCXXThisRegion(QualType thisPointerTy, const LocationContext *LC)
getCXXThisRegion - Retrieve the [artificial] region associated with the parameter 'this'.
Definition MemRegion.cpp:1357
llvm::BumpPtrAllocator & getAllocator()
const FieldRegion * getFieldRegion(const FieldDecl *FD, const SubRegion *SuperRegion)
getFieldRegion - Retrieve or create the memory region associated with a specified FieldDecl.
Definition MemRegion.cpp:1272
const BlockCodeRegion * getBlockCodeRegion(const BlockDecl *BD, CanQualType locTy, AnalysisDeclContext *AC)
Definition MemRegion.cpp:1254
const UnknownSpaceRegion * getUnknownRegion()
getUnknownRegion - Retrieve the memory region associated with unknown memory space.
Definition MemRegion.cpp:973
const CXXDerivedObjectRegion * getCXXDerivedObjectRegion(const CXXRecordDecl *BaseClass, const SubRegion *Super)
Create a CXXDerivedObjectRegion with the given derived class for region Super.
Definition MemRegion.cpp:1351
const CompoundLiteralRegion * getCompoundLiteralRegion(const CompoundLiteralExpr *CL, const LocationContext *LC)
getCompoundLiteralRegion - Retrieve the region associated with a given CompoundLiteral.
Definition MemRegion.cpp:1201
const AllocaRegion * getAllocaRegion(const Expr *Ex, unsigned Cnt, const LocationContext *LC)
getAllocaRegion - Retrieve a region associated with a call to alloca().
Definition MemRegion.cpp:1378
const ElementRegion * getElementRegion(QualType elementType, NonLoc Idx, const SubRegion *superRegion, const ASTContext &Ctx)
getElementRegion - Retrieve the memory region associated with the associated element type,...
Definition MemRegion.cpp:1217
const VarRegion * getVarRegion(const VarDecl *VD, const LocationContext *LC)
getVarRegion - Retrieve or create the memory region associated with a specified VarDecl and LocationC...
Definition MemRegion.cpp:1041
const NonParamVarRegion * getNonParamVarRegion(const VarDecl *VD, const MemRegion *superR)
getVarRegion - Retrieve or create the memory region associated with a specified VarDecl and LocationC...
Definition MemRegion.cpp:1150
const StackLocalsSpaceRegion * getStackLocalsRegion(const StackFrameContext *STC)
getStackLocalsRegion - Retrieve the memory region associated with the specified stack frame.
Definition MemRegion.cpp:925
const ObjCIvarRegion * getObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *superRegion)
getObjCIvarRegion - Retrieve or create the memory region associated with a specified Objective-c inst...
Definition MemRegion.cpp:1278
const SymbolicRegion * getSymbolicHeapRegion(SymbolRef sym)
Return a unique symbolic region belonging to heap memory space.
Definition MemRegion.cpp:1267
const ObjCStringRegion * getObjCStringRegion(const ObjCStringLiteral *Str)
Definition MemRegion.cpp:991
const StringRegion * getStringRegion(const StringLiteral *Str)
Definition MemRegion.cpp:985
ASTContext & getContext()
DefinedOrUnknownSVal getStaticSize(const MemRegion *MR, SValBuilder &SVB) const
Definition MemRegion.cpp:807
const ParamVarRegion * getParamVarRegion(const Expr *OriginExpr, unsigned Index, const LocationContext *LC)
getParamVarRegion - Retrieve or create the memory region associated with a specified CallExpr,...
Definition MemRegion.cpp:1160
const CodeSpaceRegion * getCodeRegion()
Definition MemRegion.cpp:977
const CXXLifetimeExtendedObjectRegion * getCXXLifetimeExtendedObjectRegion(Expr const *Ex, ValueDecl const *VD, LocationContext const *LC)
Create a CXXLifetimeExtendedObjectRegion for temporaries which are lifetime-extended by local referen...
Definition MemRegion.cpp:1292
const CXXTempObjectRegion * getCXXTempObjectRegion(Expr const *Ex, LocationContext const *LC)
Definition MemRegion.cpp:1284
const GlobalsSpaceRegion * getGlobalsRegion(MemRegion::Kind K=MemRegion::GlobalInternalSpaceRegionKind, const CodeTextRegion *R=nullptr)
getGlobalsRegion - Retrieve the memory region associated with global variables.
Definition MemRegion.cpp:949
const SymbolicRegion * getSymbolicRegion(SymbolRef Sym, const MemSpaceRegion *MemSpace=nullptr)
Retrieve or create a "symbolic" memory region.
Definition MemRegion.cpp:1260
const FunctionCodeRegion * getFunctionCodeRegion(const NamedDecl *FD)
Definition MemRegion.cpp:1248
const BlockDataRegion * getBlockDataRegion(const BlockCodeRegion *bc, const LocationContext *lc, unsigned blockCount)
getBlockDataRegion - Get the memory region associated with an instance of a block.
Definition MemRegion.cpp:1169
const CXXBaseObjectRegion * getCXXBaseObjectRegion(const CXXRecordDecl *BaseClass, const SubRegion *Super, bool IsVirtual)
Create a CXXBaseObjectRegion with the given base class for region Super.
Definition MemRegion.cpp:1331
const CXXLifetimeExtendedObjectRegion * getCXXStaticLifetimeExtendedObjectRegion(const Expr *Ex, ValueDecl const *VD)
Create a CXXLifetimeExtendedObjectRegion for temporaries which are lifetime-extended by static refere...
Definition MemRegion.cpp:1301
MemRegion - The root abstract class for all memory regions.
void dump() const
Definition MemRegion.cpp:474
virtual bool canPrintPrettyAsExpr() const
Returns true if this region's textual representation can be used as part of a larger expression.
Definition MemRegion.cpp:638
StringRef getKindStr() const
Definition MemRegion.cpp:642
RegionOffset getAsOffset() const
Compute the offset within the top level memory object.
Definition MemRegion.cpp:1735
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * StripCasts(bool StripBaseAndDerivedCasts=true) const
Definition MemRegion.cpp:1457
ProgramStateRef setMemorySpace(ProgramStateRef State, const MemSpaceRegion *Space) const
Set the dynamically deduced memory space of a MemRegion that currently has UnknownSpaceRegion.
Definition MemRegion.cpp:1408
ASTContext & getContext() const
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemSpaceRegion * getMemorySpace(ProgramStateRef State) const
Returns the most specific memory space for this memory region in the given ProgramStateRef.
Definition MemRegion.cpp:1397
std::string getDescriptiveName(bool UseQuotes=true) const
Get descriptive name for memory region.
Definition MemRegion.cpp:727
virtual bool isSubRegionOf(const MemRegion *R) const
Check if the region is a subregion of the given region.
Definition MemRegion.cpp:1449
virtual void dumpToStream(raw_ostream &os) const
Definition MemRegion.cpp:485
const SymbolicRegion * getSymbolicBase() const
If this is a symbolic region, returns the region.
Definition MemRegion.cpp:1480
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemRegion * getBaseRegion() const
Definition MemRegion.cpp:1422
virtual void printPretty(raw_ostream &os) const
Print the region for use in diagnostics.
Definition MemRegion.cpp:653
virtual void printPrettyAsExpr(raw_ostream &os) const
Print the region as expression.
Definition MemRegion.cpp:660
std::string getString() const
Get a string representation of a region for debug use.
Definition MemRegion.cpp:478
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...
Definition MemRegion.cpp:1442
LLVM_ATTRIBUTE_RETURNS_NONNULL const MemSpaceRegion * getRawMemorySpace() const
Deprecated.
Definition MemRegion.cpp:1385
virtual bool canPrintPretty() const
Returns true if this region can be printed in a user-friendly way.
Definition MemRegion.cpp:634
SourceRange sourceRange() const
Retrieve source range from memory region.
Definition MemRegion.cpp:789
MemSpaceRegion - A memory region that represents a "memory space"; for example, the set of global var...
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:233
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression.
Definition MemRegion.cpp:664
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:324
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
Definition MemRegion.cpp:666
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:571
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.
Definition MemRegion.cpp:679
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:312
QualType getValueType() const override
Definition MemRegion.cpp:190
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
Definition MemRegion.cpp:683
LLVM_ATTRIBUTE_RETURNS_NONNULL const ObjCIvarDecl * getDecl() const override
Definition MemRegion.cpp:188
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:551
The region associated with an ObjCStringLiteral.
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:560
ParamVarRegion - Represents a region for parameters.
bool canPrintPrettyAsExpr() const override
Returns true if this region's textual representation can be used as part of a larger expression.
Definition MemRegion.cpp:670
LLVM_ATTRIBUTE_RETURNS_NONNULL const Expr * getOriginExpr() const
const ParmVarDecl * getDecl() const override
TODO: What does this return?
Definition MemRegion.cpp:209
unsigned getIndex() const
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:336
QualType getValueType() const override
Definition MemRegion.cpp:202
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:622
void printPrettyAsExpr(raw_ostream &os) const override
Print the region as expression.
Definition MemRegion.cpp:672
InvalidationKinds
Describes different invalidation traits.
bool hasTrait(SymbolRef Sym, InvalidationKinds IK) const
Definition MemRegion.cpp:1868
void setTrait(SymbolRef Sym, InvalidationKinds IK)
Definition MemRegion.cpp:1854
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
Definition MemRegion.cpp:582
void dump() const
Definition MemRegion.cpp:578
const MemRegion * getRegion() const
nonloc::ConcreteInt makeIntVal(const IntegerLiteral *integer)
QualType getArrayIndexType() 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
Definition MemRegion.cpp:614
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:618
LLVM_ATTRIBUTE_RETURNS_NONNULL const StackFrameContext * getStackFrame() const
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:237
The region of the static variables within the current CodeTextRegion scope.
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:242
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:590
LLVM_ATTRIBUTE_RETURNS_NONNULL const CodeTextRegion * getCodeRegion() const
StringRegion - Region associated with a StringLiteral.
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:555
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.
Definition MemRegion.cpp:141
SubRegion(const MemRegion *sReg, Kind k)
const MemRegion * superRegion
MemRegionManager & getMemRegionManager() const override
Definition MemRegion.cpp:154
SymbolExtent - Represents the extent (size in bytes) of a bounded region.
const SymExprT * acquire(Args &&...args)
Create or retrieve a SymExpr of type SymExprT for the given arguments.
SymbolicRegion - A special, "non-concrete" region.
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:565
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition MemRegion.cpp:347
static void ProfileRegion(llvm::FoldingSetNodeID &ID, SymbolRef sym, const MemRegion *superRegion)
Definition MemRegion.cpp:340
TypedValueRegion - An abstract class representing regions having a typed value.
virtual QualType getValueType() const =0
void dumpToStream(raw_ostream &os) const override
Definition MemRegion.cpp:610
const StackFrameContext * getStackFrame() const
It might return null.
Definition MemRegion.cpp:166
Value representing integer constant.
Represents symbolic expression that isn't a location.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
const SymExpr * SymbolRef
DefinedOrUnknownSVal getElementExtent(QualType Ty, SValBuilder &SVB)
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool isa(CodeGen::Address addr)
const FunctionProtoType * T
LangAS
Defines the address space values used by the address space qualifier of QualType.
U cast(CodeGen::Address addr)
Extra information about a function prototype.
Describes how types, statements, expressions, and declarations should be printed.