clang  7.0.0svn
MemRegion.h
Go to the documentation of this file.
1 //== MemRegion.h - Abstract memory regions for static analysis --*- C++ -*--==//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines MemRegion and its subclasses. MemRegion defines a
11 // partially-typed abstraction of memory useful for path-sensitive dataflow
12 // analyses.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_MEMREGION_H
17 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_MEMREGION_H
18 
19 #include "clang/AST/ASTContext.h"
20 #include "clang/AST/CharUnits.h"
21 #include "clang/AST/Decl.h"
22 #include "clang/AST/DeclCXX.h"
23 #include "clang/AST/ExprObjC.h"
25 #include "clang/Basic/LLVM.h"
27 #include "llvm/ADT/FoldingSet.h"
28 #include "llvm/Support/Allocator.h"
29 #include "llvm/Support/ErrorHandling.h"
30 #include <string>
31 
32 namespace clang {
33 
34 class LocationContext;
35 class StackFrameContext;
36 
37 namespace ento {
38 
39 class CodeTextRegion;
40 class MemRegionManager;
41 class MemSpaceRegion;
42 class SValBuilder;
43 class SymbolicRegion;
44 class VarRegion;
45 
46 /// Represent a region's offset within the top level base region.
47 class RegionOffset {
48  /// The base region.
49  const MemRegion *R;
50 
51  /// The bit offset within the base region. Can be negative.
52  int64_t Offset;
53 
54 public:
55  // We're using a const instead of an enumeration due to the size required;
56  // Visual Studio will only create enumerations of size int, not long long.
57  static const int64_t Symbolic = INT64_MAX;
58 
59  RegionOffset() : R(nullptr) {}
60  RegionOffset(const MemRegion *r, int64_t off) : R(r), Offset(off) {}
61 
62  const MemRegion *getRegion() const { return R; }
63 
64  bool hasSymbolicOffset() const { return Offset == Symbolic; }
65 
66  int64_t getOffset() const {
67  assert(!hasSymbolicOffset());
68  return Offset;
69  }
70 
71  bool isValid() const { return R; }
72 };
73 
74 //===----------------------------------------------------------------------===//
75 // Base region classes.
76 //===----------------------------------------------------------------------===//
77 
78 /// MemRegion - The root abstract class for all memory regions.
79 class MemRegion : public llvm::FoldingSetNode {
80 public:
81  enum Kind {
82 #define REGION(Id, Parent) Id ## Kind,
83 #define REGION_RANGE(Id, First, Last) BEGIN_##Id = First, END_##Id = Last,
84 #include "clang/StaticAnalyzer/Core/PathSensitive/Regions.def"
85  };
86 
87 private:
88  const Kind kind;
89 
90 protected:
91  MemRegion(Kind k) : kind(k) {}
92  virtual ~MemRegion();
93 
94 public:
95  ASTContext &getContext() const;
96 
97  virtual void Profile(llvm::FoldingSetNodeID& ID) const = 0;
98 
99  virtual MemRegionManager* getMemRegionManager() const = 0;
100 
101  const MemSpaceRegion *getMemorySpace() const;
102 
103  const MemRegion *getBaseRegion() const;
104 
105  /// Check if the region is a subregion of the given region.
106  /// Each region is a subregion of itself.
107  virtual bool isSubRegionOf(const MemRegion *R) const;
108 
109  const MemRegion *StripCasts(bool StripBaseCasts = true) const;
110 
111  /// \brief If this is a symbolic region, returns the region. Otherwise,
112  /// goes up the base chain looking for the first symbolic base region.
113  const SymbolicRegion *getSymbolicBase() const;
114 
115  bool hasGlobalsOrParametersStorage() const;
116 
117  bool hasStackStorage() const;
118 
119  bool hasStackNonParametersStorage() const;
120 
121  bool hasStackParametersStorage() const;
122 
123  /// Compute the offset within the top level memory object.
124  RegionOffset getAsOffset() const;
125 
126  /// \brief Get a string representation of a region for debug use.
127  std::string getString() const;
128 
129  virtual void dumpToStream(raw_ostream &os) const;
130 
131  void dump() const;
132 
133  /// \brief Returns true if this region can be printed in a user-friendly way.
134  virtual bool canPrintPretty() const;
135 
136  /// \brief Print the region for use in diagnostics.
137  virtual void printPretty(raw_ostream &os) const;
138 
139  /// \brief Returns true if this region's textual representation can be used
140  /// as part of a larger expression.
141  virtual bool canPrintPrettyAsExpr() const;
142 
143  /// \brief Print the region as expression.
144  ///
145  /// When this region represents a subexpression, the method is for printing
146  /// an expression containing it.
147  virtual void printPrettyAsExpr(raw_ostream &os) const;
148 
149  Kind getKind() const { return kind; }
150 
151  template<typename RegionTy> const RegionTy* getAs() const;
152 
153  virtual bool isBoundable() const { return false; }
154 
155 
156  /// Get descriptive name for memory region. The name is obtained from
157  /// the variable/field declaration retrieved from the memory region.
158  /// Regions that point to an element of an array are returned as: "arr[0]".
159  /// Regions that point to a struct are returned as: "st.var".
160  //
161  /// \param UseQuotes Set if the name should be quoted.
162  ///
163  /// \returns variable name for memory region
164  std::string getDescriptiveName(bool UseQuotes = true) const;
165 
166 
167  /// Retrieve source range from memory region. The range retrieval
168  /// is based on the decl obtained from the memory region.
169  /// For a VarRegion the range of the base region is returned.
170  /// For a FieldRegion the range of the field is returned.
171  /// If no declaration is found, an empty source range is returned.
172  /// The client is responsible for checking if the returned range is valid.
173  ///
174  /// \returns source range for declaration retrieved from memory region
175  clang::SourceRange sourceRange() const;
176 };
177 
178 /// MemSpaceRegion - A memory region that represents a "memory space";
179 /// for example, the set of global variables, the stack frame, etc.
180 class MemSpaceRegion : public MemRegion {
181 protected:
183 
184  MemSpaceRegion(MemRegionManager *mgr, Kind k) : MemRegion(k), Mgr(mgr) {
185  assert(classof(this));
186  assert(mgr);
187  }
188 
189  MemRegionManager* getMemRegionManager() const override { return Mgr; }
190 
191 public:
192  bool isBoundable() const override { return false; }
193 
194  void Profile(llvm::FoldingSetNodeID &ID) const override;
195 
196  static bool classof(const MemRegion *R) {
197  Kind k = R->getKind();
198  return k >= BEGIN_MEMSPACES && k <= END_MEMSPACES;
199  }
200 };
201 
202 /// CodeSpaceRegion - The memory space that holds the executable code of
203 /// functions and blocks.
205  friend class MemRegionManager;
206 
208  : MemSpaceRegion(mgr, CodeSpaceRegionKind) {}
209 
210 public:
211  void dumpToStream(raw_ostream &os) const override;
212 
213  static bool classof(const MemRegion *R) {
214  return R->getKind() == CodeSpaceRegionKind;
215  }
216 };
217 
219  virtual void anchor();
220 
221 protected:
223  assert(classof(this));
224  }
225 
226 public:
227  static bool classof(const MemRegion *R) {
228  Kind k = R->getKind();
229  return k >= BEGIN_GLOBAL_MEMSPACES && k <= END_GLOBAL_MEMSPACES;
230  }
231 };
232 
233 /// \brief The region of the static variables within the current CodeTextRegion
234 /// scope.
235 ///
236 /// Currently, only the static locals are placed there, so we know that these
237 /// variables do not get invalidated by calls to other functions.
239  friend class MemRegionManager;
240 
241  const CodeTextRegion *CR;
242 
244  : GlobalsSpaceRegion(mgr, StaticGlobalSpaceRegionKind), CR(cr) {
245  assert(cr);
246  }
247 
248 public:
249  void Profile(llvm::FoldingSetNodeID &ID) const override;
250 
251  void dumpToStream(raw_ostream &os) const override;
252 
253  const CodeTextRegion *getCodeRegion() const { return CR; }
254 
255  static bool classof(const MemRegion *R) {
256  return R->getKind() == StaticGlobalSpaceRegionKind;
257  }
258 };
259 
260 /// \brief The region for all the non-static global variables.
261 ///
262 /// This class is further split into subclasses for efficient implementation of
263 /// invalidating a set of related global values as is done in
264 /// RegionStoreManager::invalidateRegions (instead of finding all the dependent
265 /// globals, we invalidate the whole parent region).
267  virtual void anchor() override;
268 
269 protected:
271  : GlobalsSpaceRegion(mgr, k) {
272  assert(classof(this));
273  }
274 
275 public:
276 
277  static bool classof(const MemRegion *R) {
278  Kind k = R->getKind();
279  return k >= BEGIN_NON_STATIC_GLOBAL_MEMSPACES &&
280  k <= END_NON_STATIC_GLOBAL_MEMSPACES;
281  }
282 };
283 
284 /// \brief The region containing globals which are defined in system/external
285 /// headers and are considered modifiable by system calls (ex: errno).
287  friend class MemRegionManager;
288 
290  : NonStaticGlobalSpaceRegion(mgr, GlobalSystemSpaceRegionKind) {}
291 
292 public:
293 
294  void dumpToStream(raw_ostream &os) const override;
295 
296  static bool classof(const MemRegion *R) {
297  return R->getKind() == GlobalSystemSpaceRegionKind;
298  }
299 };
300 
301 /// \brief The region containing globals which are considered not to be modified
302 /// or point to data which could be modified as a result of a function call
303 /// (system or internal). Ex: Const global scalars would be modeled as part of
304 /// this region. This region also includes most system globals since they have
305 /// low chance of being modified.
307  friend class MemRegionManager;
308 
310  : NonStaticGlobalSpaceRegion(mgr, GlobalImmutableSpaceRegionKind) {}
311 
312 public:
313 
314  void dumpToStream(raw_ostream &os) const override;
315 
316  static bool classof(const MemRegion *R) {
317  return R->getKind() == GlobalImmutableSpaceRegionKind;
318  }
319 };
320 
321 /// \brief The region containing globals which can be modified by calls to
322 /// "internally" defined functions - (for now just) functions other then system
323 /// calls.
325  friend class MemRegionManager;
326 
328  : NonStaticGlobalSpaceRegion(mgr, GlobalInternalSpaceRegionKind) {}
329 
330 public:
331 
332  void dumpToStream(raw_ostream &os) const override;
333 
334  static bool classof(const MemRegion *R) {
335  return R->getKind() == GlobalInternalSpaceRegionKind;
336  }
337 };
338 
340  friend class MemRegionManager;
341 
343  : MemSpaceRegion(mgr, HeapSpaceRegionKind) {}
344 public:
345 
346  void dumpToStream(raw_ostream &os) const override;
347 
348  static bool classof(const MemRegion *R) {
349  return R->getKind() == HeapSpaceRegionKind;
350  }
351 };
352 
354  friend class MemRegionManager;
356  : MemSpaceRegion(mgr, UnknownSpaceRegionKind) {}
357 
358 public:
359 
360  void dumpToStream(raw_ostream &os) const override;
361 
362  static bool classof(const MemRegion *R) {
363  return R->getKind() == UnknownSpaceRegionKind;
364  }
365 };
366 
368  virtual void anchor();
369 
370  const StackFrameContext *SFC;
371 
372 protected:
374  : MemSpaceRegion(mgr, k), SFC(sfc) {
375  assert(classof(this));
376  assert(sfc);
377  }
378 
379 public:
380  const StackFrameContext *getStackFrame() const { return SFC; }
381 
382  void Profile(llvm::FoldingSetNodeID &ID) const override;
383 
384  static bool classof(const MemRegion *R) {
385  Kind k = R->getKind();
386  return k >= BEGIN_STACK_MEMSPACES && k <= END_STACK_MEMSPACES;
387  }
388 };
389 
391  friend class MemRegionManager;
393  : StackSpaceRegion(mgr, StackLocalsSpaceRegionKind, sfc) {}
394 public:
395 
396  void dumpToStream(raw_ostream &os) const override;
397 
398  static bool classof(const MemRegion *R) {
399  return R->getKind() == StackLocalsSpaceRegionKind;
400  }
401 };
402 
404 private:
405  friend class MemRegionManager;
407  : StackSpaceRegion(mgr, StackArgumentsSpaceRegionKind, sfc) {}
408 public:
409 
410  void dumpToStream(raw_ostream &os) const override;
411 
412  static bool classof(const MemRegion *R) {
413  return R->getKind() == StackArgumentsSpaceRegionKind;
414  }
415 };
416 
417 
418 /// SubRegion - A region that subsets another larger region. Most regions
419 /// are subclasses of SubRegion.
420 class SubRegion : public MemRegion {
421  virtual void anchor();
422 
423 protected:
425  SubRegion(const MemRegion *sReg, Kind k) : MemRegion(k), superRegion(sReg) {
426  assert(classof(this));
427  assert(sReg);
428  }
429 
430 public:
431  const MemRegion* getSuperRegion() const {
432  return superRegion;
433  }
434 
435  /// getExtent - Returns the size of the region in bytes.
436  virtual DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const {
437  return UnknownVal();
438  }
439 
440  MemRegionManager* getMemRegionManager() const override;
441 
442  bool isSubRegionOf(const MemRegion* R) const override;
443 
444  static bool classof(const MemRegion* R) {
445  return R->getKind() > END_MEMSPACES;
446  }
447 };
448 
449 //===----------------------------------------------------------------------===//
450 // MemRegion subclasses.
451 //===----------------------------------------------------------------------===//
452 
453 /// AllocaRegion - A region that represents an untyped blob of bytes created
454 /// by a call to 'alloca'.
455 class AllocaRegion : public SubRegion {
456  friend class MemRegionManager;
457 
458  unsigned Cnt; // Block counter. Used to distinguish different pieces of
459  // memory allocated by alloca at the same call site.
460  const Expr *Ex;
461 
462  AllocaRegion(const Expr *ex, unsigned cnt, const MemSpaceRegion *superRegion)
463  : SubRegion(superRegion, AllocaRegionKind), Cnt(cnt), Ex(ex) {
464  assert(Ex);
465  }
466 
467  static void ProfileRegion(llvm::FoldingSetNodeID& ID, const Expr *Ex,
468  unsigned Cnt, const MemRegion *superRegion);
469 
470 public:
471 
472  const Expr *getExpr() const { return Ex; }
473 
474  bool isBoundable() const override { return true; }
475 
476  DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const override;
477 
478  void Profile(llvm::FoldingSetNodeID& ID) const override;
479 
480  void dumpToStream(raw_ostream &os) const override;
481 
482  static bool classof(const MemRegion* R) {
483  return R->getKind() == AllocaRegionKind;
484  }
485 };
486 
487 /// TypedRegion - An abstract class representing regions that are typed.
488 class TypedRegion : public SubRegion {
489  virtual void anchor() override;
490 
491 protected:
492  TypedRegion(const MemRegion *sReg, Kind k) : SubRegion(sReg, k) {
493  assert(classof(this));
494  }
495 
496 public:
497  virtual QualType getLocationType() const = 0;
498 
500  return getLocationType().getDesugaredType(Context);
501  }
502 
503  bool isBoundable() const override { return true; }
504 
505  static bool classof(const MemRegion* R) {
506  unsigned k = R->getKind();
507  return k >= BEGIN_TYPED_REGIONS && k <= END_TYPED_REGIONS;
508  }
509 };
510 
511 /// TypedValueRegion - An abstract class representing regions having a typed value.
513  virtual void anchor() override;
514 
515 protected:
516  TypedValueRegion(const MemRegion* sReg, Kind k) : TypedRegion(sReg, k) {
517  assert(classof(this));
518  }
519 
520 public:
521  virtual QualType getValueType() const = 0;
522 
523  QualType getLocationType() const override {
524  // FIXME: We can possibly optimize this later to cache this value.
525  QualType T = getValueType();
526  ASTContext &ctx = getContext();
527  if (T->getAs<ObjCObjectType>())
528  return ctx.getObjCObjectPointerType(T);
529  return ctx.getPointerType(getValueType());
530  }
531 
533  QualType T = getValueType();
534  return T.getTypePtrOrNull() ? T.getDesugaredType(Context) : T;
535  }
536 
537  DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const override;
538 
539  static bool classof(const MemRegion* R) {
540  unsigned k = R->getKind();
541  return k >= BEGIN_TYPED_VALUE_REGIONS && k <= END_TYPED_VALUE_REGIONS;
542  }
543 };
544 
545 
546 class CodeTextRegion : public TypedRegion {
547  virtual void anchor() override;
548 
549 protected:
550  CodeTextRegion(const MemSpaceRegion *sreg, Kind k) : TypedRegion(sreg, k) {
551  assert(classof(this));
552  }
553 
554 public:
555  bool isBoundable() const override { return false; }
556 
557  static bool classof(const MemRegion* R) {
558  Kind k = R->getKind();
559  return k >= BEGIN_CODE_TEXT_REGIONS && k <= END_CODE_TEXT_REGIONS;
560  }
561 };
562 
563 /// FunctionCodeRegion - A region that represents code texts of function.
565  friend class MemRegionManager;
566 
567  const NamedDecl *FD;
568 
569  FunctionCodeRegion(const NamedDecl *fd, const CodeSpaceRegion* sreg)
570  : CodeTextRegion(sreg, FunctionCodeRegionKind), FD(fd) {
571  assert(isa<ObjCMethodDecl>(fd) || isa<FunctionDecl>(fd));
572  }
573 
574  static void ProfileRegion(llvm::FoldingSetNodeID& ID, const NamedDecl *FD,
575  const MemRegion*);
576 
577 public:
578  QualType getLocationType() const override {
579  const ASTContext &Ctx = getContext();
580  if (const FunctionDecl *D = dyn_cast<FunctionDecl>(FD)) {
581  return Ctx.getPointerType(D->getType());
582  }
583 
584  assert(isa<ObjCMethodDecl>(FD));
585  assert(false && "Getting the type of ObjCMethod is not supported yet");
586 
587  // TODO: We might want to return a different type here (ex: id (*ty)(...))
588  // depending on how it is used.
589  return QualType();
590  }
591 
592  const NamedDecl *getDecl() const {
593  return FD;
594  }
595 
596  void dumpToStream(raw_ostream &os) const override;
597 
598  void Profile(llvm::FoldingSetNodeID& ID) const override;
599 
600  static bool classof(const MemRegion* R) {
601  return R->getKind() == FunctionCodeRegionKind;
602  }
603 };
604 
605 
606 /// BlockCodeRegion - A region that represents code texts of blocks (closures).
607 /// Blocks are represented with two kinds of regions. BlockCodeRegions
608 /// represent the "code", while BlockDataRegions represent instances of blocks,
609 /// which correspond to "code+data". The distinction is important, because
610 /// like a closure a block captures the values of externally referenced
611 /// variables.
613  friend class MemRegionManager;
614 
615  const BlockDecl *BD;
617  CanQualType locTy;
618 
619  BlockCodeRegion(const BlockDecl *bd, CanQualType lTy,
620  AnalysisDeclContext *ac, const CodeSpaceRegion* sreg)
621  : CodeTextRegion(sreg, BlockCodeRegionKind), BD(bd), AC(ac), locTy(lTy) {
622  assert(bd);
623  assert(ac);
624  assert(lTy->getTypePtr()->isBlockPointerType());
625  }
626 
627  static void ProfileRegion(llvm::FoldingSetNodeID& ID, const BlockDecl *BD,
629  const MemRegion*);
630 
631 public:
632  QualType getLocationType() const override {
633  return locTy;
634  }
635 
636  const BlockDecl *getDecl() const {
637  return BD;
638  }
639 
641 
642  void dumpToStream(raw_ostream &os) const override;
643 
644  void Profile(llvm::FoldingSetNodeID& ID) const override;
645 
646  static bool classof(const MemRegion* R) {
647  return R->getKind() == BlockCodeRegionKind;
648  }
649 };
650 
651 /// BlockDataRegion - A region that represents a block instance.
652 /// Blocks are represented with two kinds of regions. BlockCodeRegions
653 /// represent the "code", while BlockDataRegions represent instances of blocks,
654 /// which correspond to "code+data". The distinction is important, because
655 /// like a closure a block captures the values of externally referenced
656 /// variables.
657 class BlockDataRegion : public TypedRegion {
658  friend class MemRegionManager;
659 
660  const BlockCodeRegion *BC;
661  const LocationContext *LC; // Can be null */
662  unsigned BlockCount;
663  void *ReferencedVars;
664  void *OriginalVars;
665 
666  BlockDataRegion(const BlockCodeRegion *bc, const LocationContext *lc,
667  unsigned count, const MemSpaceRegion *sreg)
668  : TypedRegion(sreg, BlockDataRegionKind), BC(bc), LC(lc),
669  BlockCount(count), ReferencedVars(nullptr), OriginalVars(nullptr) {
670  assert(bc);
671  assert(lc);
672  assert(isa<GlobalImmutableSpaceRegion>(sreg) ||
673  isa<StackLocalsSpaceRegion>(sreg) ||
674  isa<UnknownSpaceRegion>(sreg));
675  }
676 
677  static void ProfileRegion(llvm::FoldingSetNodeID&, const BlockCodeRegion *,
678  const LocationContext *, unsigned,
679  const MemRegion *);
680 
681 public:
682  const BlockCodeRegion *getCodeRegion() const { return BC; }
683 
684  const BlockDecl *getDecl() const { return BC->getDecl(); }
685 
686  QualType getLocationType() const override { return BC->getLocationType(); }
687 
689  const MemRegion * const *R;
690  const MemRegion * const *OriginalR;
691  public:
692  explicit referenced_vars_iterator(const MemRegion * const *r,
693  const MemRegion * const *originalR)
694  : R(r), OriginalR(originalR) {}
695 
696  const VarRegion *getCapturedRegion() const {
697  return cast<VarRegion>(*R);
698  }
699  const VarRegion *getOriginalRegion() const {
700  return cast<VarRegion>(*OriginalR);
701  }
702 
703  bool operator==(const referenced_vars_iterator &I) const {
704  assert((R == nullptr) == (I.R == nullptr));
705  return I.R == R;
706  }
707  bool operator!=(const referenced_vars_iterator &I) const {
708  assert((R == nullptr) == (I.R == nullptr));
709  return I.R != R;
710  }
712  ++R;
713  ++OriginalR;
714  return *this;
715  }
716  };
717 
718  /// Return the original region for a captured region, if
719  /// one exists.
720  const VarRegion *getOriginalRegion(const VarRegion *VR) const;
721 
722  referenced_vars_iterator referenced_vars_begin() const;
723  referenced_vars_iterator referenced_vars_end() const;
724 
725  void dumpToStream(raw_ostream &os) const override;
726 
727  void Profile(llvm::FoldingSetNodeID& ID) const override;
728 
729  static bool classof(const MemRegion* R) {
730  return R->getKind() == BlockDataRegionKind;
731  }
732 private:
733  void LazyInitializeReferencedVars();
734  std::pair<const VarRegion *, const VarRegion *>
735  getCaptureRegions(const VarDecl *VD);
736 };
737 
738 /// SymbolicRegion - A special, "non-concrete" region. Unlike other region
739 /// classes, SymbolicRegion represents a region that serves as an alias for
740 /// either a real region, a NULL pointer, etc. It essentially is used to
741 /// map the concept of symbolic values into the domain of regions. Symbolic
742 /// regions do not need to be typed.
743 class SymbolicRegion : public SubRegion {
744  friend class MemRegionManager;
745 
746  const SymbolRef sym;
747 
748  SymbolicRegion(const SymbolRef s, const MemSpaceRegion *sreg)
749  : SubRegion(sreg, SymbolicRegionKind), sym(s) {
750  assert(s);
751  assert(s->getType()->isAnyPointerType() ||
752  s->getType()->isReferenceType() ||
753  s->getType()->isBlockPointerType());
754  assert(isa<UnknownSpaceRegion>(sreg) || isa<HeapSpaceRegion>(sreg));
755  }
756 
757 public:
759  return sym;
760  }
761 
762  bool isBoundable() const override { return true; }
763 
764  DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const override;
765 
766  void Profile(llvm::FoldingSetNodeID& ID) const override;
767 
768  static void ProfileRegion(llvm::FoldingSetNodeID& ID,
769  SymbolRef sym,
770  const MemRegion* superRegion);
771 
772  void dumpToStream(raw_ostream &os) const override;
773 
774  static bool classof(const MemRegion* R) {
775  return R->getKind() == SymbolicRegionKind;
776  }
777 };
778 
779 /// StringRegion - Region associated with a StringLiteral.
781  friend class MemRegionManager;
782 
783  const StringLiteral* Str;
784 
785  StringRegion(const StringLiteral *str, const GlobalInternalSpaceRegion *sreg)
786  : TypedValueRegion(sreg, StringRegionKind), Str(str) {
787  assert(str);
788  }
789 
790  static void ProfileRegion(llvm::FoldingSetNodeID& ID,
791  const StringLiteral* Str,
792  const MemRegion* superRegion);
793 
794 public:
795 
796  const StringLiteral* getStringLiteral() const { return Str; }
797 
798  QualType getValueType() const override {
799  return Str->getType();
800  }
801 
802  DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const override;
803 
804  bool isBoundable() const override { return false; }
805 
806  void Profile(llvm::FoldingSetNodeID& ID) const override {
807  ProfileRegion(ID, Str, superRegion);
808  }
809 
810  void dumpToStream(raw_ostream &os) const override;
811 
812  static bool classof(const MemRegion* R) {
813  return R->getKind() == StringRegionKind;
814  }
815 };
816 
817 /// The region associated with an ObjCStringLiteral.
819  friend class MemRegionManager;
820 
821  const ObjCStringLiteral* Str;
822 
824  const GlobalInternalSpaceRegion *sreg)
825  : TypedValueRegion(sreg, ObjCStringRegionKind), Str(str) {
826  assert(str);
827  }
828 
829  static void ProfileRegion(llvm::FoldingSetNodeID& ID,
830  const ObjCStringLiteral* Str,
831  const MemRegion* superRegion);
832 
833 public:
834 
835  const ObjCStringLiteral* getObjCStringLiteral() const { return Str; }
836 
837  QualType getValueType() const override {
838  return Str->getType();
839  }
840 
841  bool isBoundable() const override { return false; }
842 
843  void Profile(llvm::FoldingSetNodeID& ID) const override {
844  ProfileRegion(ID, Str, superRegion);
845  }
846 
847  void dumpToStream(raw_ostream &os) const override;
848 
849  static bool classof(const MemRegion* R) {
850  return R->getKind() == ObjCStringRegionKind;
851  }
852 };
853 
854 /// CompoundLiteralRegion - A memory region representing a compound literal.
855 /// Compound literals are essentially temporaries that are stack allocated
856 /// or in the global constant pool.
858  friend class MemRegionManager;
859 
860  const CompoundLiteralExpr *CL;
861 
863  const MemSpaceRegion *sReg)
864  : TypedValueRegion(sReg, CompoundLiteralRegionKind), CL(cl) {
865  assert(cl);
866  assert(isa<GlobalInternalSpaceRegion>(sReg) ||
867  isa<StackLocalsSpaceRegion>(sReg));
868  }
869 
870  static void ProfileRegion(llvm::FoldingSetNodeID& ID,
871  const CompoundLiteralExpr *CL,
872  const MemRegion* superRegion);
873 public:
874  QualType getValueType() const override {
875  return CL->getType();
876  }
877 
878  bool isBoundable() const override { return !CL->isFileScope(); }
879 
880  void Profile(llvm::FoldingSetNodeID& ID) const override;
881 
882  void dumpToStream(raw_ostream &os) const override;
883 
884  const CompoundLiteralExpr *getLiteralExpr() const { return CL; }
885 
886  static bool classof(const MemRegion* R) {
887  return R->getKind() == CompoundLiteralRegionKind;
888  }
889 };
890 
891 class DeclRegion : public TypedValueRegion {
892 protected:
893  const Decl *D;
894 
895  DeclRegion(const Decl *d, const MemRegion *sReg, Kind k)
896  : TypedValueRegion(sReg, k), D(d) {
897  assert(classof(this));
898  assert(d);
899  }
900 
901  static void ProfileRegion(llvm::FoldingSetNodeID& ID, const Decl *D,
902  const MemRegion* superRegion, Kind k);
903 
904 public:
905  const Decl *getDecl() const { return D; }
906  void Profile(llvm::FoldingSetNodeID& ID) const override;
907 
908  static bool classof(const MemRegion* R) {
909  unsigned k = R->getKind();
910  return k >= BEGIN_DECL_REGIONS && k <= END_DECL_REGIONS;
911  }
912 };
913 
914 class VarRegion : public DeclRegion {
915  friend class MemRegionManager;
916 
917  // Constructors and private methods.
918  VarRegion(const VarDecl *vd, const MemRegion *sReg)
919  : DeclRegion(vd, sReg, VarRegionKind) {
920  // VarRegion appears in unknown space when it's a block variable as seen
921  // from a block using it, when this block is analyzed at top-level.
922  // Other block variables appear within block data regions,
923  // which, unlike everything else on this list, are not memory spaces.
924  assert(isa<GlobalsSpaceRegion>(sReg) || isa<StackSpaceRegion>(sReg) ||
925  isa<BlockDataRegion>(sReg) || isa<UnknownSpaceRegion>(sReg));
926  }
927 
928  static void ProfileRegion(llvm::FoldingSetNodeID& ID, const VarDecl *VD,
929  const MemRegion *superRegion) {
930  DeclRegion::ProfileRegion(ID, VD, superRegion, VarRegionKind);
931  }
932 
933 public:
934  void Profile(llvm::FoldingSetNodeID& ID) const override;
935 
936  const VarDecl *getDecl() const { return cast<VarDecl>(D); }
937 
938  const StackFrameContext *getStackFrame() const;
939 
940  QualType getValueType() const override {
941  // FIXME: We can cache this if needed.
942  return getDecl()->getType();
943  }
944 
945  void dumpToStream(raw_ostream &os) const override;
946 
947  static bool classof(const MemRegion* R) {
948  return R->getKind() == VarRegionKind;
949  }
950 
951  bool canPrintPrettyAsExpr() const override;
952 
953  void printPrettyAsExpr(raw_ostream &os) const override;
954 };
955 
956 /// CXXThisRegion - Represents the region for the implicit 'this' parameter
957 /// in a call to a C++ method. This region doesn't represent the object
958 /// referred to by 'this', but rather 'this' itself.
960  friend class MemRegionManager;
961 
962  CXXThisRegion(const PointerType *thisPointerTy,
963  const StackArgumentsSpaceRegion *sReg)
964  : TypedValueRegion(sReg, CXXThisRegionKind),
965  ThisPointerTy(thisPointerTy) {
966  assert(ThisPointerTy->getPointeeType()->getAsCXXRecordDecl() &&
967  "Invalid region type!");
968  }
969 
970  static void ProfileRegion(llvm::FoldingSetNodeID &ID,
971  const PointerType *PT,
972  const MemRegion *sReg);
973 
974 public:
975  void Profile(llvm::FoldingSetNodeID &ID) const override;
976 
977  QualType getValueType() const override {
978  return QualType(ThisPointerTy, 0);
979  }
980 
981  void dumpToStream(raw_ostream &os) const override;
982 
983  static bool classof(const MemRegion* R) {
984  return R->getKind() == CXXThisRegionKind;
985  }
986 
987 private:
988  const PointerType *ThisPointerTy;
989 };
990 
991 class FieldRegion : public DeclRegion {
992  friend class MemRegionManager;
993 
994  FieldRegion(const FieldDecl *fd, const SubRegion* sReg)
995  : DeclRegion(fd, sReg, FieldRegionKind) {}
996 
997  static void ProfileRegion(llvm::FoldingSetNodeID& ID, const FieldDecl *FD,
998  const MemRegion* superRegion) {
999  DeclRegion::ProfileRegion(ID, FD, superRegion, FieldRegionKind);
1000  }
1001 
1002 public:
1003  const FieldDecl *getDecl() const { return cast<FieldDecl>(D); }
1004 
1005  QualType getValueType() const override {
1006  // FIXME: We can cache this if needed.
1007  return getDecl()->getType();
1008  }
1009 
1010  DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const override;
1011 
1012  static bool classof(const MemRegion* R) {
1013  return R->getKind() == FieldRegionKind;
1014  }
1015 
1016  void dumpToStream(raw_ostream &os) const override;
1017 
1018  bool canPrintPretty() const override;
1019  void printPretty(raw_ostream &os) const override;
1020  bool canPrintPrettyAsExpr() const override;
1021  void printPrettyAsExpr(raw_ostream &os) const override;
1022 };
1023 
1024 class ObjCIvarRegion : public DeclRegion {
1025  friend class MemRegionManager;
1026 
1027  ObjCIvarRegion(const ObjCIvarDecl *ivd, const SubRegion *sReg);
1028 
1029  static void ProfileRegion(llvm::FoldingSetNodeID& ID, const ObjCIvarDecl *ivd,
1030  const MemRegion* superRegion);
1031 
1032 public:
1033  const ObjCIvarDecl *getDecl() const;
1034  QualType getValueType() const override;
1035 
1036  bool canPrintPrettyAsExpr() const override;
1037  void printPrettyAsExpr(raw_ostream &os) const override;
1038 
1039  void dumpToStream(raw_ostream &os) const override;
1040 
1041  static bool classof(const MemRegion* R) {
1042  return R->getKind() == ObjCIvarRegionKind;
1043  }
1044 };
1045 //===----------------------------------------------------------------------===//
1046 // Auxiliary data classes for use with MemRegions.
1047 //===----------------------------------------------------------------------===//
1048 
1049 class ElementRegion;
1050 
1052  friend class ElementRegion;
1053 
1054  const MemRegion *Region;
1055  CharUnits Offset;
1056 
1057  RegionRawOffset(const MemRegion* reg, CharUnits offset = CharUnits::Zero())
1058  : Region(reg), Offset(offset) {}
1059 
1060 public:
1061  // FIXME: Eventually support symbolic offsets.
1062  CharUnits getOffset() const { return Offset; }
1063  const MemRegion *getRegion() const { return Region; }
1064 
1065  void dumpToStream(raw_ostream &os) const;
1066  void dump() const;
1067 };
1068 
1069 /// \brief ElementRegin is used to represent both array elements and casts.
1071  friend class MemRegionManager;
1072 
1073  QualType ElementType;
1074  NonLoc Index;
1075 
1076  ElementRegion(QualType elementType, NonLoc Idx, const SubRegion *sReg)
1077  : TypedValueRegion(sReg, ElementRegionKind),
1078  ElementType(elementType), Index(Idx) {
1079  assert((!Idx.getAs<nonloc::ConcreteInt>() ||
1080  Idx.castAs<nonloc::ConcreteInt>().getValue().isSigned()) &&
1081  "The index must be signed");
1082  assert(!elementType.isNull() && !elementType->isVoidType() &&
1083  "Invalid region type!");
1084  }
1085 
1086  static void ProfileRegion(llvm::FoldingSetNodeID& ID, QualType elementType,
1087  SVal Idx, const MemRegion* superRegion);
1088 
1089 public:
1090 
1091  NonLoc getIndex() const { return Index; }
1092 
1093  QualType getValueType() const override {
1094  return ElementType;
1095  }
1096 
1098  return ElementType;
1099  }
1100  /// Compute the offset within the array. The array might also be a subobject.
1101  RegionRawOffset getAsArrayOffset() const;
1102 
1103  void dumpToStream(raw_ostream &os) const override;
1104 
1105  void Profile(llvm::FoldingSetNodeID& ID) const override;
1106 
1107  static bool classof(const MemRegion* R) {
1108  return R->getKind() == ElementRegionKind;
1109  }
1110 };
1111 
1112 // C++ temporary object associated with an expression.
1114  friend class MemRegionManager;
1115 
1116  Expr const *Ex;
1117 
1118  CXXTempObjectRegion(Expr const *E, MemSpaceRegion const *sReg)
1119  : TypedValueRegion(sReg, CXXTempObjectRegionKind), Ex(E) {
1120  assert(E);
1121  assert(isa<StackLocalsSpaceRegion>(sReg) ||
1122  isa<GlobalInternalSpaceRegion>(sReg));
1123  }
1124 
1125  static void ProfileRegion(llvm::FoldingSetNodeID &ID,
1126  Expr const *E, const MemRegion *sReg);
1127 
1128 public:
1129  const Expr *getExpr() const { return Ex; }
1130 
1131  QualType getValueType() const override {
1132  return Ex->getType();
1133  }
1134 
1135  void dumpToStream(raw_ostream &os) const override;
1136 
1137  void Profile(llvm::FoldingSetNodeID &ID) const override;
1138 
1139  static bool classof(const MemRegion* R) {
1140  return R->getKind() == CXXTempObjectRegionKind;
1141  }
1142 };
1143 
1144 // CXXBaseObjectRegion represents a base object within a C++ object. It is
1145 // identified by the base class declaration and the region of its parent object.
1147  friend class MemRegionManager;
1148 
1149  llvm::PointerIntPair<const CXXRecordDecl *, 1, bool> Data;
1150 
1151  CXXBaseObjectRegion(const CXXRecordDecl *RD, bool IsVirtual,
1152  const SubRegion *SReg)
1153  : TypedValueRegion(SReg, CXXBaseObjectRegionKind), Data(RD, IsVirtual) {
1154  assert(RD);
1155  }
1156 
1157  static void ProfileRegion(llvm::FoldingSetNodeID &ID, const CXXRecordDecl *RD,
1158  bool IsVirtual, const MemRegion *SReg);
1159 
1160 public:
1161  const CXXRecordDecl *getDecl() const { return Data.getPointer(); }
1162  bool isVirtual() const { return Data.getInt(); }
1163 
1164  QualType getValueType() const override;
1165 
1166  void dumpToStream(raw_ostream &os) const override;
1167 
1168  void Profile(llvm::FoldingSetNodeID &ID) const override;
1169 
1170  static bool classof(const MemRegion *region) {
1171  return region->getKind() == CXXBaseObjectRegionKind;
1172  }
1173 
1174  bool canPrintPrettyAsExpr() const override;
1175 
1176  void printPrettyAsExpr(raw_ostream &os) const override;
1177 };
1178 
1179 template<typename RegionTy>
1180 const RegionTy* MemRegion::getAs() const {
1181  if (const RegionTy* RT = dyn_cast<RegionTy>(this))
1182  return RT;
1183 
1184  return nullptr;
1185 }
1186 
1187 //===----------------------------------------------------------------------===//
1188 // MemRegionManager - Factory object for creating regions.
1189 //===----------------------------------------------------------------------===//
1190 
1192  ASTContext &C;
1193  llvm::BumpPtrAllocator& A;
1194  llvm::FoldingSet<MemRegion> Regions;
1195 
1196  GlobalInternalSpaceRegion *InternalGlobals;
1197  GlobalSystemSpaceRegion *SystemGlobals;
1198  GlobalImmutableSpaceRegion *ImmutableGlobals;
1199 
1200 
1201  llvm::DenseMap<const StackFrameContext *, StackLocalsSpaceRegion *>
1202  StackLocalsSpaceRegions;
1203  llvm::DenseMap<const StackFrameContext *, StackArgumentsSpaceRegion *>
1204  StackArgumentsSpaceRegions;
1205  llvm::DenseMap<const CodeTextRegion *, StaticGlobalSpaceRegion *>
1206  StaticsGlobalSpaceRegions;
1207 
1208  HeapSpaceRegion *heap;
1209  UnknownSpaceRegion *unknown;
1210  CodeSpaceRegion *code;
1211 
1212 public:
1213  MemRegionManager(ASTContext &c, llvm::BumpPtrAllocator &a)
1214  : C(c), A(a), InternalGlobals(nullptr), SystemGlobals(nullptr),
1215  ImmutableGlobals(nullptr), heap(nullptr), unknown(nullptr),
1216  code(nullptr) {}
1217 
1218  ~MemRegionManager();
1219 
1220  ASTContext &getContext() { return C; }
1221 
1222  llvm::BumpPtrAllocator &getAllocator() { return A; }
1223 
1224  /// getStackLocalsRegion - Retrieve the memory region associated with the
1225  /// specified stack frame.
1226  const StackLocalsSpaceRegion *
1227  getStackLocalsRegion(const StackFrameContext *STC);
1228 
1229  /// getStackArgumentsRegion - Retrieve the memory region associated with
1230  /// function/method arguments of the specified stack frame.
1232  getStackArgumentsRegion(const StackFrameContext *STC);
1233 
1234  /// getGlobalsRegion - Retrieve the memory region associated with
1235  /// global variables.
1236  const GlobalsSpaceRegion *getGlobalsRegion(
1237  MemRegion::Kind K = MemRegion::GlobalInternalSpaceRegionKind,
1238  const CodeTextRegion *R = nullptr);
1239 
1240  /// getHeapRegion - Retrieve the memory region associated with the
1241  /// generic "heap".
1242  const HeapSpaceRegion *getHeapRegion();
1243 
1244  /// getUnknownRegion - Retrieve the memory region associated with unknown
1245  /// memory space.
1246  const UnknownSpaceRegion *getUnknownRegion();
1247 
1248  const CodeSpaceRegion *getCodeRegion();
1249 
1250  /// getAllocaRegion - Retrieve a region associated with a call to alloca().
1251  const AllocaRegion *getAllocaRegion(const Expr *Ex, unsigned Cnt,
1252  const LocationContext *LC);
1253 
1254  /// getCompoundLiteralRegion - Retrieve the region associated with a
1255  /// given CompoundLiteral.
1256  const CompoundLiteralRegion*
1257  getCompoundLiteralRegion(const CompoundLiteralExpr *CL,
1258  const LocationContext *LC);
1259 
1260  /// getCXXThisRegion - Retrieve the [artificial] region associated with the
1261  /// parameter 'this'.
1262  const CXXThisRegion *getCXXThisRegion(QualType thisPointerTy,
1263  const LocationContext *LC);
1264 
1265  /// \brief Retrieve or create a "symbolic" memory region.
1266  const SymbolicRegion* getSymbolicRegion(SymbolRef Sym);
1267 
1268  /// \brief Return a unique symbolic region belonging to heap memory space.
1269  const SymbolicRegion *getSymbolicHeapRegion(SymbolRef sym);
1270 
1271  const StringRegion *getStringRegion(const StringLiteral* Str);
1272 
1273  const ObjCStringRegion *getObjCStringRegion(const ObjCStringLiteral *Str);
1274 
1275  /// getVarRegion - Retrieve or create the memory region associated with
1276  /// a specified VarDecl and LocationContext.
1277  const VarRegion* getVarRegion(const VarDecl *D, const LocationContext *LC);
1278 
1279  /// getVarRegion - Retrieve or create the memory region associated with
1280  /// a specified VarDecl and super region.
1281  const VarRegion *getVarRegion(const VarDecl *D, const MemRegion *superR);
1282 
1283  /// getElementRegion - Retrieve the memory region associated with the
1284  /// associated element type, index, and super region.
1285  const ElementRegion *getElementRegion(QualType elementType, NonLoc Idx,
1286  const SubRegion *superRegion,
1287  ASTContext &Ctx);
1288 
1290  const SubRegion *superRegion) {
1291  return getElementRegion(ER->getElementType(), ER->getIndex(),
1292  superRegion, ER->getContext());
1293  }
1294 
1295  /// getFieldRegion - Retrieve or create the memory region associated with
1296  /// a specified FieldDecl. 'superRegion' corresponds to the containing
1297  /// memory region (which typically represents the memory representing
1298  /// a structure or class).
1299  const FieldRegion *getFieldRegion(const FieldDecl *fd,
1300  const SubRegion* superRegion);
1301 
1303  const SubRegion *superRegion) {
1304  return getFieldRegion(FR->getDecl(), superRegion);
1305  }
1306 
1307  /// getObjCIvarRegion - Retrieve or create the memory region associated with
1308  /// a specified Objective-c instance variable. 'superRegion' corresponds
1309  /// to the containing region (which typically represents the Objective-C
1310  /// object).
1311  const ObjCIvarRegion *getObjCIvarRegion(const ObjCIvarDecl *ivd,
1312  const SubRegion* superRegion);
1313 
1314  const CXXTempObjectRegion *getCXXTempObjectRegion(Expr const *Ex,
1315  LocationContext const *LC);
1316 
1317  /// Create a CXXBaseObjectRegion with the given base class for region
1318  /// \p Super.
1319  ///
1320  /// The type of \p Super is assumed be a class deriving from \p BaseClass.
1321  const CXXBaseObjectRegion *
1322  getCXXBaseObjectRegion(const CXXRecordDecl *BaseClass, const SubRegion *Super,
1323  bool IsVirtual);
1324 
1325  /// Create a CXXBaseObjectRegion with the same CXXRecordDecl but a different
1326  /// super region.
1327  const CXXBaseObjectRegion *
1329  const SubRegion *superRegion) {
1330  return getCXXBaseObjectRegion(baseReg->getDecl(), superRegion,
1331  baseReg->isVirtual());
1332  }
1333 
1334  const FunctionCodeRegion *getFunctionCodeRegion(const NamedDecl *FD);
1335  const BlockCodeRegion *getBlockCodeRegion(const BlockDecl *BD,
1336  CanQualType locTy,
1337  AnalysisDeclContext *AC);
1338 
1339  /// getBlockDataRegion - Get the memory region associated with an instance
1340  /// of a block. Unlike many other MemRegions, the LocationContext*
1341  /// argument is allowed to be NULL for cases where we have no known
1342  /// context.
1343  const BlockDataRegion *getBlockDataRegion(const BlockCodeRegion *bc,
1344  const LocationContext *lc,
1345  unsigned blockCount);
1346 
1347  /// Create a CXXTempObjectRegion for temporaries which are lifetime-extended
1348  /// by static references. This differs from getCXXTempObjectRegion in the
1349  /// super-region used.
1350  const CXXTempObjectRegion *getCXXStaticTempObjectRegion(const Expr *Ex);
1351 
1352 private:
1353  template <typename RegionTy, typename SuperTy,
1354  typename Arg1Ty>
1355  RegionTy* getSubRegion(const Arg1Ty arg1,
1356  const SuperTy* superRegion);
1357 
1358  template <typename RegionTy, typename SuperTy,
1359  typename Arg1Ty, typename Arg2Ty>
1360  RegionTy* getSubRegion(const Arg1Ty arg1, const Arg2Ty arg2,
1361  const SuperTy* superRegion);
1362 
1363  template <typename RegionTy, typename SuperTy,
1364  typename Arg1Ty, typename Arg2Ty, typename Arg3Ty>
1365  RegionTy* getSubRegion(const Arg1Ty arg1, const Arg2Ty arg2,
1366  const Arg3Ty arg3,
1367  const SuperTy* superRegion);
1368 
1369  template <typename REG>
1370  const REG* LazyAllocate(REG*& region);
1371 
1372  template <typename REG, typename ARG>
1373  const REG* LazyAllocate(REG*& region, ARG a);
1374 };
1375 
1376 //===----------------------------------------------------------------------===//
1377 // Out-of-line member definitions.
1378 //===----------------------------------------------------------------------===//
1379 
1381  return getMemRegionManager()->getContext();
1382 }
1383 
1384 //===----------------------------------------------------------------------===//
1385 // Means for storing region/symbol handling traits.
1386 //===----------------------------------------------------------------------===//
1387 
1388 /// Information about invalidation for a particular region/symbol.
1390  typedef unsigned char StorageTypeForKinds;
1391  llvm::DenseMap<const MemRegion *, StorageTypeForKinds> MRTraitsMap;
1392  llvm::DenseMap<SymbolRef, StorageTypeForKinds> SymTraitsMap;
1393 
1394  typedef llvm::DenseMap<const MemRegion *, StorageTypeForKinds>::const_iterator
1395  const_region_iterator;
1396  typedef llvm::DenseMap<SymbolRef, StorageTypeForKinds>::const_iterator
1397  const_symbol_iterator;
1398 
1399 public:
1400  /// \brief Describes different invalidation traits.
1402  /// Tells that a region's contents is not changed.
1403  TK_PreserveContents = 0x1,
1404  /// Suppress pointer-escaping of a region.
1405  TK_SuppressEscape = 0x2,
1406  // Do not invalidate super region.
1407  TK_DoNotInvalidateSuperRegion = 0x4,
1408  /// When applied to a MemSpaceRegion, indicates the entire memory space
1409  /// should be invalidated.
1410  TK_EntireMemSpace = 0x8
1411 
1412  // Do not forget to extend StorageTypeForKinds if number of traits exceed
1413  // the number of bits StorageTypeForKinds can store.
1414  };
1415 
1416  void setTrait(SymbolRef Sym, InvalidationKinds IK);
1417  void setTrait(const MemRegion *MR, InvalidationKinds IK);
1418  bool hasTrait(SymbolRef Sym, InvalidationKinds IK) const;
1419  bool hasTrait(const MemRegion *MR, InvalidationKinds IK) const;
1420 };
1421 
1422 //===----------------------------------------------------------------------===//
1423 // Pretty-printing regions.
1424 //===----------------------------------------------------------------------===//
1425 inline raw_ostream &operator<<(raw_ostream &os,
1426  const clang::ento::MemRegion *R) {
1427  R->dumpToStream(os);
1428  return os;
1429 }
1430 
1431 } // namespace ento
1432 
1433 } // namespace clang
1434 
1435 #endif
RegionOffset(const MemRegion *r, int64_t off)
Definition: MemRegion.h:60
const ElementRegion * getElementRegionWithSuper(const ElementRegion *ER, const SubRegion *superRegion)
Definition: MemRegion.h:1289
bool isBoundable() const override
Definition: MemRegion.h:878
Defines the clang::ASTContext interface.
CodeTextRegion(const MemSpaceRegion *sreg, Kind k)
Definition: MemRegion.h:550
Represents a function declaration or definition.
Definition: Decl.h:1696
TypedValueRegion - An abstract class representing regions having a typed value.
Definition: MemRegion.h:512
static bool classof(const MemRegion *R)
Definition: MemRegion.h:1012
CompoundLiteralRegion - A memory region representing a compound literal.
Definition: MemRegion.h:857
QualType getValueType() const override
Definition: MemRegion.h:977
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2289
A (possibly-)qualified type.
Definition: Type.h:653
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:79
bool isBlockPointerType() const
Definition: Type.h:5956
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
Definition: Type.h:951
SubRegion(const MemRegion *sReg, Kind k)
Definition: MemRegion.h:425
Information about invalidation for a particular region/symbol.
Definition: MemRegion.h:1389
NonLoc getIndex() const
Definition: MemRegion.h:1091
MemRegionManager * getMemRegionManager() const override
Definition: MemRegion.h:189
virtual void dumpToStream(raw_ostream &os) const
Definition: MemRegion.cpp:406
BlockCodeRegion - A region that represents code texts of blocks (closures).
Definition: MemRegion.h:612
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
static bool classof(const MemRegion *R)
Definition: MemRegion.h:886
static bool classof(const MemRegion *R)
Definition: MemRegion.h:983
QualType getLocationType() const override
Definition: MemRegion.h:686
const NamedDecl * getDecl() const
Definition: MemRegion.h:592
const MemRegion * getRegion() const
Definition: MemRegion.h:62
MemSpaceRegion - A memory region that represents a "memory space"; for example, the set of global var...
Definition: MemRegion.h:180
static bool classof(const MemRegion *region)
Definition: MemRegion.h:1170
const ObjCStringLiteral * getObjCStringLiteral() const
Definition: MemRegion.h:835
static bool classof(const MemRegion *R)
Definition: MemRegion.h:1107
Value representing integer constant.
Definition: SVals.h:353
const CXXBaseObjectRegion * getCXXBaseObjectRegionWithSuper(const CXXBaseObjectRegion *baseReg, const SubRegion *superRegion)
Create a CXXBaseObjectRegion with the same CXXRecordDecl but a different super region.
Definition: MemRegion.h:1328
AllocaRegion - A region that represents an untyped blob of bytes created by a call to &#39;alloca&#39;...
Definition: MemRegion.h:455
static bool classof(const MemRegion *R)
Definition: MemRegion.h:539
bool operator==(const referenced_vars_iterator &I) const
Definition: MemRegion.h:703
CodeSpaceRegion - The memory space that holds the executable code of functions and blocks...
Definition: MemRegion.h:204
CharUnits getOffset() const
Definition: MemRegion.h:1062
Represents a variable declaration or definition.
Definition: Decl.h:812
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:2650
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6317
QualType getElementType() const
Definition: MemRegion.h:1097
AnalysisDeclContext * getAnalysisDeclContext() const
Definition: MemRegion.h:640
Symbolic value.
Definition: SymExpr.h:29
CXXThisRegion - Represents the region for the implicit &#39;this&#39; parameter in a call to a C++ method...
Definition: MemRegion.h:959
const MemRegion * getSuperRegion() const
Definition: MemRegion.h:431
GlobalsSpaceRegion(MemRegionManager *mgr, Kind k)
Definition: MemRegion.h:222
The region containing globals which can be modified by calls to "internally" defined functions - (for...
Definition: MemRegion.h:324
The region associated with an ObjCStringLiteral.
Definition: MemRegion.h:818
Represents a class type in Objective C.
Definition: Type.h:5190
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:149
bool isFileScope() const
Definition: Expr.h:2680
bool isValid() const
Definition: MemRegion.h:71
const FieldDecl * getDecl() const
Definition: MemRegion.h:1003
Represents a member of a struct/union/class.
Definition: Decl.h:2488
ASTContext & getContext() const
Definition: MemRegion.h:1380
AnalysisDeclContext contains the context data for the function or method under analysis.
QualType getLocationType() const override
Definition: MemRegion.h:578
bool isReferenceType() const
Definition: Type.h:5960
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Definition: CharUnits.h:53
virtual DefinedOrUnknownSVal getExtent(SValBuilder &svalBuilder) const
getExtent - Returns the size of the region in bytes.
Definition: MemRegion.h:436
QualType getValueType() const override
Definition: MemRegion.h:874
bool isBoundable() const override
Definition: MemRegion.h:841
The region containing globals which are considered not to be modified or point to data which could be...
Definition: MemRegion.h:306
static bool classof(const MemRegion *R)
Definition: MemRegion.h:227
BlockDataRegion - A region that represents a block instance.
Definition: MemRegion.h:657
static bool classof(const MemRegion *R)
Definition: MemRegion.h:1041
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
uint32_t Offset
Definition: CacheTokens.cpp:43
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
const CXXRecordDecl * getDecl() const
Definition: MemRegion.h:1161
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
referenced_vars_iterator(const MemRegion *const *r, const MemRegion *const *originalR)
Definition: MemRegion.h:692
static bool classof(const MemRegion *R)
Definition: MemRegion.h:398
static bool classof(const MemRegion *R)
Definition: MemRegion.h:1139
ObjCStringLiteral, used for Objective-C string literals i.e.
Definition: ExprObjC.h:51
static bool classof(const MemRegion *R)
Definition: MemRegion.h:255
const StringLiteral * getStringLiteral() const
Definition: MemRegion.h:796
QualType getValueType() const override
Definition: MemRegion.h:940
Represent a region&#39;s offset within the top level base region.
Definition: MemRegion.h:47
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
Definition: CanonicalType.h:84
static void ProfileRegion(llvm::FoldingSetNodeID &ID, const Decl *D, const MemRegion *superRegion, Kind k)
Definition: MemRegion.cpp:277
virtual QualType getType() const =0
static bool classof(const MemRegion *R)
Definition: MemRegion.h:812
QualType getValueType() const override
Definition: MemRegion.h:798
bool operator!=(const referenced_vars_iterator &I) const
Definition: MemRegion.h:707
static bool classof(const MemRegion *R)
Definition: MemRegion.h:362
const RegionTy * getAs() const
Definition: MemRegion.h:1180
SymbolicRegion - A special, "non-concrete" region.
Definition: MemRegion.h:743
Pepresents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:3713
Expr - This represents one expression.
Definition: Expr.h:106
TypedValueRegion(const MemRegion *sReg, Kind k)
Definition: MemRegion.h:516
const FunctionProtoType * T
static const int64_t Symbolic
Definition: MemRegion.h:57
const Decl * getDecl() const
Definition: MemRegion.h:905
llvm::BumpPtrAllocator & getAllocator()
Definition: MemRegion.h:1222
static bool classof(const MemRegion *R)
Definition: MemRegion.h:729
QualType getType() const
Definition: Expr.h:128
QualType getDesugaredValueType(ASTContext &Context) const
Definition: MemRegion.h:532
const BlockCodeRegion * getCodeRegion() const
Definition: MemRegion.h:682
static bool classof(const MemRegion *R)
Definition: MemRegion.h:908
static bool classof(const MemRegion *R)
Definition: MemRegion.h:557
static bool classof(const MemRegion *R)
Definition: MemRegion.h:646
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:719
static bool classof(const MemRegion *R)
Definition: MemRegion.h:482
TypedRegion(const MemRegion *sReg, Kind k)
Definition: MemRegion.h:492
const StackFrameContext * getStackFrame() const
Definition: MemRegion.h:380
The region of the static variables within the current CodeTextRegion scope.
Definition: MemRegion.h:238
Optional< T > getAs() const
Convert to the specified SVal type, returning None if this SVal is not of the desired type...
Definition: SVals.h:100
const VarDecl * getDecl() const
Definition: MemRegion.h:936
virtual bool isBoundable() const
Definition: MemRegion.h:153
The region for all the non-static global variables.
Definition: MemRegion.h:266
Kind getKind() const
Definition: MemRegion.h:149
static bool classof(const MemRegion *R)
Definition: MemRegion.h:849
const BlockDecl * getDecl() const
Definition: MemRegion.h:636
QualType getValueType() const override
Definition: MemRegion.h:1131
Kind
static bool classof(const MemRegion *R)
Definition: MemRegion.h:774
FunctionCodeRegion - A region that represents code texts of function.
Definition: MemRegion.h:564
SymbolRef getSymbol() const
Definition: MemRegion.h:758
const CompoundLiteralExpr * getLiteralExpr() const
Definition: MemRegion.h:884
bool isBoundable() const override
Definition: MemRegion.h:503
static bool classof(const MemRegion *R)
Definition: MemRegion.h:384
SVal - This represents a symbolic expression, which can be either an L-value or an R-value...
Definition: SVals.h:63
bool isBoundable() const override
Definition: MemRegion.h:762
bool isAnyPointerType() const
Definition: Type.h:5952
QualType getLocationType() const override
Definition: MemRegion.h:523
static bool classof(const MemRegion *R)
Definition: MemRegion.h:316
static bool classof(const MemRegion *R)
Definition: MemRegion.h:444
bool isBoundable() const override
Definition: MemRegion.h:474
static bool classof(const MemRegion *R)
Definition: MemRegion.h:277
Dataflow Directional Tag Classes.
raw_ostream & operator<<(raw_ostream &Out, const CheckerBase &Checker)
Dump checker name to stream.
Definition: Checker.cpp:34
QualType getValueType() const override
Definition: MemRegion.h:837
InvalidationKinds
Describes different invalidation traits.
Definition: MemRegion.h:1401
const MemRegion * getRegion() const
Definition: MemRegion.h:1063
bool isBoundable() const override
Definition: MemRegion.h:192
QualType getLocationType() const override
Definition: MemRegion.h:632
static bool classof(const MemRegion *R)
Definition: MemRegion.h:600
static bool classof(const MemRegion *R)
Definition: MemRegion.h:334
const Expr * getExpr() const
Definition: MemRegion.h:1129
static bool classof(const MemRegion *R)
Definition: MemRegion.h:348
static bool classof(const OMPClause *T)
bool isBoundable() const override
Definition: MemRegion.h:804
T castAs() const
Convert to the specified SVal type, asserting that this SVal is of the desired type.
Definition: SVals.h:92
SubRegion - A region that subsets another larger region.
Definition: MemRegion.h:420
The region containing globals which are defined in system/external headers and are considered modifia...
Definition: MemRegion.h:286
StackSpaceRegion(MemRegionManager *mgr, Kind k, const StackFrameContext *sfc)
Definition: MemRegion.h:373
int64_t getOffset() const
Definition: MemRegion.h:66
const Type * getTypePtrOrNull() const
Definition: Type.h:5728
const CodeTextRegion * getCodeRegion() const
Definition: MemRegion.h:253
const BlockDecl * getDecl() const
Definition: MemRegion.h:684
MemSpaceRegion(MemRegionManager *mgr, Kind k)
Definition: MemRegion.h:184
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.h:843
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
const Expr * getExpr() const
Definition: MemRegion.h:472
Represents a C++ struct/union/class.
Definition: DeclCXX.h:299
bool isVoidType() const
Definition: Type.h:6175
static bool classof(const MemRegion *R)
Definition: MemRegion.h:213
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition: MemRegion.h:806
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1964
QualType getValueType() const override
Definition: MemRegion.h:1093
static bool classof(const MemRegion *R)
Definition: MemRegion.h:947
static bool classof(const MemRegion *R)
Definition: MemRegion.h:505
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
DeclRegion(const Decl *d, const MemRegion *sReg, Kind k)
Definition: MemRegion.h:895
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:61
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1509
QualType getDesugaredLocationType(ASTContext &Context) const
Definition: MemRegion.h:499
StringRegion - Region associated with a StringLiteral.
Definition: MemRegion.h:780
const FieldRegion * getFieldRegionWithSuper(const FieldRegion *FR, const SubRegion *superRegion)
Definition: MemRegion.h:1302
ElementRegin is used to represent both array elements and casts.
Definition: MemRegion.h:1070
QualType getValueType() const override
Definition: MemRegion.h:1005
MemRegionManager(ASTContext &c, llvm::BumpPtrAllocator &a)
Definition: MemRegion.h:1213
const llvm::APSInt & getValue() const
Definition: SVals.h:357
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
Definition: Decl.h:248
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
static bool classof(const MemRegion *R)
Definition: MemRegion.h:296
const MemRegion * superRegion
Definition: MemRegion.h:424
static bool classof(const MemRegion *R)
Definition: MemRegion.h:412
bool isBoundable() const override
Definition: MemRegion.h:555
MemRegionManager * Mgr
Definition: MemRegion.h:182
bool hasSymbolicOffset() const
Definition: MemRegion.h:64
NonStaticGlobalSpaceRegion(MemRegionManager *mgr, Kind k)
Definition: MemRegion.h:270
TypedRegion - An abstract class representing regions that are typed.
Definition: MemRegion.h:488
static bool classof(const MemRegion *R)
Definition: MemRegion.h:196