Coverage Report

Created: 2018-07-22 10:17

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/APValue.h
Line
Count
Source (jump to first uncovered line)
1
//===--- APValue.h - Union class for APFloat/APSInt/Complex -----*- 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 APValue class.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_APVALUE_H
15
#define LLVM_CLANG_AST_APVALUE_H
16
17
#include "clang/Basic/LLVM.h"
18
#include "llvm/ADT/APFloat.h"
19
#include "llvm/ADT/APSInt.h"
20
#include "llvm/ADT/PointerIntPair.h"
21
#include "llvm/ADT/PointerUnion.h"
22
23
namespace clang {
24
  class AddrLabelExpr;
25
  class ASTContext;
26
  class CharUnits;
27
  class DiagnosticBuilder;
28
  class Expr;
29
  class FieldDecl;
30
  class Decl;
31
  class ValueDecl;
32
  class CXXRecordDecl;
33
  class QualType;
34
35
/// APValue - This class implements a discriminated union of [uninitialized]
36
/// [APSInt] [APFloat], [Complex APSInt] [Complex APFloat], [Expr + Offset],
37
/// [Vector: N * APValue], [Array: N * APValue]
38
class APValue {
39
  typedef llvm::APSInt APSInt;
40
  typedef llvm::APFloat APFloat;
41
public:
42
  enum ValueKind {
43
    Uninitialized,
44
    Int,
45
    Float,
46
    ComplexInt,
47
    ComplexFloat,
48
    LValue,
49
    Vector,
50
    Array,
51
    Struct,
52
    Union,
53
    MemberPointer,
54
    AddrLabelDiff
55
  };
56
57
  class LValueBase {
58
  public:
59
    typedef llvm::PointerUnion<const ValueDecl *, const Expr *> PtrTy;
60
61
13.0M
    LValueBase() : CallIndex(0), Version(0) {}
62
63
    template <class T>
64
    LValueBase(T P, unsigned I = 0, unsigned V = 0)
65
22.7M
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<llvm::PointerUnion<clang::ValueDecl const*, clang::Expr const*> >(llvm::PointerUnion<clang::ValueDecl const*, clang::Expr const*>, unsigned int, unsigned int)
Line
Count
Source
65
2.98M
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<clang::ValueDecl const*>(clang::ValueDecl const*, unsigned int, unsigned int)
Line
Count
Source
65
10.7M
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<clang::Expr const*>(clang::Expr const*, unsigned int, unsigned int)
Line
Count
Source
65
10.9k
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<clang::Expr*>(clang::Expr*, unsigned int, unsigned int)
Line
Count
Source
65
91.5k
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<clang::CallExpr const*>(clang::CallExpr const*, unsigned int, unsigned int)
Line
Count
Source
65
83
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<clang::CXXTypeidExpr const*>(clang::CXXTypeidExpr const*, unsigned int, unsigned int)
Line
Count
Source
65
120
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<clang::CXXUuidofExpr const*>(clang::CXXUuidofExpr const*, unsigned int, unsigned int)
Line
Count
Source
65
75
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<clang::CompoundLiteralExpr const*>(clang::CompoundLiteralExpr const*, unsigned int, unsigned int)
Line
Count
Source
65
503
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<clang::FunctionDecl const*>(clang::FunctionDecl const*, unsigned int, unsigned int)
Line
Count
Source
65
562k
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<clang::MaterializeTemporaryExpr const*>(clang::MaterializeTemporaryExpr const*, unsigned int, unsigned int)
Line
Count
Source
65
5.87k
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<clang::CXXMethodDecl const*>(clang::CXXMethodDecl const*, unsigned int, unsigned int)
Line
Count
Source
65
151
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<clang::MemberExpr const*>(clang::MemberExpr const*, unsigned int, unsigned int)
Line
Count
Source
65
1.59k
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<clang::ObjCEncodeExpr const*>(clang::ObjCEncodeExpr const*, unsigned int, unsigned int)
Line
Count
Source
65
99
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<clang::PredefinedExpr const*>(clang::PredefinedExpr const*, unsigned int, unsigned int)
Line
Count
Source
65
30
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<clang::StringLiteral const*>(clang::StringLiteral const*, unsigned int, unsigned int)
Line
Count
Source
65
37.9k
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<clang::VarDecl const*>(clang::VarDecl const*, unsigned int, unsigned int)
Line
Count
Source
65
8.25M
        : Ptr(P), CallIndex(I), Version(V) {}
clang::APValue::LValueBase::LValueBase<clang::ImplicitValueInitExpr*>(clang::ImplicitValueInitExpr*, unsigned int, unsigned int)
Line
Count
Source
65
36.9k
        : Ptr(P), CallIndex(I), Version(V) {}
66
67
    template <class T>
68
5
    bool is() const { return Ptr.is<T>(); }
69
70
    template <class T>
71
190k
    T get() const { return Ptr.get<T>(); }
72
73
    template <class T>
74
32.4M
    T dyn_cast() const { return Ptr.dyn_cast<T>(); }
clang::ValueDecl const* clang::APValue::LValueBase::dyn_cast<clang::ValueDecl const*>() const
Line
Count
Source
74
25.8M
    T dyn_cast() const { return Ptr.dyn_cast<T>(); }
clang::Expr const* clang::APValue::LValueBase::dyn_cast<clang::Expr const*>() const
Line
Count
Source
74
6.53M
    T dyn_cast() const { return Ptr.dyn_cast<T>(); }
75
76
    void *getOpaqueValue() const;
77
78
    bool isNull() const;
79
80
    explicit operator bool () const;
81
82
0
    PtrTy getPointer() const {
83
0
      return Ptr;
84
0
    }
85
86
8.95M
    unsigned getCallIndex() const {
87
8.95M
      return CallIndex;
88
8.95M
    }
89
90
0
    void setCallIndex(unsigned Index) {
91
0
      CallIndex = Index;
92
0
    }
93
94
2.20M
    unsigned getVersion() const {
95
2.20M
      return Version;
96
2.20M
    }
97
98
29.5M
    bool operator==(const LValueBase &Other) const {
99
29.5M
      return Ptr == Other.Ptr && 
CallIndex == Other.CallIndex27.8M
&&
100
29.5M
             
Version == Other.Version27.8M
;
101
29.5M
    }
102
103
  private:
104
    PtrTy Ptr;
105
    unsigned CallIndex, Version;
106
  };
107
108
  typedef llvm::PointerIntPair<const Decl *, 1, bool> BaseOrMemberType;
109
  union LValuePathEntry {
110
    /// BaseOrMember - The FieldDecl or CXXRecordDecl indicating the next item
111
    /// in the path. An opaque value of type BaseOrMemberType.
112
    void *BaseOrMember;
113
    /// ArrayIndex - The array index of the next item in the path.
114
    uint64_t ArrayIndex;
115
  };
116
  struct NoLValuePath {};
117
  struct UninitArray {};
118
  struct UninitStruct {};
119
private:
120
  ValueKind Kind;
121
122
  struct ComplexAPSInt {
123
    APSInt Real, Imag;
124
69
    ComplexAPSInt() : Real(1), Imag(1) {}
125
  };
126
  struct ComplexAPFloat {
127
    APFloat Real, Imag;
128
172
    ComplexAPFloat() : Real(0.0), Imag(0.0) {}
129
  };
130
  struct LV;
131
  struct Vec {
132
    APValue *Elts;
133
    unsigned NumElts;
134
1.73k
    Vec() : Elts(nullptr), NumElts(0) {}
135
1.73k
    ~Vec() { delete[] Elts; }
136
  };
137
  struct Arr {
138
    APValue *Elts;
139
    unsigned NumElts, ArrSize;
140
    Arr(unsigned NumElts, unsigned ArrSize);
141
    ~Arr();
142
  };
143
  struct StructData {
144
    APValue *Elts;
145
    unsigned NumBases;
146
    unsigned NumFields;
147
    StructData(unsigned NumBases, unsigned NumFields);
148
    ~StructData();
149
  };
150
  struct UnionData {
151
    const FieldDecl *Field;
152
    APValue *Value;
153
    UnionData();
154
    ~UnionData();
155
  };
156
  struct AddrLabelDiffData {
157
    const AddrLabelExpr* LHSExpr;
158
    const AddrLabelExpr* RHSExpr;
159
  };
160
  struct MemberPointerData;
161
162
  // We ensure elsewhere that Data is big enough for LV and MemberPointerData.
163
  typedef llvm::AlignedCharArrayUnion<void *, APSInt, APFloat, ComplexAPSInt,
164
                                      ComplexAPFloat, Vec, Arr, StructData,
165
                                      UnionData, AddrLabelDiffData> DataType;
166
  static const size_t DataSize = sizeof(DataType);
167
168
  DataType Data;
169
170
public:
171
54.0M
  APValue() : Kind(Uninitialized) {}
172
18.6M
  explicit APValue(APSInt I) : Kind(Uninitialized) {
173
18.6M
    MakeInt(); setInt(std::move(I));
174
18.6M
  }
175
235k
  explicit APValue(APFloat F) : Kind(Uninitialized) {
176
235k
    MakeFloat(); setFloat(std::move(F));
177
235k
  }
178
1.32k
  explicit APValue(const APValue *E, unsigned N) : Kind(Uninitialized) {
179
1.32k
    MakeVector(); setVector(E, N);
180
1.32k
  }
181
60
  APValue(APSInt R, APSInt I) : Kind(Uninitialized) {
182
60
    MakeComplexInt(); setComplexInt(std::move(R), std::move(I));
183
60
  }
184
150
  APValue(APFloat R, APFloat I) : Kind(Uninitialized) {
185
150
    MakeComplexFloat(); setComplexFloat(std::move(R), std::move(I));
186
150
  }
187
  APValue(const APValue &RHS);
188
41.4k
  APValue(APValue &&RHS) : Kind(Uninitialized) { swap(RHS); }
189
  APValue(LValueBase B, const CharUnits &O, NoLValuePath N,
190
          bool IsNullPtr = false)
191
27.6k
      : Kind(Uninitialized) {
192
27.6k
    MakeLValue(); setLValue(B, O, N, IsNullPtr);
193
27.6k
  }
194
  APValue(LValueBase B, const CharUnits &O, ArrayRef<LValuePathEntry> Path,
195
          bool OnePastTheEnd, bool IsNullPtr = false)
196
831k
      : Kind(Uninitialized) {
197
831k
    MakeLValue(); setLValue(B, O, Path, OnePastTheEnd, IsNullPtr);
198
831k
  }
199
27.1k
  APValue(UninitArray, unsigned InitElts, unsigned Size) : Kind(Uninitialized) {
200
27.1k
    MakeArray(InitElts, Size);
201
27.1k
  }
202
30.3k
  APValue(UninitStruct, unsigned B, unsigned M) : Kind(Uninitialized) {
203
30.3k
    MakeStruct(B, M);
204
30.3k
  }
205
  explicit APValue(const FieldDecl *D, const APValue &V = APValue())
206
836
      : Kind(Uninitialized) {
207
836
    MakeUnion(); setUnion(D, V);
208
836
  }
209
  APValue(const ValueDecl *Member, bool IsDerivedMember,
210
1.47k
          ArrayRef<const CXXRecordDecl*> Path) : Kind(Uninitialized) {
211
1.47k
    MakeMemberPointer(Member, IsDerivedMember, Path);
212
1.47k
  }
213
  APValue(const AddrLabelExpr* LHSExpr, const AddrLabelExpr* RHSExpr)
214
28
      : Kind(Uninitialized) {
215
28
    MakeAddrLabelDiff(); setAddrLabelDiff(LHSExpr, RHSExpr);
216
28
  }
217
218
76.2M
  ~APValue() {
219
76.2M
    MakeUninit();
220
76.2M
  }
221
222
  /// Returns whether the object performed allocations.
223
  ///
224
  /// If APValues are constructed via placement new, \c needsCleanup()
225
  /// indicates whether the destructor must be called in order to correctly
226
  /// free all allocated memory.
227
  bool needsCleanup() const;
228
229
  /// Swaps the contents of this and the given APValue.
230
  void swap(APValue &RHS);
231
232
5.73M
  ValueKind getKind() const { return Kind; }
233
8.26M
  bool isUninit() const { return Kind == Uninitialized; }
234
13.4M
  bool isInt() const { return Kind == Int; }
235
16.2k
  bool isFloat() const { return Kind == Float; }
236
24
  bool isComplexInt() const { return Kind == ComplexInt; }
237
33
  bool isComplexFloat() const { return Kind == ComplexFloat; }
238
9.74M
  bool isLValue() const { return Kind == LValue; }
239
98
  bool isVector() const { return Kind == Vector; }
240
5.29M
  bool isArray() const { return Kind == Array; }
241
5.27M
  bool isStruct() const { return Kind == Struct; }
242
5.27M
  bool isUnion() const { return Kind == Union; }
243
5.14M
  bool isMemberPointer() const { return Kind == MemberPointer; }
244
1.40M
  bool isAddrLabelDiff() const { return Kind == AddrLabelDiff; }
245
246
  void dump() const;
247
  void dump(raw_ostream &OS) const;
248
249
  void printPretty(raw_ostream &OS, ASTContext &Ctx, QualType Ty) const;
250
  std::string getAsString(ASTContext &Ctx, QualType Ty) const;
251
252
25.8M
  APSInt &getInt() {
253
25.8M
    assert(isInt() && "Invalid accessor");
254
25.8M
    return *(APSInt*)(char*)Data.buffer;
255
25.8M
  }
256
10.6M
  const APSInt &getInt() const {
257
10.6M
    return const_cast<APValue*>(this)->getInt();
258
10.6M
  }
259
260
206k
  APFloat &getFloat() {
261
206k
    assert(isFloat() && "Invalid accessor");
262
206k
    return *(APFloat*)(char*)Data.buffer;
263
206k
  }
264
204k
  const APFloat &getFloat() const {
265
204k
    return const_cast<APValue*>(this)->getFloat();
266
204k
  }
267
268
49
  APSInt &getComplexIntReal() {
269
49
    assert(isComplexInt() && "Invalid accessor");
270
49
    return ((ComplexAPSInt*)(char*)Data.buffer)->Real;
271
49
  }
272
40
  const APSInt &getComplexIntReal() const {
273
40
    return const_cast<APValue*>(this)->getComplexIntReal();
274
40
  }
275
276
40
  APSInt &getComplexIntImag() {
277
40
    assert(isComplexInt() && "Invalid accessor");
278
40
    return ((ComplexAPSInt*)(char*)Data.buffer)->Imag;
279
40
  }
280
31
  const APSInt &getComplexIntImag() const {
281
31
    return const_cast<APValue*>(this)->getComplexIntImag();
282
31
  }
283
284
112
  APFloat &getComplexFloatReal() {
285
112
    assert(isComplexFloat() && "Invalid accessor");
286
112
    return ((ComplexAPFloat*)(char*)Data.buffer)->Real;
287
112
  }
288
110
  const APFloat &getComplexFloatReal() const {
289
110
    return const_cast<APValue*>(this)->getComplexFloatReal();
290
110
  }
291
292
87
  APFloat &getComplexFloatImag() {
293
87
    assert(isComplexFloat() && "Invalid accessor");
294
87
    return ((ComplexAPFloat*)(char*)Data.buffer)->Imag;
295
87
  }
296
85
  const APFloat &getComplexFloatImag() const {
297
85
    return const_cast<APValue*>(this)->getComplexFloatImag();
298
85
  }
299
300
  const LValueBase getLValueBase() const;
301
  CharUnits &getLValueOffset();
302
739k
  const CharUnits &getLValueOffset() const {
303
739k
    return const_cast<APValue*>(this)->getLValueOffset();
304
739k
  }
305
  bool isLValueOnePastTheEnd() const;
306
  bool hasLValuePath() const;
307
  ArrayRef<LValuePathEntry> getLValuePath() const;
308
  unsigned getLValueCallIndex() const;
309
  unsigned getLValueVersion() const;
310
  bool isNullPointer() const;
311
312
5.47k
  APValue &getVectorElt(unsigned I) {
313
5.47k
    assert(isVector() && "Invalid accessor");
314
5.47k
    assert(I < getVectorLength() && "Index out of range");
315
5.47k
    return ((Vec*)(char*)Data.buffer)->Elts[I];
316
5.47k
  }
317
5.03k
  const APValue &getVectorElt(unsigned I) const {
318
5.03k
    return const_cast<APValue*>(this)->getVectorElt(I);
319
5.03k
  }
320
1.69k
  unsigned getVectorLength() const {
321
1.69k
    assert(isVector() && "Invalid accessor");
322
1.69k
    return ((const Vec*)(const void *)Data.buffer)->NumElts;
323
1.69k
  }
324
325
162k
  APValue &getArrayInitializedElt(unsigned I) {
326
162k
    assert(isArray() && "Invalid accessor");
327
162k
    assert(I < getArrayInitializedElts() && "Index out of range");
328
162k
    return ((Arr*)(char*)Data.buffer)->Elts[I];
329
162k
  }
330
65.8k
  const APValue &getArrayInitializedElt(unsigned I) const {
331
65.8k
    return const_cast<APValue*>(this)->getArrayInitializedElt(I);
332
65.8k
  }
333
72.8k
  bool hasArrayFiller() const {
334
72.8k
    return getArrayInitializedElts() != getArraySize();
335
72.8k
  }
336
44.8k
  APValue &getArrayFiller() {
337
44.8k
    assert(isArray() && "Invalid accessor");
338
44.8k
    assert(hasArrayFiller() && "No array filler");
339
44.8k
    return ((Arr*)(char*)Data.buffer)->Elts[getArrayInitializedElts()];
340
44.8k
  }
341
6.87k
  const APValue &getArrayFiller() const {
342
6.87k
    return const_cast<APValue*>(this)->getArrayFiller();
343
6.87k
  }
344
159k
  unsigned getArrayInitializedElts() const {
345
159k
    assert(isArray() && "Invalid accessor");
346
159k
    return ((const Arr*)(const void *)Data.buffer)->NumElts;
347
159k
  }
348
85.7k
  unsigned getArraySize() const {
349
85.7k
    assert(isArray() && "Invalid accessor");
350
85.7k
    return ((const Arr*)(const void *)Data.buffer)->ArrSize;
351
85.7k
  }
352
353
442k
  unsigned getStructNumBases() const {
354
442k
    assert(isStruct() && "Invalid accessor");
355
442k
    return ((const StructData*)(const char*)Data.buffer)->NumBases;
356
442k
  }
357
140k
  unsigned getStructNumFields() const {
358
140k
    assert(isStruct() && "Invalid accessor");
359
140k
    return ((const StructData*)(const char*)Data.buffer)->NumFields;
360
140k
  }
361
3.06k
  APValue &getStructBase(unsigned i) {
362
3.06k
    assert(isStruct() && "Invalid accessor");
363
3.06k
    return ((StructData*)(char*)Data.buffer)->Elts[i];
364
3.06k
  }
365
301k
  APValue &getStructField(unsigned i) {
366
301k
    assert(isStruct() && "Invalid accessor");
367
301k
    return ((StructData*)(char*)Data.buffer)->Elts[getStructNumBases() + i];
368
301k
  }
369
611
  const APValue &getStructBase(unsigned i) const {
370
611
    return const_cast<APValue*>(this)->getStructBase(i);
371
611
  }
372
137k
  const APValue &getStructField(unsigned i) const {
373
137k
    return const_cast<APValue*>(this)->getStructField(i);
374
137k
  }
375
376
807
  const FieldDecl *getUnionField() const {
377
807
    assert(isUnion() && "Invalid accessor");
378
807
    return ((const UnionData*)(const char*)Data.buffer)->Field;
379
807
  }
380
1.20k
  APValue &getUnionValue() {
381
1.20k
    assert(isUnion() && "Invalid accessor");
382
1.20k
    return *((UnionData*)(char*)Data.buffer)->Value;
383
1.20k
  }
384
238
  const APValue &getUnionValue() const {
385
238
    return const_cast<APValue*>(this)->getUnionValue();
386
238
  }
387
388
  const ValueDecl *getMemberPointerDecl() const;
389
  bool isMemberPointerToDerivedMember() const;
390
  ArrayRef<const CXXRecordDecl*> getMemberPointerPath() const;
391
392
17
  const AddrLabelExpr* getAddrLabelDiffLHS() const {
393
17
    assert(isAddrLabelDiff() && "Invalid accessor");
394
17
    return ((const AddrLabelDiffData*)(const char*)Data.buffer)->LHSExpr;
395
17
  }
396
17
  const AddrLabelExpr* getAddrLabelDiffRHS() const {
397
17
    assert(isAddrLabelDiff() && "Invalid accessor");
398
17
    return ((const AddrLabelDiffData*)(const char*)Data.buffer)->RHSExpr;
399
17
  }
400
401
21.3M
  void setInt(APSInt I) {
402
21.3M
    assert(isInt() && "Invalid accessor");
403
21.3M
    *(APSInt *)(char *)Data.buffer = std::move(I);
404
21.3M
  }
405
255k
  void setFloat(APFloat F) {
406
255k
    assert(isFloat() && "Invalid accessor");
407
255k
    *(APFloat *)(char *)Data.buffer = std::move(F);
408
255k
  }
409
1.73k
  void setVector(const APValue *E, unsigned N) {
410
1.73k
    assert(isVector() && "Invalid accessor");
411
1.73k
    ((Vec*)(char*)Data.buffer)->Elts = new APValue[N];
412
1.73k
    ((Vec*)(char*)Data.buffer)->NumElts = N;
413
11.3k
    for (unsigned i = 0; i != N; 
++i9.57k
)
414
9.57k
      ((Vec*)(char*)Data.buffer)->Elts[i] = E[i];
415
1.73k
  }
416
69
  void setComplexInt(APSInt R, APSInt I) {
417
69
    assert(R.getBitWidth() == I.getBitWidth() &&
418
69
           "Invalid complex int (type mismatch).");
419
69
    assert(isComplexInt() && "Invalid accessor");
420
69
    ((ComplexAPSInt *)(char *)Data.buffer)->Real = std::move(R);
421
69
    ((ComplexAPSInt *)(char *)Data.buffer)->Imag = std::move(I);
422
69
  }
423
172
  void setComplexFloat(APFloat R, APFloat I) {
424
172
    assert(&R.getSemantics() == &I.getSemantics() &&
425
172
           "Invalid complex float (type mismatch).");
426
172
    assert(isComplexFloat() && "Invalid accessor");
427
172
    ((ComplexAPFloat *)(char *)Data.buffer)->Real = std::move(R);
428
172
    ((ComplexAPFloat *)(char *)Data.buffer)->Imag = std::move(I);
429
172
  }
430
  void setLValue(LValueBase B, const CharUnits &O, NoLValuePath,
431
                 bool IsNullPtr);
432
  void setLValue(LValueBase B, const CharUnits &O,
433
                 ArrayRef<LValuePathEntry> Path, bool OnePastTheEnd,
434
                 bool IsNullPtr);
435
878
  void setUnion(const FieldDecl *Field, const APValue &Value) {
436
878
    assert(isUnion() && "Invalid accessor");
437
878
    ((UnionData*)(char*)Data.buffer)->Field = Field;
438
878
    *((UnionData*)(char*)Data.buffer)->Value = Value;
439
878
  }
440
  void setAddrLabelDiff(const AddrLabelExpr* LHSExpr,
441
39
                        const AddrLabelExpr* RHSExpr) {
442
39
    ((AddrLabelDiffData*)(char*)Data.buffer)->LHSExpr = LHSExpr;
443
39
    ((AddrLabelDiffData*)(char*)Data.buffer)->RHSExpr = RHSExpr;
444
39
  }
445
446
  /// Assign by swapping from a copy of the RHS.
447
25.9M
  APValue &operator=(APValue RHS) {
448
25.9M
    swap(RHS);
449
25.9M
    return *this;
450
25.9M
  }
451
452
private:
453
  void DestroyDataAndMakeUninit();
454
76.2M
  void MakeUninit() {
455
76.2M
    if (Kind != Uninitialized)
456
22.2M
      DestroyDataAndMakeUninit();
457
76.2M
  }
458
21.3M
  void MakeInt() {
459
21.3M
    assert(isUninit() && "Bad state change");
460
21.3M
    new ((void*)Data.buffer) APSInt(1);
461
21.3M
    Kind = Int;
462
21.3M
  }
463
255k
  void MakeFloat() {
464
255k
    assert(isUninit() && "Bad state change");
465
255k
    new ((void*)(char*)Data.buffer) APFloat(0.0);
466
255k
    Kind = Float;
467
255k
  }
468
1.73k
  void MakeVector() {
469
1.73k
    assert(isUninit() && "Bad state change");
470
1.73k
    new ((void*)(char*)Data.buffer) Vec();
471
1.73k
    Kind = Vector;
472
1.73k
  }
473
69
  void MakeComplexInt() {
474
69
    assert(isUninit() && "Bad state change");
475
69
    new ((void*)(char*)Data.buffer) ComplexAPSInt();
476
69
    Kind = ComplexInt;
477
69
  }
478
172
  void MakeComplexFloat() {
479
172
    assert(isUninit() && "Bad state change");
480
172
    new ((void*)(char*)Data.buffer) ComplexAPFloat();
481
172
    Kind = ComplexFloat;
482
172
  }
483
  void MakeLValue();
484
  void MakeArray(unsigned InitElts, unsigned Size);
485
100k
  void MakeStruct(unsigned B, unsigned M) {
486
100k
    assert(isUninit() && "Bad state change");
487
100k
    new ((void*)(char*)Data.buffer) StructData(B, M);
488
100k
    Kind = Struct;
489
100k
  }
490
878
  void MakeUnion() {
491
878
    assert(isUninit() && "Bad state change");
492
878
    new ((void*)(char*)Data.buffer) UnionData();
493
878
    Kind = Union;
494
878
  }
495
  void MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember,
496
                         ArrayRef<const CXXRecordDecl*> Path);
497
39
  void MakeAddrLabelDiff() {
498
39
    assert(isUninit() && "Bad state change");
499
39
    new ((void*)(char*)Data.buffer) AddrLabelDiffData();
500
39
    Kind = AddrLabelDiff;
501
39
  }
502
};
503
504
} // end namespace clang.
505
506
namespace llvm {
507
template<> struct DenseMapInfo<clang::APValue::LValueBase> {
508
  static clang::APValue::LValueBase getEmptyKey();
509
  static clang::APValue::LValueBase getTombstoneKey();
510
  static unsigned getHashValue(const clang::APValue::LValueBase &Base);
511
  static bool isEqual(const clang::APValue::LValueBase &LHS,
512
                      const clang::APValue::LValueBase &RHS);
513
};
514
}
515
516
#endif