Coverage Report

Created: 2018-09-23 03:40

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Analysis/ProgramPoint.h
Line
Count
Source (jump to first uncovered line)
1
//==- ProgramPoint.h - Program Points for Path-Sensitive 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 the interface ProgramPoint, which identifies a
11
//  distinct location in a function.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CLANG_ANALYSIS_PROGRAMPOINT_H
16
#define LLVM_CLANG_ANALYSIS_PROGRAMPOINT_H
17
18
#include "clang/Analysis/AnalysisDeclContext.h"
19
#include "clang/Analysis/CFG.h"
20
#include "llvm/ADT/DenseMap.h"
21
#include "llvm/ADT/FoldingSet.h"
22
#include "llvm/ADT/Optional.h"
23
#include "llvm/ADT/PointerIntPair.h"
24
#include "llvm/ADT/StringRef.h"
25
#include "llvm/Support/Casting.h"
26
#include "llvm/Support/DataTypes.h"
27
#include <cassert>
28
#include <string>
29
#include <utility>
30
31
namespace clang {
32
33
class AnalysisDeclContext;
34
class FunctionDecl;
35
class LocationContext;
36
37
/// ProgramPoints can be "tagged" as representing points specific to a given
38
/// analysis entity.  Tags are abstract annotations, with an associated
39
/// description and potentially other information.
40
class ProgramPointTag {
41
public:
42
14.8k
  ProgramPointTag(void *tagKind = nullptr) : TagKind(tagKind) {}
43
  virtual ~ProgramPointTag();
44
  virtual StringRef getTagDescription() const = 0;
45
46
protected:
47
  /// Used to implement 'isKind' in subclasses.
48
0
  const void *getTagKind() { return TagKind; }
49
50
private:
51
  const void *TagKind;
52
};
53
54
class SimpleProgramPointTag : public ProgramPointTag {
55
  std::string Desc;
56
public:
57
  SimpleProgramPointTag(StringRef MsgProvider, StringRef Msg);
58
  StringRef getTagDescription() const override;
59
};
60
61
0
class ProgramPoint {
62
public:
63
  enum Kind { BlockEdgeKind,
64
              BlockEntranceKind,
65
              BlockExitKind,
66
              PreStmtKind,
67
              PreStmtPurgeDeadSymbolsKind,
68
              PostStmtPurgeDeadSymbolsKind,
69
              PostStmtKind,
70
              PreLoadKind,
71
              PostLoadKind,
72
              PreStoreKind,
73
              PostStoreKind,
74
              PostConditionKind,
75
              PostLValueKind,
76
              PostAllocatorCallKind,
77
              MinPostStmtKind = PostStmtKind,
78
              MaxPostStmtKind = PostAllocatorCallKind,
79
              PostInitializerKind,
80
              CallEnterKind,
81
              CallExitBeginKind,
82
              CallExitEndKind,
83
              FunctionExitKind,
84
              PreImplicitCallKind,
85
              PostImplicitCallKind,
86
              MinImplicitCallKind = PreImplicitCallKind,
87
              MaxImplicitCallKind = PostImplicitCallKind,
88
              LoopExitKind,
89
              EpsilonKind};
90
91
private:
92
  const void *Data1;
93
  llvm::PointerIntPair<const void *, 2, unsigned> Data2;
94
95
  // The LocationContext could be NULL to allow ProgramPoint to be used in
96
  // context insensitive analysis.
97
  llvm::PointerIntPair<const LocationContext *, 2, unsigned> L;
98
99
  llvm::PointerIntPair<const ProgramPointTag *, 2, unsigned> Tag;
100
101
protected:
102
3.72M
  ProgramPoint() = default;
103
  ProgramPoint(const void *P,
104
               Kind k,
105
               const LocationContext *l,
106
               const ProgramPointTag *tag = nullptr)
107
    : Data1(P),
108
      Data2(nullptr, (((unsigned) k) >> 0) & 0x3),
109
      L(l, (((unsigned) k) >> 2) & 0x3),
110
234k
      Tag(tag, (((unsigned) k) >> 4) & 0x3) {
111
234k
        assert(getKind() == k);
112
234k
        assert(getLocationContext() == l);
113
234k
        assert(getData1() == P);
114
234k
      }
115
116
  ProgramPoint(const void *P1,
117
               const void *P2,
118
               Kind k,
119
               const LocationContext *l,
120
               const ProgramPointTag *tag = nullptr)
121
    : Data1(P1),
122
      Data2(P2, (((unsigned) k) >> 0) & 0x3),
123
      L(l, (((unsigned) k) >> 2) & 0x3),
124
4.93M
      Tag(tag, (((unsigned) k) >> 4) & 0x3) {}
125
126
protected:
127
6.96M
  const void *getData1() const { return Data1; }
128
4.51M
  const void *getData2() const { return Data2.getPointer(); }
129
60.8k
  void setData2(const void *d) { Data2.setPointer(d); }
130
131
public:
132
  /// Create a new ProgramPoint object that is the same as the original
133
  /// except for using the specified tag value.
134
889k
  ProgramPoint withTag(const ProgramPointTag *tag) const {
135
889k
    return ProgramPoint(getData1(), getData2(), getKind(),
136
889k
                        getLocationContext(), tag);
137
889k
  }
138
139
  /// Convert to the specified ProgramPoint type, asserting that this
140
  /// ProgramPoint is of the desired type.
141
  template<typename T>
142
954k
  T castAs() const {
143
954k
    assert(T::isKind(*this));
144
954k
    T t;
145
954k
    ProgramPoint& PP = t;
146
954k
    PP = *this;
147
954k
    return t;
148
954k
  }
clang::StmtPoint clang::ProgramPoint::castAs<clang::StmtPoint>() const
Line
Count
Source
142
954
  T castAs() const {
143
954
    assert(T::isKind(*this));
144
954
    T t;
145
954
    ProgramPoint& PP = t;
146
954
    PP = *this;
147
954
    return t;
148
954
  }
clang::BlockEdge clang::ProgramPoint::castAs<clang::BlockEdge>() const
Line
Count
Source
142
161k
  T castAs() const {
143
161k
    assert(T::isKind(*this));
144
161k
    T t;
145
161k
    ProgramPoint& PP = t;
146
161k
    PP = *this;
147
161k
    return t;
148
161k
  }
clang::BlockEntrance clang::ProgramPoint::castAs<clang::BlockEntrance>() const
Line
Count
Source
142
100k
  T castAs() const {
143
100k
    assert(T::isKind(*this));
144
100k
    T t;
145
100k
    ProgramPoint& PP = t;
146
100k
    PP = *this;
147
100k
    return t;
148
100k
  }
clang::CallEnter clang::ProgramPoint::castAs<clang::CallEnter>() const
Line
Count
Source
142
19.2k
  T castAs() const {
143
19.2k
    assert(T::isKind(*this));
144
19.2k
    T t;
145
19.2k
    ProgramPoint& PP = t;
146
19.2k
    PP = *this;
147
19.2k
    return t;
148
19.2k
  }
clang::PostStmt clang::ProgramPoint::castAs<clang::PostStmt>() const
Line
Count
Source
142
671k
  T castAs() const {
143
671k
    assert(T::isKind(*this));
144
671k
    T t;
145
671k
    ProgramPoint& PP = t;
146
671k
    PP = *this;
147
671k
    return t;
148
671k
  }
clang::CallExitEnd clang::ProgramPoint::castAs<clang::CallExitEnd>() const
Line
Count
Source
142
19
  T castAs() const {
143
19
    assert(T::isKind(*this));
144
19
    T t;
145
19
    ProgramPoint& PP = t;
146
19
    PP = *this;
147
19
    return t;
148
19
  }
149
150
  /// Convert to the specified ProgramPoint type, returning None if this
151
  /// ProgramPoint is not of the desired type.
152
  template<typename T>
153
14.4M
  Optional<T> getAs() const {
154
14.4M
    if (!T::isKind(*this))
155
11.6M
      return None;
156
2.76M
    T t;
157
2.76M
    ProgramPoint& PP = t;
158
2.76M
    PP = *this;
159
2.76M
    return t;
160
2.76M
  }
llvm::Optional<clang::BlockEntrance> clang::ProgramPoint::getAs<clang::BlockEntrance>() const
Line
Count
Source
153
1.92M
  Optional<T> getAs() const {
154
1.92M
    if (!T::isKind(*this))
155
1.71M
      return None;
156
203k
    T t;
157
203k
    ProgramPoint& PP = t;
158
203k
    PP = *this;
159
203k
    return t;
160
203k
  }
llvm::Optional<clang::PostStore> clang::ProgramPoint::getAs<clang::PostStore>() const
Line
Count
Source
153
803k
  Optional<T> getAs() const {
154
803k
    if (!T::isKind(*this))
155
763k
      return None;
156
39.8k
    T t;
157
39.8k
    ProgramPoint& PP = t;
158
39.8k
    PP = *this;
159
39.8k
    return t;
160
39.8k
  }
llvm::Optional<clang::BlockEdge> clang::ProgramPoint::getAs<clang::BlockEdge>() const
Line
Count
Source
153
1.11M
  Optional<T> getAs() const {
154
1.11M
    if (!T::isKind(*this))
155
975k
      return None;
156
137k
    T t;
157
137k
    ProgramPoint& PP = t;
158
137k
    PP = *this;
159
137k
    return t;
160
137k
  }
llvm::Optional<clang::StmtPoint> clang::ProgramPoint::getAs<clang::StmtPoint>() const
Line
Count
Source
153
1.49M
  Optional<T> getAs() const {
154
1.49M
    if (!T::isKind(*this))
155
203k
      return None;
156
1.29M
    T t;
157
1.29M
    ProgramPoint& PP = t;
158
1.29M
    PP = *this;
159
1.29M
    return t;
160
1.29M
  }
llvm::Optional<clang::PostImplicitCall> clang::ProgramPoint::getAs<clang::PostImplicitCall>() const
Line
Count
Source
153
754k
  Optional<T> getAs() const {
154
754k
    if (!T::isKind(*this))
155
753k
      return None;
156
690
    T t;
157
690
    ProgramPoint& PP = t;
158
690
    PP = *this;
159
690
    return t;
160
690
  }
llvm::Optional<clang::CallEnter> clang::ProgramPoint::getAs<clang::CallEnter>() const
Line
Count
Source
153
2.22M
  Optional<T> getAs() const {
154
2.22M
    if (!T::isKind(*this))
155
2.19M
      return None;
156
22.5k
    T t;
157
22.5k
    ProgramPoint& PP = t;
158
22.5k
    PP = *this;
159
22.5k
    return t;
160
22.5k
  }
llvm::Optional<clang::PostStmt> clang::ProgramPoint::getAs<clang::PostStmt>() const
Line
Count
Source
153
1.12M
  Optional<T> getAs() const {
154
1.12M
    if (!T::isKind(*this))
155
242k
      return None;
156
882k
    T t;
157
882k
    ProgramPoint& PP = t;
158
882k
    PP = *this;
159
882k
    return t;
160
882k
  }
llvm::Optional<clang::CallExitEnd> clang::ProgramPoint::getAs<clang::CallExitEnd>() const
Line
Count
Source
153
251k
  Optional<T> getAs() const {
154
251k
    if (!T::isKind(*this))
155
231k
      return None;
156
20.1k
    T t;
157
20.1k
    ProgramPoint& PP = t;
158
20.1k
    PP = *this;
159
20.1k
    return t;
160
20.1k
  }
llvm::Optional<clang::PreStmt> clang::ProgramPoint::getAs<clang::PreStmt>() const
Line
Count
Source
153
838k
  Optional<T> getAs() const {
154
838k
    if (!T::isKind(*this))
155
823k
      return None;
156
15.3k
    T t;
157
15.3k
    ProgramPoint& PP = t;
158
15.3k
    PP = *this;
159
15.3k
    return t;
160
15.3k
  }
llvm::Optional<clang::PostInitializer> clang::ProgramPoint::getAs<clang::PostInitializer>() const
Line
Count
Source
153
863k
  Optional<T> getAs() const {
154
863k
    if (!T::isKind(*this))
155
852k
      return None;
156
11.0k
    T t;
157
11.0k
    ProgramPoint& PP = t;
158
11.0k
    PP = *this;
159
11.0k
    return t;
160
11.0k
  }
llvm::Optional<clang::CallExitBegin> clang::ProgramPoint::getAs<clang::CallExitBegin>() const
Line
Count
Source
153
113k
  Optional<T> getAs() const {
154
113k
    if (!T::isKind(*this))
155
98.1k
      return None;
156
15.6k
    T t;
157
15.6k
    ProgramPoint& PP = t;
158
15.6k
    PP = *this;
159
15.6k
    return t;
160
15.6k
  }
llvm::Optional<clang::LoopExit> clang::ProgramPoint::getAs<clang::LoopExit>() const
Line
Count
Source
153
753k
  Optional<T> getAs() const {
154
753k
    if (!T::isKind(*this))
155
753k
      return None;
156
264
    T t;
157
264
    ProgramPoint& PP = t;
158
264
    PP = *this;
159
264
    return t;
160
264
  }
llvm::Optional<clang::EpsilonPoint> clang::ProgramPoint::getAs<clang::EpsilonPoint>() const
Line
Count
Source
153
753k
  Optional<T> getAs() const {
154
753k
    if (!T::isKind(*this))
155
753k
      return None;
156
27
    T t;
157
27
    ProgramPoint& PP = t;
158
27
    PP = *this;
159
27
    return t;
160
27
  }
llvm::Optional<clang::PreStmtPurgeDeadSymbols> clang::ProgramPoint::getAs<clang::PreStmtPurgeDeadSymbols>() const
Line
Count
Source
153
1.05M
  Optional<T> getAs() const {
154
1.05M
    if (!T::isKind(*this))
155
931k
      return None;
156
120k
    T t;
157
120k
    ProgramPoint& PP = t;
158
120k
    PP = *this;
159
120k
    return t;
160
120k
  }
llvm::Optional<clang::PreImplicitCall> clang::ProgramPoint::getAs<clang::PreImplicitCall>() const
Line
Count
Source
153
337k
  Optional<T> getAs() const {
154
337k
    if (!T::isKind(*this))
155
337k
      return None;
156
48
    T t;
157
48
    ProgramPoint& PP = t;
158
48
    PP = *this;
159
48
    return t;
160
48
  }
llvm::Optional<clang::PostStmtPurgeDeadSymbols> clang::ProgramPoint::getAs<clang::PostStmtPurgeDeadSymbols>() const
Line
Count
Source
153
26.1k
  Optional<T> getAs() const {
154
26.1k
    if (!T::isKind(*this))
155
25.5k
      return None;
156
549
    T t;
157
549
    ProgramPoint& PP = t;
158
549
    PP = *this;
159
549
    return t;
160
549
  }
llvm::Optional<clang::FunctionExitPoint> clang::ProgramPoint::getAs<clang::FunctionExitPoint>() const
Line
Count
Source
153
38.7k
  Optional<T> getAs() const {
154
38.7k
    if (!T::isKind(*this))
155
37.1k
      return None;
156
1.64k
    T t;
157
1.64k
    ProgramPoint& PP = t;
158
1.64k
    PP = *this;
159
1.64k
    return t;
160
1.64k
  }
161
162
19.8M
  Kind getKind() const {
163
19.8M
    unsigned x = Tag.getInt();
164
19.8M
    x <<= 2;
165
19.8M
    x |= L.getInt();
166
19.8M
    x <<= 2;
167
19.8M
    x |= Data2.getInt();
168
19.8M
    return (Kind) x;
169
19.8M
  }
170
171
  /// Is this a program point corresponding to purge/removal of dead
172
  /// symbols and bindings.
173
92
  bool isPurgeKind() {
174
92
    Kind K = getKind();
175
92
    return (K == PostStmtPurgeDeadSymbolsKind ||
176
92
            K == PreStmtPurgeDeadSymbolsKind);
177
92
  }
178
179
4.27M
  const ProgramPointTag *getTag() const { return Tag.getPointer(); }
180
181
17.4M
  const LocationContext *getLocationContext() const {
182
17.4M
    return L.getPointer();
183
17.4M
  }
184
185
345k
  const StackFrameContext *getStackFrame() const {
186
345k
    return getLocationContext()->getStackFrame();
187
345k
  }
188
189
  // For use with DenseMap.  This hash is probably slow.
190
  unsigned getHashValue() const {
191
    llvm::FoldingSetNodeID ID;
192
    Profile(ID);
193
    return ID.ComputeHash();
194
  }
195
196
752k
  bool operator==(const ProgramPoint & RHS) const {
197
752k
    return Data1 == RHS.Data1 &&
198
752k
           
Data2 == RHS.Data2699k
&&
199
752k
           
L == RHS.L290k
&&
200
752k
           
Tag == RHS.Tag290k
;
201
752k
  }
202
203
  bool operator!=(const ProgramPoint &RHS) const {
204
    return Data1 != RHS.Data1 ||
205
           Data2 != RHS.Data2 ||
206
           L != RHS.L ||
207
           Tag != RHS.Tag;
208
  }
209
210
3.36M
  void Profile(llvm::FoldingSetNodeID& ID) const {
211
3.36M
    ID.AddInteger((unsigned) getKind());
212
3.36M
    ID.AddPointer(getData1());
213
3.36M
    ID.AddPointer(getData2());
214
3.36M
    ID.AddPointer(getLocationContext());
215
3.36M
    ID.AddPointer(getTag());
216
3.36M
  }
217
218
  static ProgramPoint getProgramPoint(const Stmt *S, ProgramPoint::Kind K,
219
                                      const LocationContext *LC,
220
                                      const ProgramPointTag *tag);
221
};
222
223
class BlockEntrance : public ProgramPoint {
224
public:
225
  BlockEntrance(const CFGBlock *B, const LocationContext *L,
226
                const ProgramPointTag *tag = nullptr)
227
114k
    : ProgramPoint(B, BlockEntranceKind, L, tag) {
228
114k
    assert(B && "BlockEntrance requires non-null block");
229
114k
  }
230
231
416k
  const CFGBlock *getBlock() const {
232
416k
    return reinterpret_cast<const CFGBlock*>(getData1());
233
416k
  }
234
235
100k
  Optional<CFGElement> getFirstElement() const {
236
100k
    const CFGBlock *B = getBlock();
237
100k
    return B->empty() ? 
Optional<CFGElement>()12.7k
:
B->front()87.5k
;
238
100k
  }
239
240
private:
241
  friend class ProgramPoint;
242
304k
  BlockEntrance() = default;
243
1.92M
  static bool isKind(const ProgramPoint &Location) {
244
1.92M
    return Location.getKind() == BlockEntranceKind;
245
1.92M
  }
246
};
247
248
class BlockExit : public ProgramPoint {
249
public:
250
  BlockExit(const CFGBlock *B, const LocationContext *L)
251
    : ProgramPoint(B, BlockExitKind, L) {}
252
253
  const CFGBlock *getBlock() const {
254
    return reinterpret_cast<const CFGBlock*>(getData1());
255
  }
256
257
  const Stmt *getTerminator() const {
258
    return getBlock()->getTerminator();
259
  }
260
261
private:
262
  friend class ProgramPoint;
263
  BlockExit() = default;
264
  static bool isKind(const ProgramPoint &Location) {
265
    return Location.getKind() == BlockExitKind;
266
  }
267
};
268
269
class StmtPoint : public ProgramPoint {
270
public:
271
  StmtPoint(const Stmt *S, const void *p2, Kind k, const LocationContext *L,
272
            const ProgramPointTag *tag)
273
3.84M
    : ProgramPoint(S, p2, k, L, tag) {
274
3.84M
    assert(S);
275
3.84M
  }
276
277
2.05M
  const Stmt *getStmt() const { return (const Stmt*) getData1(); }
278
279
  template <typename T>
280
44.7k
  const T* getStmtAs() const { return dyn_cast<T>(getStmt()); }
clang::ObjCMessageExpr const* clang::StmtPoint::getStmtAs<clang::ObjCMessageExpr>() const
Line
Count
Source
280
10
  const T* getStmtAs() const { return dyn_cast<T>(getStmt()); }
clang::BinaryOperator const* clang::StmtPoint::getStmtAs<clang::BinaryOperator>() const
Line
Count
Source
280
12.3k
  const T* getStmtAs() const { return dyn_cast<T>(getStmt()); }
clang::Expr const* clang::StmtPoint::getStmtAs<clang::Expr>() const
Line
Count
Source
280
17.7k
  const T* getStmtAs() const { return dyn_cast<T>(getStmt()); }
clang::DeclStmt const* clang::StmtPoint::getStmtAs<clang::DeclStmt>() const
Line
Count
Source
280
14.7k
  const T* getStmtAs() const { return dyn_cast<T>(getStmt()); }
281
282
protected:
283
3.02M
  StmtPoint() = default;
284
private:
285
  friend class ProgramPoint;
286
1.49M
  static bool isKind(const ProgramPoint &Location) {
287
1.49M
    unsigned k = Location.getKind();
288
1.49M
    return k >= PreStmtKind && 
k <= MaxPostStmtKind1.36M
;
289
1.49M
  }
290
};
291
292
293
class PreStmt : public StmtPoint {
294
public:
295
  PreStmt(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag,
296
          const Stmt *SubStmt = nullptr)
297
678k
    : StmtPoint(S, SubStmt, PreStmtKind, L, tag) {}
298
299
0
  const Stmt *getSubStmt() const { return (const Stmt*) getData2(); }
300
301
private:
302
  friend class ProgramPoint;
303
15.3k
  PreStmt() = default;
304
838k
  static bool isKind(const ProgramPoint &Location) {
305
838k
    return Location.getKind() == PreStmtKind;
306
838k
  }
307
};
308
309
class PostStmt : public StmtPoint {
310
protected:
311
1.59M
  PostStmt() = default;
312
  PostStmt(const Stmt *S, const void *data, Kind k, const LocationContext *L,
313
           const ProgramPointTag *tag = nullptr)
314
    : StmtPoint(S, data, k, L, tag) {}
315
316
public:
317
  explicit PostStmt(const Stmt *S, Kind k, const LocationContext *L,
318
                    const ProgramPointTag *tag = nullptr)
319
463k
    : StmtPoint(S, nullptr, k, L, tag) {}
320
321
  explicit PostStmt(const Stmt *S, const LocationContext *L,
322
                    const ProgramPointTag *tag = nullptr)
323
1.90M
    : StmtPoint(S, nullptr, PostStmtKind, L, tag) {}
324
325
private:
326
  friend class ProgramPoint;
327
1.12M
  static bool isKind(const ProgramPoint &Location) {
328
1.12M
    unsigned k = Location.getKind();
329
1.12M
    return k >= MinPostStmtKind && 
k <= MaxPostStmtKind933k
;
330
1.12M
  }
331
};
332
333
class FunctionExitPoint : public ProgramPoint {
334
public:
335
  explicit FunctionExitPoint(const ReturnStmt *S,
336
                             const LocationContext *LC,
337
                             const ProgramPointTag *tag = nullptr)
338
66.1k
      : ProgramPoint(S, FunctionExitKind, LC, tag) {}
339
340
0
  const CFGBlock *getBlock() const {
341
0
    return &getLocationContext()->getCFG()->getExit();
342
0
  }
343
344
1.64k
  const ReturnStmt *getStmt() const {
345
1.64k
    return reinterpret_cast<const ReturnStmt *>(getData1());
346
1.64k
  }
347
348
private:
349
  friend class ProgramPoint;
350
1.64k
  FunctionExitPoint() = default;
351
38.7k
  static bool isKind(const ProgramPoint &Location) {
352
38.7k
    return Location.getKind() == FunctionExitKind;
353
38.7k
  }
354
};
355
356
// PostCondition represents the post program point of a branch condition.
357
class PostCondition : public PostStmt {
358
public:
359
  PostCondition(const Stmt *S, const LocationContext *L,
360
                const ProgramPointTag *tag = nullptr)
361
40.5k
    : PostStmt(S, PostConditionKind, L, tag) {}
362
363
private:
364
  friend class ProgramPoint;
365
  PostCondition() = default;
366
  static bool isKind(const ProgramPoint &Location) {
367
    return Location.getKind() == PostConditionKind;
368
  }
369
};
370
371
class LocationCheck : public StmtPoint {
372
protected:
373
  LocationCheck() = default;
374
  LocationCheck(const Stmt *S, const LocationContext *L,
375
                ProgramPoint::Kind K, const ProgramPointTag *tag)
376
417k
    : StmtPoint(S, nullptr, K, L, tag) {}
377
378
private:
379
  friend class ProgramPoint;
380
  static bool isKind(const ProgramPoint &location) {
381
    unsigned k = location.getKind();
382
    return k == PreLoadKind || k == PreStoreKind;
383
  }
384
};
385
386
class PreLoad : public LocationCheck {
387
public:
388
  PreLoad(const Stmt *S, const LocationContext *L,
389
          const ProgramPointTag *tag = nullptr)
390
346k
    : LocationCheck(S, L, PreLoadKind, tag) {}
391
392
private:
393
  friend class ProgramPoint;
394
  PreLoad() = default;
395
  static bool isKind(const ProgramPoint &location) {
396
    return location.getKind() == PreLoadKind;
397
  }
398
};
399
400
class PreStore : public LocationCheck {
401
public:
402
  PreStore(const Stmt *S, const LocationContext *L,
403
           const ProgramPointTag *tag = nullptr)
404
70.3k
  : LocationCheck(S, L, PreStoreKind, tag) {}
405
406
private:
407
  friend class ProgramPoint;
408
  PreStore() = default;
409
  static bool isKind(const ProgramPoint &location) {
410
    return location.getKind() == PreStoreKind;
411
  }
412
};
413
414
class PostLoad : public PostStmt {
415
public:
416
  PostLoad(const Stmt *S, const LocationContext *L,
417
           const ProgramPointTag *tag = nullptr)
418
140k
    : PostStmt(S, PostLoadKind, L, tag) {}
419
420
private:
421
  friend class ProgramPoint;
422
  PostLoad() = default;
423
  static bool isKind(const ProgramPoint &Location) {
424
    return Location.getKind() == PostLoadKind;
425
  }
426
};
427
428
/// Represents a program point after a store evaluation.
429
class PostStore : public PostStmt {
430
public:
431
  /// Construct the post store point.
432
  /// \param Loc can be used to store the information about the location
433
  /// used in the form it was uttered in the code.
434
  PostStore(const Stmt *S, const LocationContext *L, const void *Loc,
435
            const ProgramPointTag *tag = nullptr)
436
60.8k
    : PostStmt(S, PostStoreKind, L, tag) {
437
60.8k
    assert(getData2() == nullptr);
438
60.8k
    setData2(Loc);
439
60.8k
  }
440
441
  /// Returns the information about the location used in the store,
442
  /// how it was uttered in the code.
443
737
  const void *getLocationValue() const {
444
737
    return getData2();
445
737
  }
446
447
private:
448
  friend class ProgramPoint;
449
39.8k
  PostStore() = default;
450
803k
  static bool isKind(const ProgramPoint &Location) {
451
803k
    return Location.getKind() == PostStoreKind;
452
803k
  }
453
};
454
455
class PostLValue : public PostStmt {
456
public:
457
  PostLValue(const Stmt *S, const LocationContext *L,
458
             const ProgramPointTag *tag = nullptr)
459
220k
    : PostStmt(S, PostLValueKind, L, tag) {}
460
461
private:
462
  friend class ProgramPoint;
463
  PostLValue() = default;
464
  static bool isKind(const ProgramPoint &Location) {
465
    return Location.getKind() == PostLValueKind;
466
  }
467
};
468
469
/// Represents a point after we ran remove dead bindings BEFORE
470
/// processing the given statement.
471
class PreStmtPurgeDeadSymbols : public StmtPoint {
472
public:
473
  PreStmtPurgeDeadSymbols(const Stmt *S, const LocationContext *L,
474
                       const ProgramPointTag *tag = nullptr)
475
290k
    : StmtPoint(S, nullptr, PreStmtPurgeDeadSymbolsKind, L, tag) { }
476
477
private:
478
  friend class ProgramPoint;
479
120k
  PreStmtPurgeDeadSymbols() = default;
480
1.05M
  static bool isKind(const ProgramPoint &Location) {
481
1.05M
    return Location.getKind() == PreStmtPurgeDeadSymbolsKind;
482
1.05M
  }
483
};
484
485
/// Represents a point after we ran remove dead bindings AFTER
486
/// processing the  given statement.
487
class PostStmtPurgeDeadSymbols : public StmtPoint {
488
public:
489
  PostStmtPurgeDeadSymbols(const Stmt *S, const LocationContext *L,
490
                       const ProgramPointTag *tag = nullptr)
491
86.5k
    : StmtPoint(S, nullptr, PostStmtPurgeDeadSymbolsKind, L, tag) { }
492
493
private:
494
  friend class ProgramPoint;
495
549
  PostStmtPurgeDeadSymbols() = default;
496
26.1k
  static bool isKind(const ProgramPoint &Location) {
497
26.1k
    return Location.getKind() == PostStmtPurgeDeadSymbolsKind;
498
26.1k
  }
499
};
500
501
class BlockEdge : public ProgramPoint {
502
public:
503
  BlockEdge(const CFGBlock *B1, const CFGBlock *B2, const LocationContext *L)
504
160k
    : ProgramPoint(B1, B2, BlockEdgeKind, L) {
505
160k
    assert(B1 && "BlockEdge: source block must be non-null");
506
160k
    assert(B2 && "BlockEdge: destination block must be non-null");
507
160k
  }
508
509
190k
  const CFGBlock *getSrc() const {
510
190k
    return static_cast<const CFGBlock*>(getData1());
511
190k
  }
512
513
179k
  const CFGBlock *getDst() const {
514
179k
    return static_cast<const CFGBlock*>(getData2());
515
179k
  }
516
517
private:
518
  friend class ProgramPoint;
519
298k
  BlockEdge() = default;
520
1.11M
  static bool isKind(const ProgramPoint &Location) {
521
1.11M
    return Location.getKind() == BlockEdgeKind;
522
1.11M
  }
523
};
524
525
class PostInitializer : public ProgramPoint {
526
public:
527
  /// Construct a PostInitializer point that represents a location after
528
  ///   CXXCtorInitializer expression evaluation.
529
  ///
530
  /// \param I The initializer.
531
  /// \param Loc The location of the field being initialized.
532
  PostInitializer(const CXXCtorInitializer *I,
533
                  const void *Loc,
534
                  const LocationContext *L)
535
7.76k
    : ProgramPoint(I, Loc, PostInitializerKind, L) {}
536
537
6.27k
  const CXXCtorInitializer *getInitializer() const {
538
6.27k
    return static_cast<const CXXCtorInitializer *>(getData1());
539
6.27k
  }
540
541
  /// Returns the location of the field.
542
72
  const void *getLocationValue() const {
543
72
    return getData2();
544
72
  }
545
546
private:
547
  friend class ProgramPoint;
548
11.0k
  PostInitializer() = default;
549
863k
  static bool isKind(const ProgramPoint &Location) {
550
863k
    return Location.getKind() == PostInitializerKind;
551
863k
  }
552
};
553
554
/// Represents an implicit call event.
555
///
556
/// The nearest statement is provided for diagnostic purposes.
557
class ImplicitCallPoint : public ProgramPoint {
558
public:
559
  ImplicitCallPoint(const Decl *D, SourceLocation Loc, Kind K,
560
                    const LocationContext *L, const ProgramPointTag *Tag)
561
9.09k
    : ProgramPoint(Loc.getPtrEncoding(), D, K, L, Tag) {}
562
563
0
  const Decl *getDecl() const { return static_cast<const Decl *>(getData2()); }
564
60
  SourceLocation getLocation() const {
565
60
    return SourceLocation::getFromPtrEncoding(getData1());
566
60
  }
567
568
protected:
569
738
  ImplicitCallPoint() = default;
570
private:
571
  friend class ProgramPoint;
572
0
  static bool isKind(const ProgramPoint &Location) {
573
0
    return Location.getKind() >= MinImplicitCallKind &&
574
0
           Location.getKind() <= MaxImplicitCallKind;
575
0
  }
576
};
577
578
/// Represents a program point just before an implicit call event.
579
///
580
/// Explicit calls will appear as PreStmt program points.
581
class PreImplicitCall : public ImplicitCallPoint {
582
public:
583
  PreImplicitCall(const Decl *D, SourceLocation Loc, const LocationContext *L,
584
                  const ProgramPointTag *Tag = nullptr)
585
5.56k
    : ImplicitCallPoint(D, Loc, PreImplicitCallKind, L, Tag) {}
586
587
private:
588
  friend class ProgramPoint;
589
48
  PreImplicitCall() = default;
590
337k
  static bool isKind(const ProgramPoint &Location) {
591
337k
    return Location.getKind() == PreImplicitCallKind;
592
337k
  }
593
};
594
595
/// Represents a program point just after an implicit call event.
596
///
597
/// Explicit calls will appear as PostStmt program points.
598
class PostImplicitCall : public ImplicitCallPoint {
599
public:
600
  PostImplicitCall(const Decl *D, SourceLocation Loc, const LocationContext *L,
601
                   const ProgramPointTag *Tag = nullptr)
602
3.52k
    : ImplicitCallPoint(D, Loc, PostImplicitCallKind, L, Tag) {}
603
604
private:
605
  friend class ProgramPoint;
606
690
  PostImplicitCall() = default;
607
754k
  static bool isKind(const ProgramPoint &Location) {
608
754k
    return Location.getKind() == PostImplicitCallKind;
609
754k
  }
610
};
611
612
class PostAllocatorCall : public StmtPoint {
613
public:
614
  PostAllocatorCall(const Stmt *S, const LocationContext *L,
615
                    const ProgramPointTag *Tag = nullptr)
616
583
      : StmtPoint(S, nullptr, PostAllocatorCallKind, L, Tag) {}
617
618
private:
619
  friend class ProgramPoint;
620
  PostAllocatorCall() = default;
621
  static bool isKind(const ProgramPoint &Location) {
622
    return Location.getKind() == PostAllocatorCallKind;
623
  }
624
};
625
626
/// Represents a point when we begin processing an inlined call.
627
/// CallEnter uses the caller's location context.
628
class CallEnter : public ProgramPoint {
629
public:
630
  CallEnter(const Stmt *stmt, const StackFrameContext *calleeCtx,
631
            const LocationContext *callerCtx)
632
19.2k
    : ProgramPoint(stmt, calleeCtx, CallEnterKind, callerCtx, nullptr) {}
633
634
422
  const Stmt *getCallExpr() const {
635
422
    return static_cast<const Stmt *>(getData1());
636
422
  }
637
638
79.8k
  const StackFrameContext *getCalleeContext() const {
639
79.8k
    return static_cast<const StackFrameContext *>(getData2());
640
79.8k
  }
641
642
  /// Returns the entry block in the CFG for the entered function.
643
38.5k
  const CFGBlock *getEntry() const {
644
38.5k
    const StackFrameContext *CalleeCtx = getCalleeContext();
645
38.5k
    const CFG *CalleeCFG = CalleeCtx->getCFG();
646
38.5k
    return &(CalleeCFG->getEntry());
647
38.5k
  }
648
649
private:
650
  friend class ProgramPoint;
651
41.7k
  CallEnter() = default;
652
2.22M
  static bool isKind(const ProgramPoint &Location) {
653
2.22M
    return Location.getKind() == CallEnterKind;
654
2.22M
  }
655
};
656
657
/// Represents a point when we start the call exit sequence (for inlined call).
658
///
659
/// The call exit is simulated with a sequence of nodes, which occur between
660
/// CallExitBegin and CallExitEnd. The following operations occur between the
661
/// two program points:
662
/// - CallExitBegin
663
/// - Bind the return value
664
/// - Run Remove dead bindings (to clean up the dead symbols from the callee).
665
/// - CallExitEnd
666
class CallExitBegin : public ProgramPoint {
667
public:
668
  // CallExitBegin uses the callee's location context.
669
  CallExitBegin(const StackFrameContext *L, const ReturnStmt *RS)
670
27.5k
    : ProgramPoint(RS, CallExitBeginKind, L, nullptr) { }
671
672
14.4k
  const ReturnStmt *getReturnStmt() const {
673
14.4k
    return static_cast<const ReturnStmt *>(getData1());
674
14.4k
  }
675
676
private:
677
  friend class ProgramPoint;
678
15.6k
  CallExitBegin() = default;
679
113k
  static bool isKind(const ProgramPoint &Location) {
680
113k
    return Location.getKind() == CallExitBeginKind;
681
113k
  }
682
};
683
684
/// Represents a point when we finish the call exit sequence (for inlined call).
685
/// \sa CallExitBegin
686
class CallExitEnd : public ProgramPoint {
687
public:
688
  // CallExitEnd uses the caller's location context.
689
  CallExitEnd(const StackFrameContext *CalleeCtx,
690
              const LocationContext *CallerCtx)
691
25.8k
    : ProgramPoint(CalleeCtx, CallExitEndKind, CallerCtx, nullptr) {}
692
693
23.2k
  const StackFrameContext *getCalleeContext() const {
694
23.2k
    return static_cast<const StackFrameContext *>(getData1());
695
23.2k
  }
696
697
private:
698
  friend class ProgramPoint;
699
20.2k
  CallExitEnd() = default;
700
251k
  static bool isKind(const ProgramPoint &Location) {
701
251k
    return Location.getKind() == CallExitEndKind;
702
251k
  }
703
};
704
705
/// Represents a point when we exit a loop.
706
/// When this ProgramPoint is encountered we can be sure that the symbolic
707
/// execution of the corresponding LoopStmt is finished on the given path.
708
/// Note: It is possible to encounter a LoopExit element when we haven't even
709
/// encountered the loop itself. At the current state not all loop exits will
710
/// result in a LoopExit program point.
711
class LoopExit : public ProgramPoint {
712
public:
713
    LoopExit(const Stmt *LoopStmt, const LocationContext *LC)
714
141
            : ProgramPoint(LoopStmt, nullptr, LoopExitKind, LC) {}
715
716
0
    const Stmt *getLoopStmt() const {
717
0
      return static_cast<const Stmt *>(getData1());
718
0
    }
719
720
private:
721
    friend class ProgramPoint;
722
264
    LoopExit() = default;
723
753k
    static bool isKind(const ProgramPoint &Location) {
724
753k
      return Location.getKind() == LoopExitKind;
725
753k
    }
726
};
727
728
/// This is a meta program point, which should be skipped by all the diagnostic
729
/// reasoning etc.
730
class EpsilonPoint : public ProgramPoint {
731
public:
732
  EpsilonPoint(const LocationContext *L, const void *Data1,
733
               const void *Data2 = nullptr,
734
               const ProgramPointTag *tag = nullptr)
735
31
    : ProgramPoint(Data1, Data2, EpsilonKind, L, tag) {}
736
737
0
  const void *getData() const { return getData1(); }
738
739
private:
740
  friend class ProgramPoint;
741
27
  EpsilonPoint() = default;
742
753k
  static bool isKind(const ProgramPoint &Location) {
743
753k
    return Location.getKind() == EpsilonKind;
744
753k
  }
745
};
746
747
} // end namespace clang
748
749
750
namespace llvm { // Traits specialization for DenseMap
751
752
template <> struct DenseMapInfo<clang::ProgramPoint> {
753
754
static inline clang::ProgramPoint getEmptyKey() {
755
  uintptr_t x =
756
   reinterpret_cast<uintptr_t>(DenseMapInfo<void*>::getEmptyKey()) & ~0x7;
757
  return clang::BlockEntrance(reinterpret_cast<clang::CFGBlock*>(x), nullptr);
758
}
759
760
static inline clang::ProgramPoint getTombstoneKey() {
761
  uintptr_t x =
762
   reinterpret_cast<uintptr_t>(DenseMapInfo<void*>::getTombstoneKey()) & ~0x7;
763
  return clang::BlockEntrance(reinterpret_cast<clang::CFGBlock*>(x), nullptr);
764
}
765
766
static unsigned getHashValue(const clang::ProgramPoint &Loc) {
767
  return Loc.getHashValue();
768
}
769
770
static bool isEqual(const clang::ProgramPoint &L,
771
                    const clang::ProgramPoint &R) {
772
  return L == R;
773
}
774
775
};
776
777
template <>
778
struct isPodLike<clang::ProgramPoint> { static const bool value = true; };
779
780
} // end namespace llvm
781
782
#endif