Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/APValue.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- APValue.cpp - Union class for APFloat/APSInt/Complex -------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
//  This file implements the APValue class.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/AST/APValue.h"
14
#include "Linkage.h"
15
#include "clang/AST/ASTContext.h"
16
#include "clang/AST/CharUnits.h"
17
#include "clang/AST/DeclCXX.h"
18
#include "clang/AST/Expr.h"
19
#include "clang/AST/ExprCXX.h"
20
#include "clang/AST/Type.h"
21
#include "llvm/Support/ErrorHandling.h"
22
#include "llvm/Support/raw_ostream.h"
23
using namespace clang;
24
25
/// The identity of a type_info object depends on the canonical unqualified
26
/// type only.
27
TypeInfoLValue::TypeInfoLValue(const Type *T)
28
1.38k
    : T(T->getCanonicalTypeUnqualified().getTypePtr()) {}
29
30
void TypeInfoLValue::print(llvm::raw_ostream &Out,
31
45
                           const PrintingPolicy &Policy) const {
32
45
  Out << "typeid(";
33
45
  QualType(getType(), 0).print(Out, Policy);
34
45
  Out << ")";
35
45
}
36
37
static_assert(
38
    1 << llvm::PointerLikeTypeTraits<TypeInfoLValue>::NumLowBitsAvailable <=
39
        alignof(Type),
40
    "Type is insufficiently aligned");
41
42
APValue::LValueBase::LValueBase(const ValueDecl *P, unsigned I, unsigned V)
43
32.4M
    : Ptr(P ? cast<ValueDecl>(P->getCanonicalDecl()) : nullptr), Local{I, V} {}
44
APValue::LValueBase::LValueBase(const Expr *P, unsigned I, unsigned V)
45
2.06M
    : Ptr(P), Local{I, V} {}
46
47
APValue::LValueBase APValue::LValueBase::getDynamicAlloc(DynamicAllocLValue LV,
48
838
                                                         QualType Type) {
49
838
  LValueBase Base;
50
838
  Base.Ptr = LV;
51
838
  Base.DynamicAllocType = Type.getAsOpaquePtr();
52
838
  return Base;
53
838
}
54
55
APValue::LValueBase APValue::LValueBase::getTypeInfo(TypeInfoLValue LV,
56
1.38k
                                                     QualType TypeInfo) {
57
1.38k
  LValueBase Base;
58
1.38k
  Base.Ptr = LV;
59
1.38k
  Base.TypeInfoType = TypeInfo.getAsOpaquePtr();
60
1.38k
  return Base;
61
1.38k
}
62
63
18.7M
QualType APValue::LValueBase::getType() const {
64
18.7M
  if (!*this) 
return QualType()21
;
65
18.7M
  if (const ValueDecl *D = dyn_cast<const ValueDecl*>()) {
66
    // FIXME: It's unclear where we're supposed to take the type from, and
67
    // this actually matters for arrays of unknown bound. Eg:
68
    //
69
    // extern int arr[]; void f() { extern int arr[3]; };
70
    // constexpr int *p = &arr[1]; // valid?
71
    //
72
    // For now, we take the most complete type we can find.
73
16.5M
    for (auto *Redecl = cast<ValueDecl>(D->getMostRecentDecl()); Redecl;
74
16.5M
         
Redecl = cast_or_null<ValueDecl>(Redecl->getPreviousDecl())2.46k
) {
75
16.5M
      QualType T = Redecl->getType();
76
16.5M
      if (!T->isIncompleteArrayType())
77
16.5M
        return T;
78
16.5M
    }
79
2.01k
    return D->getType();
80
16.5M
  }
81
82
2.16M
  if (is<TypeInfoLValue>())
83
2.63k
    return getTypeInfoType();
84
85
2.15M
  if (is<DynamicAllocLValue>())
86
6.06k
    return getDynamicAllocType();
87
88
2.15M
  const Expr *Base = get<const Expr*>();
89
90
  // For a materialized temporary, the type of the temporary we materialized
91
  // may not be the type of the expression.
92
2.15M
  if (const MaterializeTemporaryExpr *MTE =
93
2.15M
          clang::dyn_cast<MaterializeTemporaryExpr>(Base)) {
94
2.03M
    SmallVector<const Expr *, 2> CommaLHSs;
95
2.03M
    SmallVector<SubobjectAdjustment, 2> Adjustments;
96
2.03M
    const Expr *Temp = MTE->getSubExpr();
97
2.03M
    const Expr *Inner = Temp->skipRValueSubobjectAdjustments(CommaLHSs,
98
2.03M
                                                             Adjustments);
99
    // Keep any cv-qualifiers from the reference if we generated a temporary
100
    // for it directly. Otherwise use the type after adjustment.
101
2.03M
    if (!Adjustments.empty())
102
3.20k
      return Inner->getType();
103
2.03M
  }
104
105
2.14M
  return Base->getType();
106
2.15M
}
107
108
10.2M
unsigned APValue::LValueBase::getCallIndex() const {
109
10.2M
  return (is<TypeInfoLValue>() || 
is<DynamicAllocLValue>()10.2M
) ?
03.70k
110
10.2M
                                                            : 
Local.CallIndex10.2M
;
111
10.2M
}
112
113
5.02M
unsigned APValue::LValueBase::getVersion() const {
114
5.02M
  return (is<TypeInfoLValue>() || 
is<DynamicAllocLValue>()5.02M
) ?
052
:
Local.Version5.02M
;
115
5.02M
}
116
117
2.78k
QualType APValue::LValueBase::getTypeInfoType() const {
118
2.78k
  assert(is<TypeInfoLValue>() && "not a type_info lvalue");
119
0
  return QualType::getFromOpaquePtr(TypeInfoType);
120
2.78k
}
121
122
8.72k
QualType APValue::LValueBase::getDynamicAllocType() const {
123
8.72k
  assert(is<DynamicAllocLValue>() && "not a dynamic allocation lvalue");
124
0
  return QualType::getFromOpaquePtr(DynamicAllocType);
125
8.72k
}
126
127
73
void APValue::LValueBase::Profile(llvm::FoldingSetNodeID &ID) const {
128
73
  ID.AddPointer(Ptr.getOpaqueValue());
129
73
  if (is<TypeInfoLValue>() || is<DynamicAllocLValue>())
130
0
    return;
131
73
  ID.AddInteger(Local.CallIndex);
132
73
  ID.AddInteger(Local.Version);
133
73
}
134
135
namespace clang {
136
bool operator==(const APValue::LValueBase &LHS,
137
7.24M
                const APValue::LValueBase &RHS) {
138
7.24M
  if (LHS.Ptr != RHS.Ptr)
139
5.73M
    return false;
140
1.51M
  if (LHS.is<TypeInfoLValue>() || LHS.is<DynamicAllocLValue>())
141
490
    return true;
142
1.51M
  return LHS.Local.CallIndex == RHS.Local.CallIndex &&
143
1.51M
         
LHS.Local.Version == RHS.Local.Version1.51M
;
144
1.51M
}
145
}
146
147
174k
APValue::LValuePathEntry::LValuePathEntry(BaseOrMemberType BaseOrMember) {
148
174k
  if (const Decl *D = BaseOrMember.getPointer())
149
174k
    BaseOrMember.setPointer(D->getCanonicalDecl());
150
174k
  Value = reinterpret_cast<uintptr_t>(BaseOrMember.getOpaqueValue());
151
174k
}
152
153
49
void APValue::LValuePathEntry::Profile(llvm::FoldingSetNodeID &ID) const {
154
49
  ID.AddInteger(Value);
155
49
}
156
157
APValue::LValuePathSerializationHelper::LValuePathSerializationHelper(
158
    ArrayRef<LValuePathEntry> Path, QualType ElemTy)
159
25
    : ElemTy((const void *)ElemTy.getTypePtrOrNull()), Path(Path) {}
160
161
25
QualType APValue::LValuePathSerializationHelper::getType() {
162
25
  return QualType::getFromOpaquePtr(ElemTy);
163
25
}
164
165
namespace {
166
  struct LVBase {
167
    APValue::LValueBase Base;
168
    CharUnits Offset;
169
    unsigned PathLength;
170
    bool IsNullPtr : 1;
171
    bool IsOnePastTheEnd : 1;
172
  };
173
}
174
175
115k
void *APValue::LValueBase::getOpaqueValue() const {
176
115k
  return Ptr.getOpaqueValue();
177
115k
}
178
179
7.18k
bool APValue::LValueBase::isNull() const {
180
7.18k
  return Ptr.isNull();
181
7.18k
}
182
183
27.5M
APValue::LValueBase::operator bool () const {
184
27.5M
  return static_cast<bool>(Ptr);
185
27.5M
}
186
187
clang::APValue::LValueBase
188
176k
llvm::DenseMapInfo<clang::APValue::LValueBase>::getEmptyKey() {
189
176k
  clang::APValue::LValueBase B;
190
176k
  B.Ptr = DenseMapInfo<const ValueDecl*>::getEmptyKey();
191
176k
  return B;
192
176k
}
193
194
clang::APValue::LValueBase
195
155k
llvm::DenseMapInfo<clang::APValue::LValueBase>::getTombstoneKey() {
196
155k
  clang::APValue::LValueBase B;
197
155k
  B.Ptr = DenseMapInfo<const ValueDecl*>::getTombstoneKey();
198
155k
  return B;
199
155k
}
200
201
namespace clang {
202
107k
llvm::hash_code hash_value(const APValue::LValueBase &Base) {
203
107k
  if (Base.is<TypeInfoLValue>() || Base.is<DynamicAllocLValue>())
204
750
    return llvm::hash_value(Base.getOpaqueValue());
205
106k
  return llvm::hash_combine(Base.getOpaqueValue(), Base.getCallIndex(),
206
106k
                            Base.getVersion());
207
107k
}
208
}
209
210
unsigned llvm::DenseMapInfo<clang::APValue::LValueBase>::getHashValue(
211
0
    const clang::APValue::LValueBase &Base) {
212
0
  return hash_value(Base);
213
0
}
214
215
bool llvm::DenseMapInfo<clang::APValue::LValueBase>::isEqual(
216
    const clang::APValue::LValueBase &LHS,
217
0
    const clang::APValue::LValueBase &RHS) {
218
0
  return LHS == RHS;
219
0
}
220
221
struct APValue::LV : LVBase {
222
  static const unsigned InlinePathSpace =
223
      (DataSize - sizeof(LVBase)) / sizeof(LValuePathEntry);
224
225
  /// Path - The sequence of base classes, fields and array indices to follow to
226
  /// walk from Base to the subobject. When performing GCC-style folding, there
227
  /// may not be such a path.
228
  union {
229
    LValuePathEntry Path[InlinePathSpace];
230
    LValuePathEntry *PathPtr;
231
  };
232
233
1.26M
  LV() { PathLength = (unsigned)-1; }
234
1.25M
  ~LV() { resizePath(0); }
235
236
2.52M
  void resizePath(unsigned Length) {
237
2.52M
    if (Length == PathLength)
238
1.18M
      return;
239
1.33M
    if (hasPathPtr())
240
148
      delete [] PathPtr;
241
1.33M
    PathLength = Length;
242
1.33M
    if (hasPathPtr())
243
148
      PathPtr = new LValuePathEntry[Length];
244
1.33M
  }
245
246
7.59M
  bool hasPath() const { return PathLength != (unsigned)-1; }
247
5.39M
  bool hasPathPtr() const { return hasPath() && 
PathLength > InlinePathSpace4.12M
; }
248
249
1.25M
  LValuePathEntry *getPath() { return hasPathPtr() ? 
PathPtr148
:
Path1.25M
; }
250
1.44M
  const LValuePathEntry *getPath() const {
251
1.44M
    return hasPathPtr() ? 
PathPtr343
:
Path1.44M
;
252
1.44M
  }
253
};
254
255
namespace {
256
  struct MemberPointerBase {
257
    llvm::PointerIntPair<const ValueDecl*, 1, bool> MemberAndIsDerivedMember;
258
    unsigned PathLength;
259
  };
260
}
261
262
struct APValue::MemberPointerData : MemberPointerBase {
263
  static const unsigned InlinePathSpace =
264
      (DataSize - sizeof(MemberPointerBase)) / sizeof(const CXXRecordDecl*);
265
  typedef const CXXRecordDecl *PathElem;
266
  union {
267
    PathElem Path[InlinePathSpace];
268
    PathElem *PathPtr;
269
  };
270
271
2.12k
  MemberPointerData() { PathLength = 0; }
272
1.59k
  ~MemberPointerData() { resizePath(0); }
273
274
3.72k
  void resizePath(unsigned Length) {
275
3.72k
    if (Length == PathLength)
276
3.08k
      return;
277
637
    if (hasPathPtr())
278
91
      delete [] PathPtr;
279
637
    PathLength = Length;
280
637
    if (hasPathPtr())
281
91
      PathPtr = new PathElem[Length];
282
637
  }
283
284
5.02k
  bool hasPathPtr() const { return PathLength > InlinePathSpace; }
285
286
2.12k
  PathElem *getPath() { return hasPathPtr() ? 
PathPtr91
:
Path2.03k
; }
287
1.08k
  const PathElem *getPath() const {
288
1.08k
    return hasPathPtr() ? 
PathPtr168
:
Path919
;
289
1.08k
  }
290
};
291
292
// FIXME: Reduce the malloc traffic here.
293
294
APValue::Arr::Arr(unsigned NumElts, unsigned Size) :
295
  Elts(new APValue[NumElts + (NumElts != Size ? 1 : 0)]),
296
17.6k
  NumElts(NumElts), ArrSize(Size) {}
297
17.6k
APValue::Arr::~Arr() { delete [] Elts; }
298
299
APValue::StructData::StructData(unsigned NumBases, unsigned NumFields) :
300
  Elts(new APValue[NumBases+NumFields]),
301
50.1k
  NumBases(NumBases), NumFields(NumFields) {}
302
50.1k
APValue::StructData::~StructData() {
303
50.1k
  delete [] Elts;
304
50.1k
}
305
306
2.95k
APValue::UnionData::UnionData() : Field(nullptr), Value(new APValue) {}
307
2.95k
APValue::UnionData::~UnionData () {
308
2.95k
  delete Value;
309
2.95k
}
310
311
9.36M
APValue::APValue(const APValue &RHS) : Kind(None) {
312
9.36M
  switch (RHS.getKind()) {
313
9.42k
  case None:
314
10.6k
  case Indeterminate:
315
10.6k
    Kind = RHS.getKind();
316
10.6k
    break;
317
9.29M
  case Int:
318
9.29M
    MakeInt();
319
9.29M
    setInt(RHS.getInt());
320
9.29M
    break;
321
16.8k
  case Float:
322
16.8k
    MakeFloat();
323
16.8k
    setFloat(RHS.getFloat());
324
16.8k
    break;
325
6
  case FixedPoint: {
326
6
    APFixedPoint FXCopy = RHS.getFixedPoint();
327
6
    MakeFixedPoint(std::move(FXCopy));
328
6
    break;
329
9.42k
  }
330
1.77k
  case Vector:
331
1.77k
    MakeVector();
332
1.77k
    setVector(((const Vec *)(const char *)&RHS.Data)->Elts,
333
1.77k
              RHS.getVectorLength());
334
1.77k
    break;
335
171
  case ComplexInt:
336
171
    MakeComplexInt();
337
171
    setComplexInt(RHS.getComplexIntReal(), RHS.getComplexIntImag());
338
171
    break;
339
174
  case ComplexFloat:
340
174
    MakeComplexFloat();
341
174
    setComplexFloat(RHS.getComplexFloatReal(), RHS.getComplexFloatImag());
342
174
    break;
343
31.8k
  case LValue:
344
31.8k
    MakeLValue();
345
31.8k
    if (RHS.hasLValuePath())
346
31.4k
      setLValue(RHS.getLValueBase(), RHS.getLValueOffset(), RHS.getLValuePath(),
347
31.4k
                RHS.isLValueOnePastTheEnd(), RHS.isNullPointer());
348
373
    else
349
373
      setLValue(RHS.getLValueBase(), RHS.getLValueOffset(), NoLValuePath(),
350
373
                RHS.isNullPointer());
351
31.8k
    break;
352
1.33k
  case Array:
353
1.33k
    MakeArray(RHS.getArrayInitializedElts(), RHS.getArraySize());
354
6.79k
    for (unsigned I = 0, N = RHS.getArrayInitializedElts(); I != N; 
++I5.46k
)
355
5.46k
      getArrayInitializedElt(I) = RHS.getArrayInitializedElt(I);
356
1.33k
    if (RHS.hasArrayFiller())
357
418
      getArrayFiller() = RHS.getArrayFiller();
358
1.33k
    break;
359
4.75k
  case Struct:
360
4.75k
    MakeStruct(RHS.getStructNumBases(), RHS.getStructNumFields());
361
5.22k
    for (unsigned I = 0, N = RHS.getStructNumBases(); I != N; 
++I468
)
362
468
      getStructBase(I) = RHS.getStructBase(I);
363
11.9k
    for (unsigned I = 0, N = RHS.getStructNumFields(); I != N; 
++I7.16k
)
364
7.16k
      getStructField(I) = RHS.getStructField(I);
365
4.75k
    break;
366
568
  case Union:
367
568
    MakeUnion();
368
568
    setUnion(RHS.getUnionField(), RHS.getUnionValue());
369
568
    break;
370
457
  case MemberPointer:
371
457
    MakeMemberPointer(RHS.getMemberPointerDecl(),
372
457
                      RHS.isMemberPointerToDerivedMember(),
373
457
                      RHS.getMemberPointerPath());
374
457
    break;
375
19
  case AddrLabelDiff:
376
19
    MakeAddrLabelDiff();
377
19
    setAddrLabelDiff(RHS.getAddrLabelDiffLHS(), RHS.getAddrLabelDiffRHS());
378
19
    break;
379
9.36M
  }
380
9.36M
}
381
382
80.5k
APValue::APValue(APValue &&RHS) : Kind(RHS.Kind), Data(RHS.Data) {
383
80.5k
  RHS.Kind = None;
384
80.5k
}
385
386
3.52M
APValue &APValue::operator=(const APValue &RHS) {
387
3.52M
  if (this != &RHS)
388
3.52M
    *this = APValue(RHS);
389
3.52M
  return *this;
390
3.52M
}
391
392
35.6M
APValue &APValue::operator=(APValue &&RHS) {
393
35.6M
  if (Kind != None && 
Kind != Indeterminate2.30M
)
394
2.30M
    DestroyDataAndMakeUninit();
395
35.6M
  Kind = RHS.Kind;
396
35.6M
  Data = RHS.Data;
397
35.6M
  RHS.Kind = None;
398
35.6M
  return *this;
399
35.6M
}
400
401
41.1M
void APValue::DestroyDataAndMakeUninit() {
402
41.1M
  if (Kind == Int)
403
39.7M
    ((APSInt *)(char *)&Data)->~APSInt();
404
1.39M
  else if (Kind == Float)
405
60.6k
    ((APFloat *)(char *)&Data)->~APFloat();
406
1.33M
  else if (Kind == FixedPoint)
407
2.90k
    ((APFixedPoint *)(char *)&Data)->~APFixedPoint();
408
1.33M
  else if (Kind == Vector)
409
4.77k
    ((Vec *)(char *)&Data)->~Vec();
410
1.33M
  else if (Kind == ComplexInt)
411
258
    ((ComplexAPSInt *)(char *)&Data)->~ComplexAPSInt();
412
1.32M
  else if (Kind == ComplexFloat)
413
362
    ((ComplexAPFloat *)(char *)&Data)->~ComplexAPFloat();
414
1.32M
  else if (Kind == LValue)
415
1.25M
    ((LV *)(char *)&Data)->~LV();
416
72.3k
  else if (Kind == Array)
417
17.6k
    ((Arr *)(char *)&Data)->~Arr();
418
54.7k
  else if (Kind == Struct)
419
50.1k
    ((StructData *)(char *)&Data)->~StructData();
420
4.60k
  else if (Kind == Union)
421
2.95k
    ((UnionData *)(char *)&Data)->~UnionData();
422
1.65k
  else if (Kind == MemberPointer)
423
1.59k
    ((MemberPointerData *)(char *)&Data)->~MemberPointerData();
424
56
  else if (Kind == AddrLabelDiff)
425
56
    ((AddrLabelDiffData *)(char *)&Data)->~AddrLabelDiffData();
426
41.1M
  Kind = None;
427
41.1M
}
428
429
353k
bool APValue::needsCleanup() const {
430
353k
  switch (getKind()) {
431
4
  case None:
432
4
  case Indeterminate:
433
12
  case AddrLabelDiff:
434
12
    return false;
435
15.1k
  case Struct:
436
15.5k
  case Union:
437
20.2k
  case Array:
438
20.6k
  case Vector:
439
20.6k
    return true;
440
321k
  case Int:
441
321k
    return getInt().needsCleanup();
442
2.05k
  case Float:
443
2.05k
    return getFloat().needsCleanup();
444
350
  case FixedPoint:
445
350
    return getFixedPoint().getValue().needsCleanup();
446
55
  case ComplexFloat:
447
55
    assert(getComplexFloatImag().needsCleanup() ==
448
55
               getComplexFloatReal().needsCleanup() &&
449
55
           "In _Complex float types, real and imaginary values always have the "
450
55
           "same size.");
451
0
    return getComplexFloatReal().needsCleanup();
452
31
  case ComplexInt:
453
31
    assert(getComplexIntImag().needsCleanup() ==
454
31
               getComplexIntReal().needsCleanup() &&
455
31
           "In _Complex int types, real and imaginary values must have the "
456
31
           "same size.");
457
0
    return getComplexIntReal().needsCleanup();
458
8.50k
  case LValue:
459
8.50k
    return reinterpret_cast<const LV *>(&Data)->hasPathPtr();
460
539
  case MemberPointer:
461
539
    return reinterpret_cast<const MemberPointerData *>(&Data)->hasPathPtr();
462
353k
  }
463
0
  llvm_unreachable("Unknown APValue kind!");
464
0
}
465
466
12.5M
void APValue::swap(APValue &RHS) {
467
12.5M
  std::swap(Kind, RHS.Kind);
468
12.5M
  std::swap(Data, RHS.Data);
469
12.5M
}
470
471
/// Profile the value of an APInt, excluding its bit-width.
472
1.03k
static void profileIntValue(llvm::FoldingSetNodeID &ID, const llvm::APInt &V) {
473
2.11k
  for (unsigned I = 0, N = V.getBitWidth(); I < N; 
I += 321.08k
)
474
1.08k
    ID.AddInteger((uint32_t)V.extractBitsAsZExtValue(std::min(32u, N - I), I));
475
1.03k
}
476
477
1.78k
void APValue::Profile(llvm::FoldingSetNodeID &ID) const {
478
  // Note that our profiling assumes that only APValues of the same type are
479
  // ever compared. As a result, we don't consider collisions that could only
480
  // happen if the types are different. (For example, structs with different
481
  // numbers of members could profile the same.)
482
483
1.78k
  ID.AddInteger(Kind);
484
485
1.78k
  switch (Kind) {
486
41
  case None:
487
41
  case Indeterminate:
488
41
    return;
489
490
0
  case AddrLabelDiff:
491
0
    ID.AddPointer(getAddrLabelDiffLHS()->getLabel()->getCanonicalDecl());
492
0
    ID.AddPointer(getAddrLabelDiffRHS()->getLabel()->getCanonicalDecl());
493
0
    return;
494
495
439
  case Struct:
496
464
    for (unsigned I = 0, N = getStructNumBases(); I != N; 
++I25
)
497
25
      getStructBase(I).Profile(ID);
498
1.07k
    for (unsigned I = 0, N = getStructNumFields(); I != N; 
++I633
)
499
633
      getStructField(I).Profile(ID);
500
439
    return;
501
502
55
  case Union:
503
55
    if (!getUnionField()) {
504
9
      ID.AddInteger(0);
505
9
      return;
506
9
    }
507
46
    ID.AddInteger(getUnionField()->getFieldIndex() + 1);
508
46
    getUnionValue().Profile(ID);
509
46
    return;
510
511
122
  case Array: {
512
122
    if (getArraySize() == 0)
513
0
      return;
514
515
    // The profile should not depend on whether the array is expanded or
516
    // not, but we don't want to profile the array filler many times for
517
    // a large array. So treat all equal trailing elements as the filler.
518
    // Elements are profiled in reverse order to support this, and the
519
    // first profiled element is followed by a count. For example:
520
    //
521
    //   ['a', 'c', 'x', 'x', 'x'] is profiled as
522
    //   [5, 'x', 3, 'c', 'a']
523
122
    llvm::FoldingSetNodeID FillerID;
524
122
    (hasArrayFiller() ? 
getArrayFiller()86
525
122
                      : 
getArrayInitializedElt(getArrayInitializedElts() - 1)36
)
526
122
        .Profile(FillerID);
527
122
    ID.AddNodeID(FillerID);
528
122
    unsigned NumFillers = getArraySize() - getArrayInitializedElts();
529
122
    unsigned N = getArrayInitializedElts();
530
531
    // Count the number of elements equal to the last one. This loop ends
532
    // by adding an integer indicating the number of such elements, with
533
    // N set to the number of elements left to profile.
534
183
    while (true) {
535
183
      if (N == 0) {
536
        // All elements are fillers.
537
19
        assert(NumFillers == getArraySize());
538
0
        ID.AddInteger(NumFillers);
539
19
        break;
540
19
      }
541
542
      // No need to check if the last element is equal to the last
543
      // element.
544
164
      if (N != getArraySize()) {
545
128
        llvm::FoldingSetNodeID ElemID;
546
128
        getArrayInitializedElt(N - 1).Profile(ElemID);
547
128
        if (ElemID != FillerID) {
548
103
          ID.AddInteger(NumFillers);
549
103
          ID.AddNodeID(ElemID);
550
103
          --N;
551
103
          break;
552
103
        }
553
128
      }
554
555
      // This is a filler.
556
61
      ++NumFillers;
557
61
      --N;
558
61
    }
559
560
    // Emit the remaining elements.
561
385
    for (; N != 0; 
--N263
)
562
263
      getArrayInitializedElt(N - 1).Profile(ID);
563
122
    return;
564
122
  }
565
566
40
  case Vector:
567
158
    for (unsigned I = 0, N = getVectorLength(); I != N; 
++I118
)
568
118
      getVectorElt(I).Profile(ID);
569
40
    return;
570
571
852
  case Int:
572
852
    profileIntValue(ID, getInt());
573
852
    return;
574
575
74
  case Float:
576
74
    profileIntValue(ID, getFloat().bitcastToAPInt());
577
74
    return;
578
579
0
  case FixedPoint:
580
0
    profileIntValue(ID, getFixedPoint().getValue());
581
0
    return;
582
583
26
  case ComplexFloat:
584
26
    profileIntValue(ID, getComplexFloatReal().bitcastToAPInt());
585
26
    profileIntValue(ID, getComplexFloatImag().bitcastToAPInt());
586
26
    return;
587
588
26
  case ComplexInt:
589
26
    profileIntValue(ID, getComplexIntReal());
590
26
    profileIntValue(ID, getComplexIntImag());
591
26
    return;
592
593
73
  case LValue:
594
73
    getLValueBase().Profile(ID);
595
73
    ID.AddInteger(getLValueOffset().getQuantity());
596
73
    ID.AddInteger((isNullPointer() ? 
124
:
049
) |
597
73
                  (isLValueOnePastTheEnd() ? 
21
:
072
) |
598
73
                  (hasLValuePath() ? 
464
:
09
));
599
73
    if (hasLValuePath()) {
600
64
      ID.AddInteger(getLValuePath().size());
601
      // For uniqueness, we only need to profile the entries corresponding
602
      // to union members, but we don't have the type here so we don't know
603
      // how to interpret the entries.
604
64
      for (LValuePathEntry E : getLValuePath())
605
49
        E.Profile(ID);
606
64
    }
607
73
    return;
608
609
33
  case MemberPointer:
610
33
    ID.AddPointer(getMemberPointerDecl());
611
33
    ID.AddInteger(isMemberPointerToDerivedMember());
612
33
    for (const CXXRecordDecl *D : getMemberPointerPath())
613
7
      ID.AddPointer(D);
614
33
    return;
615
1.78k
  }
616
617
0
  llvm_unreachable("Unknown APValue kind!");
618
0
}
619
620
21
static double GetApproxValue(const llvm::APFloat &F) {
621
21
  llvm::APFloat V = F;
622
21
  bool ignored;
623
21
  V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven,
624
21
            &ignored);
625
21
  return V.convertToDouble();
626
21
}
627
628
void APValue::printPretty(raw_ostream &Out, const ASTContext &Ctx,
629
3.31k
                          QualType Ty) const {
630
3.31k
  printPretty(Out, Ctx.getPrintingPolicy(), Ty, &Ctx);
631
3.31k
}
632
633
void APValue::printPretty(raw_ostream &Out, const PrintingPolicy &Policy,
634
3.42k
                          QualType Ty, const ASTContext *Ctx) const {
635
  // There are no objects of type 'void', but values of this type can be
636
  // returned from functions.
637
3.42k
  if (Ty->isVoidType()) {
638
0
    Out << "void()";
639
0
    return;
640
0
  }
641
642
3.42k
  switch (getKind()) {
643
0
  case APValue::None:
644
0
    Out << "<out of lifetime>";
645
0
    return;
646
4
  case APValue::Indeterminate:
647
4
    Out << "<uninitialized>";
648
4
    return;
649
1.41k
  case APValue::Int:
650
1.41k
    if (Ty->isBooleanType())
651
44
      Out << (getInt().getBoolValue() ? 
"true"29
:
"false"15
);
652
1.36k
    else
653
1.36k
      Out << getInt();
654
1.41k
    return;
655
17
  case APValue::Float:
656
17
    Out << GetApproxValue(getFloat());
657
17
    return;
658
0
  case APValue::FixedPoint:
659
0
    Out << getFixedPoint();
660
0
    return;
661
2
  case APValue::Vector: {
662
2
    Out << '{';
663
2
    QualType ElemTy = Ty->castAs<VectorType>()->getElementType();
664
2
    getVectorElt(0).printPretty(Out, Policy, ElemTy, Ctx);
665
8
    for (unsigned i = 1; i != getVectorLength(); 
++i6
) {
666
6
      Out << ", ";
667
6
      getVectorElt(i).printPretty(Out, Policy, ElemTy, Ctx);
668
6
    }
669
2
    Out << '}';
670
2
    return;
671
0
  }
672
2
  case APValue::ComplexInt:
673
2
    Out << getComplexIntReal() << "+" << getComplexIntImag() << "i";
674
2
    return;
675
2
  case APValue::ComplexFloat:
676
2
    Out << GetApproxValue(getComplexFloatReal()) << "+"
677
2
        << GetApproxValue(getComplexFloatImag()) << "i";
678
2
    return;
679
1.89k
  case APValue::LValue: {
680
1.89k
    bool IsReference = Ty->isReferenceType();
681
1.89k
    QualType InnerTy
682
1.89k
      = IsReference ? 
Ty.getNonReferenceType()797
:
Ty->getPointeeType()1.09k
;
683
1.89k
    if (InnerTy.isNull())
684
821
      InnerTy = Ty;
685
686
1.89k
    LValueBase Base = getLValueBase();
687
1.89k
    if (!Base) {
688
103
      if (isNullPointer()) {
689
87
        Out << (Policy.Nullptr ? "nullptr" : 
"0"0
);
690
87
      } else 
if (16
IsReference16
) {
691
0
        Out << "*(" << InnerTy.stream(Policy) << "*)"
692
0
            << getLValueOffset().getQuantity();
693
16
      } else {
694
16
        Out << "(" << Ty.stream(Policy) << ")"
695
16
            << getLValueOffset().getQuantity();
696
16
      }
697
103
      return;
698
103
    }
699
700
1.79k
    if (!hasLValuePath()) {
701
      // No lvalue path: just print the offset.
702
2
      CharUnits O = getLValueOffset();
703
2
      CharUnits S = Ctx ? Ctx->getTypeSizeInCharsIfKnown(InnerTy).getValueOr(
704
2
                              CharUnits::Zero())
705
2
                        : 
CharUnits::Zero()0
;
706
2
      if (!O.isZero()) {
707
2
        if (IsReference)
708
0
          Out << "*(";
709
2
        if (S.isZero() || O % S) {
710
2
          Out << "(char*)";
711
2
          S = CharUnits::One();
712
2
        }
713
2
        Out << '&';
714
2
      } else 
if (0
!IsReference0
) {
715
0
        Out << '&';
716
0
      }
717
718
2
      if (const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>())
719
2
        Out << *VD;
720
0
      else if (TypeInfoLValue TI = Base.dyn_cast<TypeInfoLValue>()) {
721
0
        TI.print(Out, Policy);
722
0
      } else if (DynamicAllocLValue DA = Base.dyn_cast<DynamicAllocLValue>()) {
723
0
        Out << "{*new "
724
0
            << Base.getDynamicAllocType().stream(Policy) << "#"
725
0
            << DA.getIndex() << "}";
726
0
      } else {
727
0
        assert(Base.get<const Expr *>() != nullptr &&
728
0
               "Expecting non-null Expr");
729
0
        Base.get<const Expr*>()->printPretty(Out, nullptr, Policy);
730
0
      }
731
732
2
      if (!O.isZero()) {
733
2
        Out << " + " << (O / S);
734
2
        if (IsReference)
735
0
          Out << ')';
736
2
      }
737
2
      return;
738
2
    }
739
740
    // We have an lvalue path. Print it out nicely.
741
1.79k
    if (!IsReference)
742
994
      Out << '&';
743
797
    else if (isLValueOnePastTheEnd())
744
0
      Out << "*(&";
745
746
1.79k
    QualType ElemTy = Base.getType();
747
1.79k
    if (const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>()) {
748
1.45k
      Out << *VD;
749
1.45k
    } else 
if (TypeInfoLValue 337
TI337
= Base.dyn_cast<TypeInfoLValue>()) {
750
45
      TI.print(Out, Policy);
751
292
    } else if (DynamicAllocLValue DA = Base.dyn_cast<DynamicAllocLValue>()) {
752
17
      Out << "{*new " << Base.getDynamicAllocType().stream(Policy) << "#"
753
17
          << DA.getIndex() << "}";
754
275
    } else {
755
275
      const Expr *E = Base.get<const Expr*>();
756
275
      assert(E != nullptr && "Expecting non-null Expr");
757
0
      E->printPretty(Out, nullptr, Policy);
758
275
    }
759
760
0
    ArrayRef<LValuePathEntry> Path = getLValuePath();
761
1.79k
    const CXXRecordDecl *CastToBase = nullptr;
762
2.03k
    for (unsigned I = 0, N = Path.size(); I != N; 
++I245
) {
763
245
      if (ElemTy->isRecordType()) {
764
        // The lvalue refers to a class type, so the next path entry is a base
765
        // or member.
766
88
        const Decl *BaseOrMember = Path[I].getAsBaseOrMember().getPointer();
767
88
        if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(BaseOrMember)) {
768
54
          CastToBase = RD;
769
          // Leave ElemTy referring to the most-derived class. The actual type
770
          // doesn't matter except for array types.
771
54
        } else {
772
34
          const ValueDecl *VD = cast<ValueDecl>(BaseOrMember);
773
34
          Out << ".";
774
34
          if (CastToBase)
775
4
            Out << *CastToBase << "::";
776
34
          Out << *VD;
777
34
          ElemTy = VD->getType();
778
34
        }
779
157
      } else {
780
        // The lvalue must refer to an array.
781
157
        Out << '[' << Path[I].getAsArrayIndex() << ']';
782
157
        ElemTy = ElemTy->castAsArrayTypeUnsafe()->getElementType();
783
157
      }
784
245
    }
785
786
    // Handle formatting of one-past-the-end lvalues.
787
1.79k
    if (isLValueOnePastTheEnd()) {
788
      // FIXME: If CastToBase is non-0, we should prefix the output with
789
      // "(CastToBase*)".
790
4
      Out << " + 1";
791
4
      if (IsReference)
792
0
        Out << ')';
793
4
    }
794
1.79k
    return;
795
1.79k
  }
796
16
  case APValue::Array: {
797
16
    const ArrayType *AT = Ty->castAsArrayTypeUnsafe();
798
16
    QualType ElemTy = AT->getElementType();
799
16
    Out << '{';
800
16
    if (unsigned N = getArrayInitializedElts()) {
801
12
      getArrayInitializedElt(0).printPretty(Out, Policy, ElemTy, Ctx);
802
46
      for (unsigned I = 1; I != N; 
++I34
) {
803
36
        Out << ", ";
804
36
        if (I == 10) {
805
          // Avoid printing out the entire contents of large arrays.
806
2
          Out << "...";
807
2
          break;
808
2
        }
809
34
        getArrayInitializedElt(I).printPretty(Out, Policy, ElemTy, Ctx);
810
34
      }
811
12
    }
812
16
    Out << '}';
813
16
    return;
814
1.79k
  }
815
56
  case APValue::Struct: {
816
56
    Out << '{';
817
56
    const RecordDecl *RD = Ty->castAs<RecordType>()->getDecl();
818
56
    bool First = true;
819
56
    if (unsigned N = getStructNumBases()) {
820
2
      const CXXRecordDecl *CD = cast<CXXRecordDecl>(RD);
821
2
      CXXRecordDecl::base_class_const_iterator BI = CD->bases_begin();
822
4
      for (unsigned I = 0; I != N; 
++I, ++BI2
) {
823
2
        assert(BI != CD->bases_end());
824
2
        if (!First)
825
0
          Out << ", ";
826
2
        getStructBase(I).printPretty(Out, Policy, BI->getType(), Ctx);
827
2
        First = false;
828
2
      }
829
2
    }
830
56
    for (const auto *FI : RD->fields()) {
831
46
      if (!First)
832
13
        Out << ", ";
833
46
      if (FI->isUnnamedBitfield()) 
continue0
;
834
46
      getStructField(FI->getFieldIndex()).
835
46
        printPretty(Out, Policy, FI->getType(), Ctx);
836
46
      First = false;
837
46
    }
838
56
    Out << '}';
839
56
    return;
840
1.79k
  }
841
11
  case APValue::Union:
842
11
    Out << '{';
843
11
    if (const FieldDecl *FD = getUnionField()) {
844
11
      Out << "." << *FD << " = ";
845
11
      getUnionValue().printPretty(Out, Policy, FD->getType(), Ctx);
846
11
    }
847
11
    Out << '}';
848
11
    return;
849
2
  case APValue::MemberPointer:
850
    // FIXME: This is not enough to unambiguously identify the member in a
851
    // multiple-inheritance scenario.
852
2
    if (const ValueDecl *VD = getMemberPointerDecl()) {
853
2
      Out << '&' << *cast<CXXRecordDecl>(VD->getDeclContext()) << "::" << *VD;
854
2
      return;
855
2
    }
856
0
    Out << "0";
857
0
    return;
858
2
  case APValue::AddrLabelDiff:
859
2
    Out << "&&" << getAddrLabelDiffLHS()->getLabel()->getName();
860
2
    Out << " - ";
861
2
    Out << "&&" << getAddrLabelDiffRHS()->getLabel()->getName();
862
2
    return;
863
3.42k
  }
864
0
  llvm_unreachable("Unknown APValue kind!");
865
0
}
866
867
566
std::string APValue::getAsString(const ASTContext &Ctx, QualType Ty) const {
868
566
  std::string Result;
869
566
  llvm::raw_string_ostream Out(Result);
870
566
  printPretty(Out, Ctx, Ty);
871
566
  Out.flush();
872
566
  return Result;
873
566
}
874
875
bool APValue::toIntegralConstant(APSInt &Result, QualType SrcTy,
876
1.06k
                                 const ASTContext &Ctx) const {
877
1.06k
  if (isInt()) {
878
249
    Result = getInt();
879
249
    return true;
880
249
  }
881
882
818
  if (isLValue() && 
isNullPointer()817
) {
883
391
    Result = Ctx.MakeIntValue(Ctx.getTargetNullPointerValue(SrcTy), SrcTy);
884
391
    return true;
885
391
  }
886
887
427
  if (isLValue() && 
!getLValueBase()426
) {
888
424
    Result = Ctx.MakeIntValue(getLValueOffset().getQuantity(), SrcTy);
889
424
    return true;
890
424
  }
891
892
3
  return false;
893
427
}
894
895
2.20M
const APValue::LValueBase APValue::getLValueBase() const {
896
2.20M
  assert(isLValue() && "Invalid accessor");
897
0
  return ((const LV *)(const void *)&Data)->Base;
898
2.20M
}
899
900
749k
bool APValue::isLValueOnePastTheEnd() const {
901
749k
  assert(isLValue() && "Invalid accessor");
902
0
  return ((const LV *)(const void *)&Data)->IsOnePastTheEnd;
903
749k
}
904
905
759k
CharUnits &APValue::getLValueOffset() {
906
759k
  assert(isLValue() && "Invalid accessor");
907
0
  return ((LV *)(void *)&Data)->Offset;
908
759k
}
909
910
2.20M
bool APValue::hasLValuePath() const {
911
2.20M
  assert(isLValue() && "Invalid accessor");
912
0
  return ((const LV *)(const char *)&Data)->hasPath();
913
2.20M
}
914
915
1.44M
ArrayRef<APValue::LValuePathEntry> APValue::getLValuePath() const {
916
1.44M
  assert(isLValue() && hasLValuePath() && "Invalid accessor");
917
0
  const LV &LVal = *((const LV *)(const char *)&Data);
918
1.44M
  return llvm::makeArrayRef(LVal.getPath(), LVal.PathLength);
919
1.44M
}
920
921
0
unsigned APValue::getLValueCallIndex() const {
922
0
  assert(isLValue() && "Invalid accessor");
923
0
  return ((const LV *)(const char *)&Data)->Base.getCallIndex();
924
0
}
925
926
0
unsigned APValue::getLValueVersion() const {
927
0
  assert(isLValue() && "Invalid accessor");
928
0
  return ((const LV *)(const char *)&Data)->Base.getVersion();
929
0
}
930
931
753k
bool APValue::isNullPointer() const {
932
753k
  assert(isLValue() && "Invalid usage");
933
0
  return ((const LV *)(const char *)&Data)->IsNullPtr;
934
753k
}
935
936
void APValue::setLValue(LValueBase B, const CharUnits &O, NoLValuePath,
937
7.03k
                        bool IsNullPtr) {
938
7.03k
  assert(isLValue() && "Invalid accessor");
939
0
  LV &LVal = *((LV *)(char *)&Data);
940
7.03k
  LVal.Base = B;
941
7.03k
  LVal.IsOnePastTheEnd = false;
942
7.03k
  LVal.Offset = O;
943
7.03k
  LVal.resizePath((unsigned)-1);
944
7.03k
  LVal.IsNullPtr = IsNullPtr;
945
7.03k
}
946
947
MutableArrayRef<APValue::LValuePathEntry>
948
APValue::setLValueUninit(LValueBase B, const CharUnits &O, unsigned Size,
949
1.25M
                         bool IsOnePastTheEnd, bool IsNullPtr) {
950
1.25M
  assert(isLValue() && "Invalid accessor");
951
0
  LV &LVal = *((LV *)(char *)&Data);
952
1.25M
  LVal.Base = B;
953
1.25M
  LVal.IsOnePastTheEnd = IsOnePastTheEnd;
954
1.25M
  LVal.Offset = O;
955
1.25M
  LVal.IsNullPtr = IsNullPtr;
956
1.25M
  LVal.resizePath(Size);
957
1.25M
  return {LVal.getPath(), Size};
958
1.25M
}
959
960
void APValue::setLValue(LValueBase B, const CharUnits &O,
961
                        ArrayRef<LValuePathEntry> Path, bool IsOnePastTheEnd,
962
1.25M
                        bool IsNullPtr) {
963
1.25M
  MutableArrayRef<APValue::LValuePathEntry> InternalPath =
964
1.25M
      setLValueUninit(B, O, Path.size(), IsOnePastTheEnd, IsNullPtr);
965
1.25M
  if (Path.size()) {
966
74.3k
    memcpy(InternalPath.data(), Path.data(),
967
74.3k
           Path.size() * sizeof(LValuePathEntry));
968
74.3k
  }
969
1.25M
}
970
971
3.01k
void APValue::setUnion(const FieldDecl *Field, const APValue &Value) {
972
3.01k
  assert(isUnion() && "Invalid accessor");
973
0
  ((UnionData *)(char *)&Data)->Field =
974
3.01k
      Field ? 
Field->getCanonicalDecl()2.28k
:
nullptr733
;
975
3.01k
  *((UnionData *)(char *)&Data)->Value = Value;
976
3.01k
}
977
978
2.97k
const ValueDecl *APValue::getMemberPointerDecl() const {
979
2.97k
  assert(isMemberPointer() && "Invalid accessor");
980
0
  const MemberPointerData &MPD =
981
2.97k
      *((const MemberPointerData *)(const char *)&Data);
982
2.97k
  return MPD.MemberAndIsDerivedMember.getPointer();
983
2.97k
}
984
985
950
bool APValue::isMemberPointerToDerivedMember() const {
986
950
  assert(isMemberPointer() && "Invalid accessor");
987
0
  const MemberPointerData &MPD =
988
950
      *((const MemberPointerData *)(const char *)&Data);
989
950
  return MPD.MemberAndIsDerivedMember.getInt();
990
950
}
991
992
1.08k
ArrayRef<const CXXRecordDecl*> APValue::getMemberPointerPath() const {
993
1.08k
  assert(isMemberPointer() && "Invalid accessor");
994
0
  const MemberPointerData &MPD =
995
1.08k
      *((const MemberPointerData *)(const char *)&Data);
996
1.08k
  return llvm::makeArrayRef(MPD.getPath(), MPD.PathLength);
997
1.08k
}
998
999
1.26M
void APValue::MakeLValue() {
1000
1.26M
  assert(isAbsent() && "Bad state change");
1001
0
  static_assert(sizeof(LV) <= DataSize, "LV too big");
1002
1.26M
  new ((void *)(char *)&Data) LV();
1003
1.26M
  Kind = LValue;
1004
1.26M
}
1005
1006
17.6k
void APValue::MakeArray(unsigned InitElts, unsigned Size) {
1007
17.6k
  assert(isAbsent() && "Bad state change");
1008
0
  new ((void *)(char *)&Data) Arr(InitElts, Size);
1009
17.6k
  Kind = Array;
1010
17.6k
}
1011
1012
MutableArrayRef<APValue::LValuePathEntry>
1013
setLValueUninit(APValue::LValueBase B, const CharUnits &O, unsigned Size,
1014
                bool OnePastTheEnd, bool IsNullPtr);
1015
1016
MutableArrayRef<const CXXRecordDecl *>
1017
APValue::setMemberPointerUninit(const ValueDecl *Member, bool IsDerivedMember,
1018
2.12k
                                unsigned Size) {
1019
2.12k
  assert(isAbsent() && "Bad state change");
1020
0
  MemberPointerData *MPD = new ((void *)(char *)&Data) MemberPointerData;
1021
2.12k
  Kind = MemberPointer;
1022
2.12k
  MPD->MemberAndIsDerivedMember.setPointer(
1023
2.12k
      Member ? 
cast<ValueDecl>(Member->getCanonicalDecl())1.82k
:
nullptr302
);
1024
2.12k
  MPD->MemberAndIsDerivedMember.setInt(IsDerivedMember);
1025
2.12k
  MPD->resizePath(Size);
1026
2.12k
  return {MPD->getPath(), MPD->PathLength};
1027
2.12k
}
1028
1029
void APValue::MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember,
1030
2.12k
                                ArrayRef<const CXXRecordDecl *> Path) {
1031
2.12k
  MutableArrayRef<const CXXRecordDecl *> InternalPath =
1032
2.12k
      setMemberPointerUninit(Member, IsDerivedMember, Path.size());
1033
3.62k
  for (unsigned I = 0; I != Path.size(); 
++I1.49k
)
1034
1.49k
    InternalPath[I] = Path[I]->getCanonicalDecl();
1035
2.12k
}
1036
1037
LinkageInfo LinkageComputer::getLVForValue(const APValue &V,
1038
2.65k
                                           LVComputationKind computation) {
1039
2.65k
  LinkageInfo LV = LinkageInfo::external();
1040
1041
2.65k
  auto MergeLV = [&](LinkageInfo MergeLV) {
1042
2.11k
    LV.merge(MergeLV);
1043
2.11k
    return LV.getLinkage() == InternalLinkage;
1044
2.11k
  };
1045
2.65k
  auto Merge = [&](const APValue &V) {
1046
1.99k
    return MergeLV(getLVForValue(V, computation));
1047
1.99k
  };
1048
1049
2.65k
  switch (V.getKind()) {
1050
120
  case APValue::None:
1051
120
  case APValue::Indeterminate:
1052
1.08k
  case APValue::Int:
1053
1.25k
  case APValue::Float:
1054
1.25k
  case APValue::FixedPoint:
1055
1.33k
  case APValue::ComplexInt:
1056
1.41k
  case APValue::ComplexFloat:
1057
1.52k
  case APValue::Vector:
1058
1.52k
    break;
1059
1060
0
  case APValue::AddrLabelDiff:
1061
    // Even for an inline function, it's not reasonable to treat a difference
1062
    // between the addresses of labels as an external value.
1063
0
    return LinkageInfo::internal();
1064
1065
720
  case APValue::Struct: {
1066
820
    for (unsigned I = 0, N = V.getStructNumBases(); I != N; 
++I100
)
1067
100
      if (Merge(V.getStructBase(I)))
1068
0
        break;
1069
2.19k
    for (unsigned I = 0, N = V.getStructNumFields(); I != N; 
++I1.47k
)
1070
1.47k
      if (Merge(V.getStructField(I)))
1071
0
        break;
1072
720
    break;
1073
1.41k
  }
1074
1075
108
  case APValue::Union:
1076
108
    if (V.getUnionField())
1077
68
      Merge(V.getUnionValue());
1078
108
    break;
1079
1080
114
  case APValue::Array: {
1081
410
    for (unsigned I = 0, N = V.getArrayInitializedElts(); I != N; 
++I296
)
1082
296
      if (Merge(V.getArrayInitializedElt(I)))
1083
0
        break;
1084
114
    if (V.hasArrayFiller())
1085
60
      Merge(V.getArrayFiller());
1086
114
    break;
1087
1.41k
  }
1088
1089
138
  case APValue::LValue: {
1090
138
    if (!V.getLValueBase()) {
1091
      // Null or absolute address: this is external.
1092
88
    } else if (const auto *VD =
1093
88
                   V.getLValueBase().dyn_cast<const ValueDecl *>()) {
1094
88
      if (VD && MergeLV(getLVForDecl(VD, computation)))
1095
0
        break;
1096
88
    } else 
if (const auto 0
TI0
= V.getLValueBase().dyn_cast<TypeInfoLValue>()) {
1097
0
      if (MergeLV(getLVForType(*TI.getType(), computation)))
1098
0
        break;
1099
0
    } else if (const Expr *E = V.getLValueBase().dyn_cast<const Expr *>()) {
1100
      // Almost all expression bases are internal. The exception is
1101
      // lifetime-extended temporaries.
1102
      // FIXME: These should be modeled as having the
1103
      // LifetimeExtendedTemporaryDecl itself as the base.
1104
      // FIXME: If we permit Objective-C object literals in template arguments,
1105
      // they should not imply internal linkage.
1106
0
      auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E);
1107
0
      if (!MTE || MTE->getStorageDuration() == SD_FullExpression)
1108
0
        return LinkageInfo::internal();
1109
0
      if (MergeLV(getLVForDecl(MTE->getExtendingDecl(), computation)))
1110
0
        break;
1111
0
    } else {
1112
0
      assert(V.getLValueBase().is<DynamicAllocLValue>() &&
1113
0
             "unexpected LValueBase kind");
1114
0
      return LinkageInfo::internal();
1115
0
    }
1116
    // The lvalue path doesn't matter: pointers to all subobjects always have
1117
    // the same visibility as pointers to the complete object.
1118
138
    break;
1119
138
  }
1120
1121
138
  case APValue::MemberPointer:
1122
58
    if (const NamedDecl *D = V.getMemberPointerDecl())
1123
33
      MergeLV(getLVForDecl(D, computation));
1124
    // Note that we could have a base-to-derived conversion here to a member of
1125
    // a derived class with less linkage/visibility. That's covered by the
1126
    // linkage and visibility of the value's type.
1127
58
    break;
1128
2.65k
  }
1129
1130
2.65k
  return LV;
1131
2.65k
}