1 //== MemRegion.cpp - Abstract memory regions for static analysis --*- C++ -*--//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines MemRegion and its subclasses. MemRegion defines a
11 // partially-typed abstraction of memory useful for path-sensitive dataflow
14 //===----------------------------------------------------------------------===//
16 #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
17 #include "clang/AST/Attr.h"
18 #include "clang/AST/CharUnits.h"
19 #include "clang/AST/DeclObjC.h"
20 #include "clang/AST/RecordLayout.h"
21 #include "clang/Analysis/AnalysisContext.h"
22 #include "clang/Analysis/Support/BumpVector.h"
23 #include "clang/Basic/SourceManager.h"
24 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
25 #include "llvm/Support/raw_ostream.h"
27 using namespace clang;
30 //===----------------------------------------------------------------------===//
31 // MemRegion Construction.
32 //===----------------------------------------------------------------------===//
34 template<typename RegionTy> struct MemRegionManagerTrait;
36 template <typename RegionTy, typename A1>
37 RegionTy* MemRegionManager::getRegion(const A1 a1) {
39 const typename MemRegionManagerTrait<RegionTy>::SuperRegionTy *superRegion =
40 MemRegionManagerTrait<RegionTy>::getSuperRegion(*this, a1);
42 llvm::FoldingSetNodeID ID;
43 RegionTy::ProfileRegion(ID, a1, superRegion);
45 RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID,
49 R = (RegionTy*) A.Allocate<RegionTy>();
50 new (R) RegionTy(a1, superRegion);
51 Regions.InsertNode(R, InsertPos);
57 template <typename RegionTy, typename A1>
58 RegionTy* MemRegionManager::getSubRegion(const A1 a1,
59 const MemRegion *superRegion) {
60 llvm::FoldingSetNodeID ID;
61 RegionTy::ProfileRegion(ID, a1, superRegion);
63 RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID,
67 R = (RegionTy*) A.Allocate<RegionTy>();
68 new (R) RegionTy(a1, superRegion);
69 Regions.InsertNode(R, InsertPos);
75 template <typename RegionTy, typename A1, typename A2>
76 RegionTy* MemRegionManager::getRegion(const A1 a1, const A2 a2) {
78 const typename MemRegionManagerTrait<RegionTy>::SuperRegionTy *superRegion =
79 MemRegionManagerTrait<RegionTy>::getSuperRegion(*this, a1, a2);
81 llvm::FoldingSetNodeID ID;
82 RegionTy::ProfileRegion(ID, a1, a2, superRegion);
84 RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID,
88 R = (RegionTy*) A.Allocate<RegionTy>();
89 new (R) RegionTy(a1, a2, superRegion);
90 Regions.InsertNode(R, InsertPos);
96 template <typename RegionTy, typename A1, typename A2>
97 RegionTy* MemRegionManager::getSubRegion(const A1 a1, const A2 a2,
98 const MemRegion *superRegion) {
100 llvm::FoldingSetNodeID ID;
101 RegionTy::ProfileRegion(ID, a1, a2, superRegion);
103 RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID,
107 R = (RegionTy*) A.Allocate<RegionTy>();
108 new (R) RegionTy(a1, a2, superRegion);
109 Regions.InsertNode(R, InsertPos);
115 template <typename RegionTy, typename A1, typename A2, typename A3>
116 RegionTy* MemRegionManager::getSubRegion(const A1 a1, const A2 a2, const A3 a3,
117 const MemRegion *superRegion) {
119 llvm::FoldingSetNodeID ID;
120 RegionTy::ProfileRegion(ID, a1, a2, a3, superRegion);
122 RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID,
126 R = (RegionTy*) A.Allocate<RegionTy>();
127 new (R) RegionTy(a1, a2, a3, superRegion);
128 Regions.InsertNode(R, InsertPos);
134 //===----------------------------------------------------------------------===//
135 // Object destruction.
136 //===----------------------------------------------------------------------===//
138 MemRegion::~MemRegion() {}
140 MemRegionManager::~MemRegionManager() {
141 // All regions and their data are BumpPtrAllocated. No need to call
142 // their destructors.
145 //===----------------------------------------------------------------------===//
147 //===----------------------------------------------------------------------===//
149 bool SubRegion::isSubRegionOf(const MemRegion* R) const {
150 const MemRegion* r = getSuperRegion();
151 while (r != nullptr) {
154 if (const SubRegion* sr = dyn_cast<SubRegion>(r))
155 r = sr->getSuperRegion();
162 MemRegionManager* SubRegion::getMemRegionManager() const {
163 const SubRegion* r = this;
165 const MemRegion *superRegion = r->getSuperRegion();
166 if (const SubRegion *sr = dyn_cast<SubRegion>(superRegion)) {
170 return superRegion->getMemRegionManager();
174 const StackFrameContext *VarRegion::getStackFrame() const {
175 const StackSpaceRegion *SSR = dyn_cast<StackSpaceRegion>(getMemorySpace());
176 return SSR ? SSR->getStackFrame() : nullptr;
179 //===----------------------------------------------------------------------===//
181 //===----------------------------------------------------------------------===//
183 DefinedOrUnknownSVal TypedValueRegion::getExtent(SValBuilder &svalBuilder) const {
184 ASTContext &Ctx = svalBuilder.getContext();
185 QualType T = getDesugaredValueType(Ctx);
187 if (isa<VariableArrayType>(T))
188 return nonloc::SymbolVal(svalBuilder.getSymbolManager().getExtentSymbol(this));
189 if (T->isIncompleteType())
192 CharUnits size = Ctx.getTypeSizeInChars(T);
193 QualType sizeTy = svalBuilder.getArrayIndexType();
194 return svalBuilder.makeIntVal(size.getQuantity(), sizeTy);
197 DefinedOrUnknownSVal FieldRegion::getExtent(SValBuilder &svalBuilder) const {
198 // Force callers to deal with bitfields explicitly.
199 if (getDecl()->isBitField())
202 DefinedOrUnknownSVal Extent = DeclRegion::getExtent(svalBuilder);
204 // A zero-length array at the end of a struct often stands for dynamically-
205 // allocated extra memory.
206 if (Extent.isZeroConstant()) {
207 QualType T = getDesugaredValueType(svalBuilder.getContext());
209 if (isa<ConstantArrayType>(T))
216 DefinedOrUnknownSVal AllocaRegion::getExtent(SValBuilder &svalBuilder) const {
217 return nonloc::SymbolVal(svalBuilder.getSymbolManager().getExtentSymbol(this));
220 DefinedOrUnknownSVal SymbolicRegion::getExtent(SValBuilder &svalBuilder) const {
221 return nonloc::SymbolVal(svalBuilder.getSymbolManager().getExtentSymbol(this));
224 DefinedOrUnknownSVal StringRegion::getExtent(SValBuilder &svalBuilder) const {
225 return svalBuilder.makeIntVal(getStringLiteral()->getByteLength()+1,
226 svalBuilder.getArrayIndexType());
229 ObjCIvarRegion::ObjCIvarRegion(const ObjCIvarDecl *ivd, const MemRegion* sReg)
230 : DeclRegion(ivd, sReg, ObjCIvarRegionKind) {}
232 const ObjCIvarDecl *ObjCIvarRegion::getDecl() const {
233 return cast<ObjCIvarDecl>(D);
236 QualType ObjCIvarRegion::getValueType() const {
237 return getDecl()->getType();
240 QualType CXXBaseObjectRegion::getValueType() const {
241 return QualType(getDecl()->getTypeForDecl(), 0);
244 //===----------------------------------------------------------------------===//
245 // FoldingSet profiling.
246 //===----------------------------------------------------------------------===//
248 void MemSpaceRegion::Profile(llvm::FoldingSetNodeID& ID) const {
249 ID.AddInteger((unsigned)getKind());
252 void StackSpaceRegion::Profile(llvm::FoldingSetNodeID &ID) const {
253 ID.AddInteger((unsigned)getKind());
254 ID.AddPointer(getStackFrame());
257 void StaticGlobalSpaceRegion::Profile(llvm::FoldingSetNodeID &ID) const {
258 ID.AddInteger((unsigned)getKind());
259 ID.AddPointer(getCodeRegion());
262 void StringRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
263 const StringLiteral* Str,
264 const MemRegion* superRegion) {
265 ID.AddInteger((unsigned) StringRegionKind);
267 ID.AddPointer(superRegion);
270 void ObjCStringRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
271 const ObjCStringLiteral* Str,
272 const MemRegion* superRegion) {
273 ID.AddInteger((unsigned) ObjCStringRegionKind);
275 ID.AddPointer(superRegion);
278 void AllocaRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
279 const Expr *Ex, unsigned cnt,
280 const MemRegion *superRegion) {
281 ID.AddInteger((unsigned) AllocaRegionKind);
284 ID.AddPointer(superRegion);
287 void AllocaRegion::Profile(llvm::FoldingSetNodeID& ID) const {
288 ProfileRegion(ID, Ex, Cnt, superRegion);
291 void CompoundLiteralRegion::Profile(llvm::FoldingSetNodeID& ID) const {
292 CompoundLiteralRegion::ProfileRegion(ID, CL, superRegion);
295 void CompoundLiteralRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
296 const CompoundLiteralExpr *CL,
297 const MemRegion* superRegion) {
298 ID.AddInteger((unsigned) CompoundLiteralRegionKind);
300 ID.AddPointer(superRegion);
303 void CXXThisRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
304 const PointerType *PT,
305 const MemRegion *sRegion) {
306 ID.AddInteger((unsigned) CXXThisRegionKind);
308 ID.AddPointer(sRegion);
311 void CXXThisRegion::Profile(llvm::FoldingSetNodeID &ID) const {
312 CXXThisRegion::ProfileRegion(ID, ThisPointerTy, superRegion);
315 void ObjCIvarRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
316 const ObjCIvarDecl *ivd,
317 const MemRegion* superRegion) {
318 DeclRegion::ProfileRegion(ID, ivd, superRegion, ObjCIvarRegionKind);
321 void DeclRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, const Decl *D,
322 const MemRegion* superRegion, Kind k) {
323 ID.AddInteger((unsigned) k);
325 ID.AddPointer(superRegion);
328 void DeclRegion::Profile(llvm::FoldingSetNodeID& ID) const {
329 DeclRegion::ProfileRegion(ID, D, superRegion, getKind());
332 void VarRegion::Profile(llvm::FoldingSetNodeID &ID) const {
333 VarRegion::ProfileRegion(ID, getDecl(), superRegion);
336 void SymbolicRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, SymbolRef sym,
337 const MemRegion *sreg) {
338 ID.AddInteger((unsigned) MemRegion::SymbolicRegionKind);
343 void SymbolicRegion::Profile(llvm::FoldingSetNodeID& ID) const {
344 SymbolicRegion::ProfileRegion(ID, sym, getSuperRegion());
347 void ElementRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
348 QualType ElementType, SVal Idx,
349 const MemRegion* superRegion) {
350 ID.AddInteger(MemRegion::ElementRegionKind);
352 ID.AddPointer(superRegion);
356 void ElementRegion::Profile(llvm::FoldingSetNodeID& ID) const {
357 ElementRegion::ProfileRegion(ID, ElementType, Index, superRegion);
360 void FunctionTextRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
363 ID.AddInteger(MemRegion::FunctionTextRegionKind);
367 void FunctionTextRegion::Profile(llvm::FoldingSetNodeID& ID) const {
368 FunctionTextRegion::ProfileRegion(ID, FD, superRegion);
371 void BlockTextRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
372 const BlockDecl *BD, CanQualType,
373 const AnalysisDeclContext *AC,
375 ID.AddInteger(MemRegion::BlockTextRegionKind);
379 void BlockTextRegion::Profile(llvm::FoldingSetNodeID& ID) const {
380 BlockTextRegion::ProfileRegion(ID, BD, locTy, AC, superRegion);
383 void BlockDataRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
384 const BlockTextRegion *BC,
385 const LocationContext *LC,
387 const MemRegion *sReg) {
388 ID.AddInteger(MemRegion::BlockDataRegionKind);
391 ID.AddInteger(BlkCount);
395 void BlockDataRegion::Profile(llvm::FoldingSetNodeID& ID) const {
396 BlockDataRegion::ProfileRegion(ID, BC, LC, BlockCount, getSuperRegion());
399 void CXXTempObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
401 const MemRegion *sReg) {
406 void CXXTempObjectRegion::Profile(llvm::FoldingSetNodeID &ID) const {
407 ProfileRegion(ID, Ex, getSuperRegion());
410 void CXXBaseObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &ID,
411 const CXXRecordDecl *RD,
413 const MemRegion *SReg) {
415 ID.AddBoolean(IsVirtual);
419 void CXXBaseObjectRegion::Profile(llvm::FoldingSetNodeID &ID) const {
420 ProfileRegion(ID, getDecl(), isVirtual(), superRegion);
423 //===----------------------------------------------------------------------===//
425 //===----------------------------------------------------------------------===//
427 void GlobalsSpaceRegion::anchor() { }
428 void HeapSpaceRegion::anchor() { }
429 void UnknownSpaceRegion::anchor() { }
430 void StackLocalsSpaceRegion::anchor() { }
431 void StackArgumentsSpaceRegion::anchor() { }
432 void TypedRegion::anchor() { }
433 void TypedValueRegion::anchor() { }
434 void CodeTextRegion::anchor() { }
435 void SubRegion::anchor() { }
437 //===----------------------------------------------------------------------===//
438 // Region pretty-printing.
439 //===----------------------------------------------------------------------===//
441 void MemRegion::dump() const {
442 dumpToStream(llvm::errs());
445 std::string MemRegion::getString() const {
447 llvm::raw_string_ostream os(s);
452 void MemRegion::dumpToStream(raw_ostream &os) const {
453 os << "<Unknown Region>";
456 void AllocaRegion::dumpToStream(raw_ostream &os) const {
457 os << "alloca{" << (const void*) Ex << ',' << Cnt << '}';
460 void FunctionTextRegion::dumpToStream(raw_ostream &os) const {
461 os << "code{" << getDecl()->getDeclName().getAsString() << '}';
464 void BlockTextRegion::dumpToStream(raw_ostream &os) const {
465 os << "block_code{" << (const void*) this << '}';
468 void BlockDataRegion::dumpToStream(raw_ostream &os) const {
469 os << "block_data{" << BC;
471 for (BlockDataRegion::referenced_vars_iterator
472 I = referenced_vars_begin(),
473 E = referenced_vars_end(); I != E; ++I)
474 os << "(" << I.getCapturedRegion() << "," <<
475 I.getOriginalRegion() << ") ";
479 void CompoundLiteralRegion::dumpToStream(raw_ostream &os) const {
480 // FIXME: More elaborate pretty-printing.
481 os << "{ " << (const void*) CL << " }";
484 void CXXTempObjectRegion::dumpToStream(raw_ostream &os) const {
485 os << "temp_object{" << getValueType().getAsString() << ','
486 << (const void*) Ex << '}';
489 void CXXBaseObjectRegion::dumpToStream(raw_ostream &os) const {
490 os << "base{" << superRegion << ',' << getDecl()->getName() << '}';
493 void CXXThisRegion::dumpToStream(raw_ostream &os) const {
497 void ElementRegion::dumpToStream(raw_ostream &os) const {
498 os << "element{" << superRegion << ','
499 << Index << ',' << getElementType().getAsString() << '}';
502 void FieldRegion::dumpToStream(raw_ostream &os) const {
503 os << superRegion << "->" << *getDecl();
506 void ObjCIvarRegion::dumpToStream(raw_ostream &os) const {
507 os << "ivar{" << superRegion << ',' << *getDecl() << '}';
510 void StringRegion::dumpToStream(raw_ostream &os) const {
511 assert(Str != nullptr && "Expecting non-null StringLiteral");
512 Str->printPretty(os, nullptr, PrintingPolicy(getContext().getLangOpts()));
515 void ObjCStringRegion::dumpToStream(raw_ostream &os) const {
516 assert(Str != nullptr && "Expecting non-null ObjCStringLiteral");
517 Str->printPretty(os, nullptr, PrintingPolicy(getContext().getLangOpts()));
520 void SymbolicRegion::dumpToStream(raw_ostream &os) const {
521 os << "SymRegion{" << sym << '}';
524 void VarRegion::dumpToStream(raw_ostream &os) const {
525 os << *cast<VarDecl>(D);
528 void RegionRawOffset::dump() const {
529 dumpToStream(llvm::errs());
532 void RegionRawOffset::dumpToStream(raw_ostream &os) const {
533 os << "raw_offset{" << getRegion() << ',' << getOffset().getQuantity() << '}';
536 void StaticGlobalSpaceRegion::dumpToStream(raw_ostream &os) const {
537 os << "StaticGlobalsMemSpace{" << CR << '}';
540 void GlobalInternalSpaceRegion::dumpToStream(raw_ostream &os) const {
541 os << "GlobalInternalSpaceRegion";
544 void GlobalSystemSpaceRegion::dumpToStream(raw_ostream &os) const {
545 os << "GlobalSystemSpaceRegion";
548 void GlobalImmutableSpaceRegion::dumpToStream(raw_ostream &os) const {
549 os << "GlobalImmutableSpaceRegion";
552 void HeapSpaceRegion::dumpToStream(raw_ostream &os) const {
553 os << "HeapSpaceRegion";
556 void UnknownSpaceRegion::dumpToStream(raw_ostream &os) const {
557 os << "UnknownSpaceRegion";
560 void StackArgumentsSpaceRegion::dumpToStream(raw_ostream &os) const {
561 os << "StackArgumentsSpaceRegion";
564 void StackLocalsSpaceRegion::dumpToStream(raw_ostream &os) const {
565 os << "StackLocalsSpaceRegion";
568 bool MemRegion::canPrintPretty() const {
569 return canPrintPrettyAsExpr();
572 bool MemRegion::canPrintPrettyAsExpr() const {
576 void MemRegion::printPretty(raw_ostream &os) const {
577 assert(canPrintPretty() && "This region cannot be printed pretty.");
579 printPrettyAsExpr(os);
584 void MemRegion::printPrettyAsExpr(raw_ostream &os) const {
585 llvm_unreachable("This region cannot be printed pretty.");
589 bool VarRegion::canPrintPrettyAsExpr() const {
593 void VarRegion::printPrettyAsExpr(raw_ostream &os) const {
594 os << getDecl()->getName();
597 bool ObjCIvarRegion::canPrintPrettyAsExpr() const {
601 void ObjCIvarRegion::printPrettyAsExpr(raw_ostream &os) const {
602 os << getDecl()->getName();
605 bool FieldRegion::canPrintPretty() const {
609 bool FieldRegion::canPrintPrettyAsExpr() const {
610 return superRegion->canPrintPrettyAsExpr();
613 void FieldRegion::printPrettyAsExpr(raw_ostream &os) const {
614 assert(canPrintPrettyAsExpr());
615 superRegion->printPrettyAsExpr(os);
616 os << "." << getDecl()->getName();
619 void FieldRegion::printPretty(raw_ostream &os) const {
620 if (canPrintPrettyAsExpr()) {
622 printPrettyAsExpr(os);
625 os << "field " << "\'" << getDecl()->getName() << "'";
630 bool CXXBaseObjectRegion::canPrintPrettyAsExpr() const {
631 return superRegion->canPrintPrettyAsExpr();
634 void CXXBaseObjectRegion::printPrettyAsExpr(raw_ostream &os) const {
635 superRegion->printPrettyAsExpr(os);
638 //===----------------------------------------------------------------------===//
639 // MemRegionManager methods.
640 //===----------------------------------------------------------------------===//
642 template <typename REG>
643 const REG *MemRegionManager::LazyAllocate(REG*& region) {
645 region = (REG*) A.Allocate<REG>();
646 new (region) REG(this);
652 template <typename REG, typename ARG>
653 const REG *MemRegionManager::LazyAllocate(REG*& region, ARG a) {
655 region = (REG*) A.Allocate<REG>();
656 new (region) REG(this, a);
662 const StackLocalsSpaceRegion*
663 MemRegionManager::getStackLocalsRegion(const StackFrameContext *STC) {
665 StackLocalsSpaceRegion *&R = StackLocalsSpaceRegions[STC];
670 R = A.Allocate<StackLocalsSpaceRegion>();
671 new (R) StackLocalsSpaceRegion(this, STC);
675 const StackArgumentsSpaceRegion *
676 MemRegionManager::getStackArgumentsRegion(const StackFrameContext *STC) {
678 StackArgumentsSpaceRegion *&R = StackArgumentsSpaceRegions[STC];
683 R = A.Allocate<StackArgumentsSpaceRegion>();
684 new (R) StackArgumentsSpaceRegion(this, STC);
688 const GlobalsSpaceRegion
689 *MemRegionManager::getGlobalsRegion(MemRegion::Kind K,
690 const CodeTextRegion *CR) {
692 if (K == MemRegion::GlobalSystemSpaceRegionKind)
693 return LazyAllocate(SystemGlobals);
694 if (K == MemRegion::GlobalImmutableSpaceRegionKind)
695 return LazyAllocate(ImmutableGlobals);
696 assert(K == MemRegion::GlobalInternalSpaceRegionKind);
697 return LazyAllocate(InternalGlobals);
700 assert(K == MemRegion::StaticGlobalSpaceRegionKind);
701 StaticGlobalSpaceRegion *&R = StaticsGlobalSpaceRegions[CR];
705 R = A.Allocate<StaticGlobalSpaceRegion>();
706 new (R) StaticGlobalSpaceRegion(this, CR);
710 const HeapSpaceRegion *MemRegionManager::getHeapRegion() {
711 return LazyAllocate(heap);
714 const MemSpaceRegion *MemRegionManager::getUnknownRegion() {
715 return LazyAllocate(unknown);
718 const MemSpaceRegion *MemRegionManager::getCodeRegion() {
719 return LazyAllocate(code);
722 //===----------------------------------------------------------------------===//
723 // Constructing regions.
724 //===----------------------------------------------------------------------===//
725 const StringRegion* MemRegionManager::getStringRegion(const StringLiteral* Str){
726 return getSubRegion<StringRegion>(Str, getGlobalsRegion());
729 const ObjCStringRegion *
730 MemRegionManager::getObjCStringRegion(const ObjCStringLiteral* Str){
731 return getSubRegion<ObjCStringRegion>(Str, getGlobalsRegion());
734 /// Look through a chain of LocationContexts to either find the
735 /// StackFrameContext that matches a DeclContext, or find a VarRegion
736 /// for a variable captured by a block.
737 static llvm::PointerUnion<const StackFrameContext *, const VarRegion *>
738 getStackOrCaptureRegionForDeclContext(const LocationContext *LC,
739 const DeclContext *DC,
742 if (const StackFrameContext *SFC = dyn_cast<StackFrameContext>(LC)) {
743 if (cast<DeclContext>(SFC->getDecl()) == DC)
746 if (const BlockInvocationContext *BC =
747 dyn_cast<BlockInvocationContext>(LC)) {
748 const BlockDataRegion *BR =
749 static_cast<const BlockDataRegion*>(BC->getContextData());
750 // FIXME: This can be made more efficient.
751 for (BlockDataRegion::referenced_vars_iterator
752 I = BR->referenced_vars_begin(),
753 E = BR->referenced_vars_end(); I != E; ++I) {
754 if (const VarRegion *VR = dyn_cast<VarRegion>(I.getOriginalRegion()))
755 if (VR->getDecl() == VD)
756 return cast<VarRegion>(I.getCapturedRegion());
760 LC = LC->getParent();
762 return (const StackFrameContext *)nullptr;
765 const VarRegion* MemRegionManager::getVarRegion(const VarDecl *D,
766 const LocationContext *LC) {
767 const MemRegion *sReg = nullptr;
769 if (D->hasGlobalStorage() && !D->isStaticLocal()) {
771 // First handle the globals defined in system headers.
772 if (C.getSourceManager().isInSystemHeader(D->getLocation())) {
773 // Whitelist the system globals which often DO GET modified, assume the
774 // rest are immutable.
775 if (D->getName().find("errno") != StringRef::npos)
776 sReg = getGlobalsRegion(MemRegion::GlobalSystemSpaceRegionKind);
778 sReg = getGlobalsRegion(MemRegion::GlobalImmutableSpaceRegionKind);
780 // Treat other globals as GlobalInternal unless they are constants.
782 QualType GQT = D->getType();
783 const Type *GT = GQT.getTypePtrOrNull();
784 // TODO: We could walk the complex types here and see if everything is
786 if (GT && GQT.isConstQualified() && GT->isArithmeticType())
787 sReg = getGlobalsRegion(MemRegion::GlobalImmutableSpaceRegionKind);
789 sReg = getGlobalsRegion();
792 // Finally handle static locals.
794 // FIXME: Once we implement scope handling, we will need to properly lookup
795 // 'D' to the proper LocationContext.
796 const DeclContext *DC = D->getDeclContext();
797 llvm::PointerUnion<const StackFrameContext *, const VarRegion *> V =
798 getStackOrCaptureRegionForDeclContext(LC, DC, D);
800 if (V.is<const VarRegion*>())
801 return V.get<const VarRegion*>();
803 const StackFrameContext *STC = V.get<const StackFrameContext*>();
806 sReg = getUnknownRegion();
808 if (D->hasLocalStorage()) {
809 sReg = isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)
810 ? static_cast<const MemRegion*>(getStackArgumentsRegion(STC))
811 : static_cast<const MemRegion*>(getStackLocalsRegion(STC));
814 assert(D->isStaticLocal());
815 const Decl *STCD = STC->getDecl();
816 if (isa<FunctionDecl>(STCD) || isa<ObjCMethodDecl>(STCD))
817 sReg = getGlobalsRegion(MemRegion::StaticGlobalSpaceRegionKind,
818 getFunctionTextRegion(cast<NamedDecl>(STCD)));
819 else if (const BlockDecl *BD = dyn_cast<BlockDecl>(STCD)) {
820 // FIXME: The fallback type here is totally bogus -- though it should
821 // never be queried, it will prevent uniquing with the real
822 // BlockTextRegion. Ideally we'd fix the AST so that we always had a
825 if (const TypeSourceInfo *TSI = BD->getSignatureAsWritten())
828 T = getContext().VoidTy;
829 if (!T->getAs<FunctionType>())
830 T = getContext().getFunctionNoProtoType(T);
831 T = getContext().getBlockPointerType(T);
833 const BlockTextRegion *BTR =
834 getBlockTextRegion(BD, C.getCanonicalType(T),
835 STC->getAnalysisDeclContext());
836 sReg = getGlobalsRegion(MemRegion::StaticGlobalSpaceRegionKind,
840 sReg = getGlobalsRegion();
846 return getSubRegion<VarRegion>(D, sReg);
849 const VarRegion *MemRegionManager::getVarRegion(const VarDecl *D,
850 const MemRegion *superR) {
851 return getSubRegion<VarRegion>(D, superR);
854 const BlockDataRegion *
855 MemRegionManager::getBlockDataRegion(const BlockTextRegion *BC,
856 const LocationContext *LC,
857 unsigned blockCount) {
858 const MemRegion *sReg = nullptr;
859 const BlockDecl *BD = BC->getDecl();
860 if (!BD->hasCaptures()) {
861 // This handles 'static' blocks.
862 sReg = getGlobalsRegion(MemRegion::GlobalImmutableSpaceRegionKind);
866 // FIXME: Once we implement scope handling, we want the parent region
868 const StackFrameContext *STC = LC->getCurrentStackFrame();
870 sReg = getStackLocalsRegion(STC);
873 // We allow 'LC' to be NULL for cases where want BlockDataRegions
874 // without context-sensitivity.
875 sReg = getUnknownRegion();
879 return getSubRegion<BlockDataRegion>(BC, LC, blockCount, sReg);
882 const CXXTempObjectRegion *
883 MemRegionManager::getCXXStaticTempObjectRegion(const Expr *Ex) {
884 return getSubRegion<CXXTempObjectRegion>(
885 Ex, getGlobalsRegion(MemRegion::GlobalInternalSpaceRegionKind, nullptr));
888 const CompoundLiteralRegion*
889 MemRegionManager::getCompoundLiteralRegion(const CompoundLiteralExpr *CL,
890 const LocationContext *LC) {
892 const MemRegion *sReg = nullptr;
894 if (CL->isFileScope())
895 sReg = getGlobalsRegion();
897 const StackFrameContext *STC = LC->getCurrentStackFrame();
899 sReg = getStackLocalsRegion(STC);
902 return getSubRegion<CompoundLiteralRegion>(CL, sReg);
906 MemRegionManager::getElementRegion(QualType elementType, NonLoc Idx,
907 const MemRegion* superRegion,
910 QualType T = Ctx.getCanonicalType(elementType).getUnqualifiedType();
912 llvm::FoldingSetNodeID ID;
913 ElementRegion::ProfileRegion(ID, T, Idx, superRegion);
916 MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
917 ElementRegion* R = cast_or_null<ElementRegion>(data);
920 R = (ElementRegion*) A.Allocate<ElementRegion>();
921 new (R) ElementRegion(T, Idx, superRegion);
922 Regions.InsertNode(R, InsertPos);
928 const FunctionTextRegion *
929 MemRegionManager::getFunctionTextRegion(const NamedDecl *FD) {
930 return getSubRegion<FunctionTextRegion>(FD, getCodeRegion());
933 const BlockTextRegion *
934 MemRegionManager::getBlockTextRegion(const BlockDecl *BD, CanQualType locTy,
935 AnalysisDeclContext *AC) {
936 return getSubRegion<BlockTextRegion>(BD, locTy, AC, getCodeRegion());
940 /// getSymbolicRegion - Retrieve or create a "symbolic" memory region.
941 const SymbolicRegion *MemRegionManager::getSymbolicRegion(SymbolRef sym) {
942 return getSubRegion<SymbolicRegion>(sym, getUnknownRegion());
945 const SymbolicRegion *MemRegionManager::getSymbolicHeapRegion(SymbolRef Sym) {
946 return getSubRegion<SymbolicRegion>(Sym, getHeapRegion());
950 MemRegionManager::getFieldRegion(const FieldDecl *d,
951 const MemRegion* superRegion){
952 return getSubRegion<FieldRegion>(d, superRegion);
955 const ObjCIvarRegion*
956 MemRegionManager::getObjCIvarRegion(const ObjCIvarDecl *d,
957 const MemRegion* superRegion) {
958 return getSubRegion<ObjCIvarRegion>(d, superRegion);
961 const CXXTempObjectRegion*
962 MemRegionManager::getCXXTempObjectRegion(Expr const *E,
963 LocationContext const *LC) {
964 const StackFrameContext *SFC = LC->getCurrentStackFrame();
966 return getSubRegion<CXXTempObjectRegion>(E, getStackLocalsRegion(SFC));
969 /// Checks whether \p BaseClass is a valid virtual or direct non-virtual base
970 /// class of the type of \p Super.
971 static bool isValidBaseClass(const CXXRecordDecl *BaseClass,
972 const TypedValueRegion *Super,
974 BaseClass = BaseClass->getCanonicalDecl();
976 const CXXRecordDecl *Class = Super->getValueType()->getAsCXXRecordDecl();
981 return Class->isVirtuallyDerivedFrom(BaseClass);
983 for (const auto &I : Class->bases()) {
984 if (I.getType()->getAsCXXRecordDecl()->getCanonicalDecl() == BaseClass)
991 const CXXBaseObjectRegion *
992 MemRegionManager::getCXXBaseObjectRegion(const CXXRecordDecl *RD,
993 const MemRegion *Super,
995 if (isa<TypedValueRegion>(Super)) {
996 assert(isValidBaseClass(RD, dyn_cast<TypedValueRegion>(Super), IsVirtual));
997 (void)&isValidBaseClass;
1000 // Virtual base regions should not be layered, since the layout rules
1002 while (const CXXBaseObjectRegion *Base =
1003 dyn_cast<CXXBaseObjectRegion>(Super)) {
1004 Super = Base->getSuperRegion();
1006 assert(Super && !isa<MemSpaceRegion>(Super));
1010 return getSubRegion<CXXBaseObjectRegion>(RD, IsVirtual, Super);
1013 const CXXThisRegion*
1014 MemRegionManager::getCXXThisRegion(QualType thisPointerTy,
1015 const LocationContext *LC) {
1016 const PointerType *PT = thisPointerTy->getAs<PointerType>();
1018 // Inside the body of the operator() of a lambda a this expr might refer to an
1019 // object in one of the parent location contexts.
1020 const auto *D = dyn_cast<CXXMethodDecl>(LC->getDecl());
1021 // FIXME: when operator() of lambda is analyzed as a top level function and
1022 // 'this' refers to a this to the enclosing scope, there is no right region to
1024 while (!LC->inTopFrame() &&
1025 (!D || PT != D->getThisType(getContext())->getAs<PointerType>())) {
1026 LC = LC->getParent();
1027 D = dyn_cast<CXXMethodDecl>(LC->getDecl());
1029 const StackFrameContext *STC = LC->getCurrentStackFrame();
1031 return getSubRegion<CXXThisRegion>(PT, getStackArgumentsRegion(STC));
1035 MemRegionManager::getAllocaRegion(const Expr *E, unsigned cnt,
1036 const LocationContext *LC) {
1037 const StackFrameContext *STC = LC->getCurrentStackFrame();
1039 return getSubRegion<AllocaRegion>(E, cnt, getStackLocalsRegion(STC));
1042 const MemSpaceRegion *MemRegion::getMemorySpace() const {
1043 const MemRegion *R = this;
1044 const SubRegion* SR = dyn_cast<SubRegion>(this);
1047 R = SR->getSuperRegion();
1048 SR = dyn_cast<SubRegion>(R);
1051 return dyn_cast<MemSpaceRegion>(R);
1054 bool MemRegion::hasStackStorage() const {
1055 return isa<StackSpaceRegion>(getMemorySpace());
1058 bool MemRegion::hasStackNonParametersStorage() const {
1059 return isa<StackLocalsSpaceRegion>(getMemorySpace());
1062 bool MemRegion::hasStackParametersStorage() const {
1063 return isa<StackArgumentsSpaceRegion>(getMemorySpace());
1066 bool MemRegion::hasGlobalsOrParametersStorage() const {
1067 const MemSpaceRegion *MS = getMemorySpace();
1068 return isa<StackArgumentsSpaceRegion>(MS) ||
1069 isa<GlobalsSpaceRegion>(MS);
1072 // getBaseRegion strips away all elements and fields, and get the base region
1074 const MemRegion *MemRegion::getBaseRegion() const {
1075 const MemRegion *R = this;
1077 switch (R->getKind()) {
1078 case MemRegion::ElementRegionKind:
1079 case MemRegion::FieldRegionKind:
1080 case MemRegion::ObjCIvarRegionKind:
1081 case MemRegion::CXXBaseObjectRegionKind:
1082 R = cast<SubRegion>(R)->getSuperRegion();
1092 bool MemRegion::isSubRegionOf(const MemRegion *R) const {
1096 //===----------------------------------------------------------------------===//
1098 //===----------------------------------------------------------------------===//
1100 const MemRegion *MemRegion::StripCasts(bool StripBaseCasts) const {
1101 const MemRegion *R = this;
1103 switch (R->getKind()) {
1104 case ElementRegionKind: {
1105 const ElementRegion *ER = cast<ElementRegion>(R);
1106 if (!ER->getIndex().isZeroConstant())
1108 R = ER->getSuperRegion();
1111 case CXXBaseObjectRegionKind:
1112 if (!StripBaseCasts)
1114 R = cast<CXXBaseObjectRegion>(R)->getSuperRegion();
1122 const SymbolicRegion *MemRegion::getSymbolicBase() const {
1123 const SubRegion *SubR = dyn_cast<SubRegion>(this);
1126 if (const SymbolicRegion *SymR = dyn_cast<SymbolicRegion>(SubR))
1128 SubR = dyn_cast<SubRegion>(SubR->getSuperRegion());
1133 RegionRawOffset ElementRegion::getAsArrayOffset() const {
1134 CharUnits offset = CharUnits::Zero();
1135 const ElementRegion *ER = this;
1136 const MemRegion *superR = nullptr;
1137 ASTContext &C = getContext();
1139 // FIXME: Handle multi-dimensional arrays.
1142 superR = ER->getSuperRegion();
1144 // FIXME: generalize to symbolic offsets.
1145 SVal index = ER->getIndex();
1146 if (Optional<nonloc::ConcreteInt> CI = index.getAs<nonloc::ConcreteInt>()) {
1147 // Update the offset.
1148 int64_t i = CI->getValue().getSExtValue();
1151 QualType elemType = ER->getElementType();
1153 // If we are pointing to an incomplete type, go no further.
1154 if (elemType->isIncompleteType()) {
1159 CharUnits size = C.getTypeSizeInChars(elemType);
1160 offset += (i * size);
1163 // Go to the next ElementRegion (if any).
1164 ER = dyn_cast<ElementRegion>(superR);
1171 assert(superR && "super region cannot be NULL");
1172 return RegionRawOffset(superR, offset);
1176 /// Returns true if \p Base is an immediate base class of \p Child
1177 static bool isImmediateBase(const CXXRecordDecl *Child,
1178 const CXXRecordDecl *Base) {
1179 // Note that we do NOT canonicalize the base class here, because
1180 // ASTRecordLayout doesn't either. If that leads us down the wrong path,
1181 // so be it; at least we won't crash.
1182 for (const auto &I : Child->bases()) {
1183 if (I.getType()->getAsCXXRecordDecl() == Base)
1190 RegionOffset MemRegion::getAsOffset() const {
1191 const MemRegion *R = this;
1192 const MemRegion *SymbolicOffsetBase = nullptr;
1196 switch (R->getKind()) {
1197 case GenericMemSpaceRegionKind:
1198 case StackLocalsSpaceRegionKind:
1199 case StackArgumentsSpaceRegionKind:
1200 case HeapSpaceRegionKind:
1201 case UnknownSpaceRegionKind:
1202 case StaticGlobalSpaceRegionKind:
1203 case GlobalInternalSpaceRegionKind:
1204 case GlobalSystemSpaceRegionKind:
1205 case GlobalImmutableSpaceRegionKind:
1206 // Stores can bind directly to a region space to set a default value.
1207 assert(Offset == 0 && !SymbolicOffsetBase);
1210 case FunctionTextRegionKind:
1211 case BlockTextRegionKind:
1212 case BlockDataRegionKind:
1213 // These will never have bindings, but may end up having values requested
1214 // if the user does some strange casting.
1216 SymbolicOffsetBase = R;
1219 case SymbolicRegionKind:
1220 case AllocaRegionKind:
1221 case CompoundLiteralRegionKind:
1222 case CXXThisRegionKind:
1223 case StringRegionKind:
1224 case ObjCStringRegionKind:
1226 case CXXTempObjectRegionKind:
1227 // Usual base regions.
1230 case ObjCIvarRegionKind:
1231 // This is a little strange, but it's a compromise between
1232 // ObjCIvarRegions having unknown compile-time offsets (when using the
1233 // non-fragile runtime) and yet still being distinct, non-overlapping
1234 // regions. Thus we treat them as "like" base regions for the purposes
1235 // of computing offsets.
1238 case CXXBaseObjectRegionKind: {
1239 const CXXBaseObjectRegion *BOR = cast<CXXBaseObjectRegion>(R);
1240 R = BOR->getSuperRegion();
1243 bool RootIsSymbolic = false;
1244 if (const TypedValueRegion *TVR = dyn_cast<TypedValueRegion>(R)) {
1245 Ty = TVR->getDesugaredValueType(getContext());
1246 } else if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R)) {
1247 // If our base region is symbolic, we don't know what type it really is.
1248 // Pretend the type of the symbol is the true dynamic type.
1249 // (This will at least be self-consistent for the life of the symbol.)
1250 Ty = SR->getSymbol()->getType()->getPointeeType();
1251 RootIsSymbolic = true;
1254 const CXXRecordDecl *Child = Ty->getAsCXXRecordDecl();
1256 // We cannot compute the offset of the base class.
1257 SymbolicOffsetBase = R;
1260 if (RootIsSymbolic) {
1261 // Base layers on symbolic regions may not be type-correct.
1262 // Double-check the inheritance here, and revert to a symbolic offset
1263 // if it's invalid (e.g. due to a reinterpret_cast).
1264 if (BOR->isVirtual()) {
1265 if (!Child->isVirtuallyDerivedFrom(BOR->getDecl()))
1266 SymbolicOffsetBase = R;
1268 if (!isImmediateBase(Child, BOR->getDecl()))
1269 SymbolicOffsetBase = R;
1273 // Don't bother calculating precise offsets if we already have a
1274 // symbolic offset somewhere in the chain.
1275 if (SymbolicOffsetBase)
1278 CharUnits BaseOffset;
1279 const ASTRecordLayout &Layout = getContext().getASTRecordLayout(Child);
1280 if (BOR->isVirtual())
1281 BaseOffset = Layout.getVBaseClassOffset(BOR->getDecl());
1283 BaseOffset = Layout.getBaseClassOffset(BOR->getDecl());
1285 // The base offset is in chars, not in bits.
1286 Offset += BaseOffset.getQuantity() * getContext().getCharWidth();
1289 case ElementRegionKind: {
1290 const ElementRegion *ER = cast<ElementRegion>(R);
1291 R = ER->getSuperRegion();
1293 QualType EleTy = ER->getValueType();
1294 if (EleTy->isIncompleteType()) {
1295 // We cannot compute the offset of the base class.
1296 SymbolicOffsetBase = R;
1300 SVal Index = ER->getIndex();
1301 if (Optional<nonloc::ConcreteInt> CI =
1302 Index.getAs<nonloc::ConcreteInt>()) {
1303 // Don't bother calculating precise offsets if we already have a
1304 // symbolic offset somewhere in the chain.
1305 if (SymbolicOffsetBase)
1308 int64_t i = CI->getValue().getSExtValue();
1309 // This type size is in bits.
1310 Offset += i * getContext().getTypeSize(EleTy);
1312 // We cannot compute offset for non-concrete index.
1313 SymbolicOffsetBase = R;
1317 case FieldRegionKind: {
1318 const FieldRegion *FR = cast<FieldRegion>(R);
1319 R = FR->getSuperRegion();
1321 const RecordDecl *RD = FR->getDecl()->getParent();
1322 if (RD->isUnion() || !RD->isCompleteDefinition()) {
1323 // We cannot compute offset for incomplete type.
1324 // For unions, we could treat everything as offset 0, but we'd rather
1325 // treat each field as a symbolic offset so they aren't stored on top
1326 // of each other, since we depend on things in typed regions actually
1327 // matching their types.
1328 SymbolicOffsetBase = R;
1331 // Don't bother calculating precise offsets if we already have a
1332 // symbolic offset somewhere in the chain.
1333 if (SymbolicOffsetBase)
1336 // Get the field number.
1338 for (RecordDecl::field_iterator FI = RD->field_begin(),
1339 FE = RD->field_end(); FI != FE; ++FI, ++idx)
1340 if (FR->getDecl() == *FI)
1343 const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
1344 // This is offset in bits.
1345 Offset += Layout.getFieldOffset(idx);
1352 if (SymbolicOffsetBase)
1353 return RegionOffset(SymbolicOffsetBase, RegionOffset::Symbolic);
1354 return RegionOffset(R, Offset);
1357 //===----------------------------------------------------------------------===//
1359 //===----------------------------------------------------------------------===//
1361 std::pair<const VarRegion *, const VarRegion *>
1362 BlockDataRegion::getCaptureRegions(const VarDecl *VD) {
1363 MemRegionManager &MemMgr = *getMemRegionManager();
1364 const VarRegion *VR = nullptr;
1365 const VarRegion *OriginalVR = nullptr;
1367 if (!VD->hasAttr<BlocksAttr>() && VD->hasLocalStorage()) {
1368 VR = MemMgr.getVarRegion(VD, this);
1369 OriginalVR = MemMgr.getVarRegion(VD, LC);
1373 VR = MemMgr.getVarRegion(VD, LC);
1377 VR = MemMgr.getVarRegion(VD, MemMgr.getUnknownRegion());
1378 OriginalVR = MemMgr.getVarRegion(VD, LC);
1381 return std::make_pair(VR, OriginalVR);
1384 void BlockDataRegion::LazyInitializeReferencedVars() {
1388 AnalysisDeclContext *AC = getCodeRegion()->getAnalysisDeclContext();
1389 const auto &ReferencedBlockVars = AC->getReferencedBlockVars(BC->getDecl());
1391 std::distance(ReferencedBlockVars.begin(), ReferencedBlockVars.end());
1393 if (NumBlockVars == 0) {
1394 ReferencedVars = (void*) 0x1;
1398 MemRegionManager &MemMgr = *getMemRegionManager();
1399 llvm::BumpPtrAllocator &A = MemMgr.getAllocator();
1400 BumpVectorContext BC(A);
1402 typedef BumpVector<const MemRegion*> VarVec;
1403 VarVec *BV = (VarVec*) A.Allocate<VarVec>();
1404 new (BV) VarVec(BC, NumBlockVars);
1405 VarVec *BVOriginal = (VarVec*) A.Allocate<VarVec>();
1406 new (BVOriginal) VarVec(BC, NumBlockVars);
1408 for (const VarDecl *VD : ReferencedBlockVars) {
1409 const VarRegion *VR = nullptr;
1410 const VarRegion *OriginalVR = nullptr;
1411 std::tie(VR, OriginalVR) = getCaptureRegions(VD);
1414 BV->push_back(VR, BC);
1415 BVOriginal->push_back(OriginalVR, BC);
1418 ReferencedVars = BV;
1419 OriginalVars = BVOriginal;
1422 BlockDataRegion::referenced_vars_iterator
1423 BlockDataRegion::referenced_vars_begin() const {
1424 const_cast<BlockDataRegion*>(this)->LazyInitializeReferencedVars();
1426 BumpVector<const MemRegion*> *Vec =
1427 static_cast<BumpVector<const MemRegion*>*>(ReferencedVars);
1429 if (Vec == (void*) 0x1)
1430 return BlockDataRegion::referenced_vars_iterator(nullptr, nullptr);
1432 BumpVector<const MemRegion*> *VecOriginal =
1433 static_cast<BumpVector<const MemRegion*>*>(OriginalVars);
1435 return BlockDataRegion::referenced_vars_iterator(Vec->begin(),
1436 VecOriginal->begin());
1439 BlockDataRegion::referenced_vars_iterator
1440 BlockDataRegion::referenced_vars_end() const {
1441 const_cast<BlockDataRegion*>(this)->LazyInitializeReferencedVars();
1443 BumpVector<const MemRegion*> *Vec =
1444 static_cast<BumpVector<const MemRegion*>*>(ReferencedVars);
1446 if (Vec == (void*) 0x1)
1447 return BlockDataRegion::referenced_vars_iterator(nullptr, nullptr);
1449 BumpVector<const MemRegion*> *VecOriginal =
1450 static_cast<BumpVector<const MemRegion*>*>(OriginalVars);
1452 return BlockDataRegion::referenced_vars_iterator(Vec->end(),
1453 VecOriginal->end());
1456 const VarRegion *BlockDataRegion::getOriginalRegion(const VarRegion *R) const {
1457 for (referenced_vars_iterator I = referenced_vars_begin(),
1458 E = referenced_vars_end();
1460 if (I.getCapturedRegion() == R)
1461 return I.getOriginalRegion();
1466 //===----------------------------------------------------------------------===//
1467 // RegionAndSymbolInvalidationTraits
1468 //===----------------------------------------------------------------------===//
1470 void RegionAndSymbolInvalidationTraits::setTrait(SymbolRef Sym,
1471 InvalidationKinds IK) {
1472 SymTraitsMap[Sym] |= IK;
1475 void RegionAndSymbolInvalidationTraits::setTrait(const MemRegion *MR,
1476 InvalidationKinds IK) {
1478 if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(MR))
1479 setTrait(SR->getSymbol(), IK);
1481 MRTraitsMap[MR] |= IK;
1484 bool RegionAndSymbolInvalidationTraits::hasTrait(SymbolRef Sym,
1485 InvalidationKinds IK) {
1486 const_symbol_iterator I = SymTraitsMap.find(Sym);
1487 if (I != SymTraitsMap.end())
1488 return I->second & IK;
1493 bool RegionAndSymbolInvalidationTraits::hasTrait(const MemRegion *MR,
1494 InvalidationKinds IK) {
1498 if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(MR))
1499 return hasTrait(SR->getSymbol(), IK);
1501 const_region_iterator I = MRTraitsMap.find(MR);
1502 if (I != MRTraitsMap.end())
1503 return I->second & IK;