clang  6.0.0svn
SymExpr.h
Go to the documentation of this file.
1 //== SymExpr.h - Management of Symbolic Values ------------------*- 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 SymExpr and SymbolData.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMEXPR_H
15 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMEXPR_H
16 
17 #include "clang/AST/Type.h"
18 #include "llvm/ADT/FoldingSet.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/Support/raw_ostream.h"
21 
22 namespace clang {
23 namespace ento {
24 
25 class MemRegion;
26 
27 /// \brief Symbolic value. These values used to capture symbolic execution of
28 /// the program.
29 class SymExpr : public llvm::FoldingSetNode {
30  virtual void anchor();
31 
32 public:
33  enum Kind {
34 #define SYMBOL(Id, Parent) Id##Kind,
35 #define SYMBOL_RANGE(Id, First, Last) BEGIN_##Id = First, END_##Id = Last,
36 #include "clang/StaticAnalyzer/Core/PathSensitive/Symbols.def"
37  };
38 
39 private:
40  Kind K;
41 
42 protected:
43  SymExpr(Kind k) : K(k) {}
44 
46  // FIXME: Depending on whether we choose to deprecate structural symbols,
47  // this may become much stricter.
48  return !T.isNull() && !T->isVoidType();
49  }
50 
51 public:
52  virtual ~SymExpr() {}
53 
54  Kind getKind() const { return K; }
55 
56  virtual void dump() const;
57 
58  virtual void dumpToStream(raw_ostream &os) const {}
59 
60  virtual QualType getType() const = 0;
61  virtual void Profile(llvm::FoldingSetNodeID &profile) = 0;
62 
63  /// \brief Iterator over symbols that the current symbol depends on.
64  ///
65  /// For SymbolData, it's the symbol itself; for expressions, it's the
66  /// expression symbol and all the operands in it. Note, SymbolDerived is
67  /// treated as SymbolData - the iterator will NOT visit the parent region.
70  void expand();
71 
72  public:
74  symbol_iterator(const SymExpr *SE);
75 
77  const SymExpr *operator*();
78 
79  bool operator==(const symbol_iterator &X) const;
80  bool operator!=(const symbol_iterator &X) const;
81  };
82 
83  symbol_iterator symbol_begin() const { return symbol_iterator(this); }
85 
86  unsigned computeComplexity() const;
87 
88  /// \brief Find the region from which this symbol originates.
89  ///
90  /// Whenever the symbol was constructed to denote an unknown value of
91  /// a certain memory region, return this region. This method
92  /// allows checkers to make decisions depending on the origin of the symbol.
93  /// Symbol classes for which the origin region is known include
94  /// SymbolRegionValue which denotes the value of the region before
95  /// the beginning of the analysis, and SymbolDerived which denotes the value
96  /// of a certain memory region after its super region (a memory space or
97  /// a larger record region) is default-bound with a certain symbol.
98  virtual const MemRegion *getOriginRegion() const { return nullptr; }
99 };
100 
101 inline raw_ostream &operator<<(raw_ostream &os,
102  const clang::ento::SymExpr *SE) {
103  SE->dumpToStream(os);
104  return os;
105 }
106 
107 typedef const SymExpr *SymbolRef;
109 
110 typedef unsigned SymbolID;
111 /// \brief A symbol representing data which can be stored in a memory location
112 /// (region).
113 class SymbolData : public SymExpr {
114  void anchor() override;
115  const SymbolID Sym;
116 
117 protected:
118  SymbolData(Kind k, SymbolID sym) : SymExpr(k), Sym(sym) {
119  assert(classof(this));
120  }
121 
122 public:
123  ~SymbolData() override {}
124 
125  SymbolID getSymbolID() const { return Sym; }
126 
127  // Implement isa<T> support.
128  static inline bool classof(const SymExpr *SE) {
129  Kind k = SE->getKind();
130  return k >= BEGIN_SYMBOLS && k <= END_SYMBOLS;
131  }
132 };
133 
134 } // namespace ento
135 } // namespace clang
136 
137 #endif
SmallVector< SymbolRef, 2 > SymbolRefSmallVectorTy
Definition: SymExpr.h:108
A (possibly-)qualified type.
Definition: Type.h:653
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:79
~SymbolData() override
Definition: SymExpr.h:123
const SymExpr * SymbolRef
C Language Family Type Representation.
unsigned SymbolID
Definition: SymExpr.h:110
bool operator!=(const symbol_iterator &X) const
virtual ~SymExpr()
Definition: SymExpr.h:52
virtual void dump() const
virtual const MemRegion * getOriginRegion() const
Find the region from which this symbol originates.
Definition: SymExpr.h:98
Symbolic value.
Definition: SymExpr.h:29
symbol_iterator symbol_begin() const
Definition: SymExpr.h:83
virtual void dumpToStream(raw_ostream &os) const
Definition: SymExpr.h:58
virtual QualType getType() const =0
SymbolID getSymbolID() const
Definition: SymExpr.h:125
const FunctionProtoType * T
static bool classof(const SymExpr *SE)
Definition: SymExpr.h:128
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:719
Kind
virtual void Profile(llvm::FoldingSetNodeID &profile)=0
static bool isValidTypeForSymbol(QualType T)
Definition: SymExpr.h:45
Dataflow Directional Tag Classes.
raw_ostream & operator<<(raw_ostream &Out, const CheckerBase &Checker)
Dump checker name to stream.
Definition: Checker.cpp:34
static symbol_iterator symbol_end()
Definition: SymExpr.h:84
SymbolData(Kind k, SymbolID sym)
Definition: SymExpr.h:118
unsigned computeComplexity() const
static bool classof(const OMPClause *T)
Kind getKind() const
Definition: SymExpr.h:54
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
Definition: SemaDecl.cpp:13010
bool isVoidType() const
Definition: Type.h:6171
bool operator==(const symbol_iterator &X) const
A symbol representing data which can be stored in a memory location (region).
Definition: SymExpr.h:113
Iterator over symbols that the current symbol depends on.
Definition: SymExpr.h:68