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