Coverage Report

Created: 2021-08-24 07:12

/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.36k
    : 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.9M
    : Ptr(P ? cast<ValueDecl>(P->getCanonicalDecl()) : nullptr), Local{I, V} {}
44
APValue::LValueBase::LValueBase(const Expr *P, unsigned I, unsigned V)
45
2.01M
    : Ptr(P), Local{I, V} {}
46
47
APValue::LValueBase APValue::LValueBase::getDynamicAlloc(DynamicAllocLValue LV,
48
843
                                                         QualType Type) {
49
843
  LValueBase Base;
50
843
  Base.Ptr = LV;
51
843
  Base.DynamicAllocType = Type.getAsOpaquePtr();
52
843
  return Base;
53
843
}
54
55
APValue::LValueBase APValue::LValueBase::getTypeInfo(TypeInfoLValue LV,
56
1.36k
                                                     QualType TypeInfo) {
57
1.36k
  LValueBase Base;
58
1.36k
  Base.Ptr = LV;
59
1.36k
  Base.TypeInfoType = TypeInfo.getAsOpaquePtr();
60
1.36k
  return Base;
61
1.36k
}
62
63
19.2M
QualType APValue::LValueBase::getType() const {
64
19.2M
  if (!*this) 
return QualType()20
;
65
19.2M
  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
17.1M
    for (auto *Redecl = cast<ValueDecl>(D->getMostRecentDecl()); Redecl;
74
17.1M
         
Redecl = cast_or_null<ValueDecl>(Redecl->getPreviousDecl())2.48k
) {
75
17.1M
      QualType T = Redecl->getType();
76
17.1M
      if (!T->isIncompleteArrayType())
77
17.1M
        return T;
78
17.1M
    }
79
2.02k
    return D->getType();
80
17.1M
  }
81
82
2.11M
  if (is<TypeInfoLValue>())
83
2.58k
    return getTypeInfoType();
84
85
2.10M
  if (is<DynamicAllocLValue>())
86
6.09k
    return getDynamicAllocType();
87
88
2.10M
  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.10M
  if (const MaterializeTemporaryExpr *MTE =
93
2.10M
          clang::dyn_cast<MaterializeTemporaryExpr>(Base)) {
94
1.98M
    SmallVector<const Expr *, 2> CommaLHSs;
95
1.98M
    SmallVector<SubobjectAdjustment, 2> Adjustments;
96
1.98M
    const Expr *Temp = MTE->getSubExpr();
97
1.98M
    const Expr *Inner = Temp->skipRValueSubobjectAdjustments(CommaLHSs,
98
1.98M
                                                             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
1.98M
    if (!Adjustments.empty())
102
3.43k
      return Inner->getType();
103
1.98M
  }
104
105
2.09M
  return Base->getType();
106
2.10M
}
107
108
10.4M
unsigned APValue::LValueBase::getCallIndex() const {
109
10.4M
  return (is<TypeInfoLValue>() || 
is<DynamicAllocLValue>()10.4M
) ?
03.70k
110
10.4M
                                                            : 
Local.CallIndex10.4M
;
111
10.4M
}
112
113
5.08M
unsigned APValue::LValueBase::getVersion() const {
114
5.08M
  return (is<TypeInfoLValue>() || 
is<DynamicAllocLValue>()5.08M
) ?
052
:
Local.Version5.08M
;
115
5.08M
}
116
117
2.73k
QualType APValue::LValueBase::getTypeInfoType() const {
118
2.73k
  assert(is<TypeInfoLValue>() && "not a type_info lvalue");
119
0
  return QualType::getFromOpaquePtr(TypeInfoType);
120
2.73k
}
121
122
8.75k
QualType APValue::LValueBase::getDynamicAllocType() const {
123
8.75k
  assert(is<DynamicAllocLValue>() && "not a dynamic allocation lvalue");
124
0
  return QualType::getFromOpaquePtr(DynamicAllocType);
125
8.75k
}
126
127
72
void APValue::LValueBase::Profile(llvm::FoldingSetNodeID &ID) const {
128
72
  ID.AddPointer(Ptr.getOpaqueValue());
129
72
  if (is<TypeInfoLValue>() || is<DynamicAllocLValue>())
130
0
    return;
131
72
  ID.AddInteger(Local.CallIndex);
132
72
  ID.AddInteger(Local.Version);
133
72
}
134
135
namespace clang {
136
bool operator==(const APValue::LValueBase &LHS,
137
7.30M
                const APValue::LValueBase &RHS) {
138
7.30M
  if (LHS.Ptr != RHS.Ptr)
139
5.81M
    return false;
140
1.49M
  if (LHS.is<TypeInfoLValue>() || LHS.is<DynamicAllocLValue>())
141
490
    return true;
142
1.49M
  return LHS.Local.CallIndex == RHS.Local.CallIndex &&
143
1.49M
         
LHS.Local.Version == RHS.Local.Version1.49M
;
144
1.49M
}
145
}
146
147
169k
APValue::LValuePathEntry::LValuePathEntry(BaseOrMemberType BaseOrMember) {
148
169k
  if (const Decl *D = BaseOrMember.getPointer())
149
169k
    BaseOrMember.setPointer(D->getCanonicalDecl());
150
169k
  Value = reinterpret_cast<uintptr_t>(BaseOrMember.getOpaqueValue());
151
169k
}
152
153
56
void APValue::LValuePathEntry::Profile(llvm::FoldingSetNodeID &ID) const {
154
56
  ID.AddInteger(Value);
155
56
}
156
157
APValue::LValuePathSerializationHelper::LValuePathSerializationHelper(
158
    ArrayRef<LValuePathEntry> Path, QualType ElemTy)
159
23
    : ElemTy((const void *)ElemTy.getTypePtrOrNull()), Path(Path) {}
160
161
23
QualType APValue::LValuePathSerializationHelper::getType() {
162
23
  return QualType::getFromOpaquePtr(ElemTy);
163
23
}
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
114k
void *APValue::LValueBase::getOpaqueValue() const {
176
114k
  return Ptr.getOpaqueValue();
177
114k
}
178
179
7.68k
bool APValue::LValueBase::isNull() const {
180
7.68k
  return Ptr.isNull();
181
7.68k
}
182
183
28.2M
APValue::LValueBase::operator bool () const {
184
28.2M
  return static_cast<bool>(Ptr);
185
28.2M
}
186
187
clang::APValue::LValueBase
188
173k
llvm::DenseMapInfo<clang::APValue::LValueBase>::getEmptyKey() {
189
173k
  clang::APValue::LValueBase B;
190
173k
  B.Ptr = DenseMapInfo<const ValueDecl*>::getEmptyKey();
191
173k
  return B;
192
173k
}
193
194
clang::APValue::LValueBase
195
153k
llvm::DenseMapInfo<clang::APValue::LValueBase>::getTombstoneKey() {
196
153k
  clang::APValue::LValueBase B;
197
153k
  B.Ptr = DenseMapInfo<const ValueDecl*>::getTombstoneKey();
198
153k
  return B;
199
153k
}
200
201
namespace clang {
202
105k
llvm::hash_code hash_value(const APValue::LValueBase &Base) {
203
105k
  if (Base.is<TypeInfoLValue>() || Base.is<DynamicAllocLValue>())
204
750
    return llvm::hash_value(Base.getOpaqueValue());
205
105k
  return llvm::hash_combine(Base.getOpaqueValue(), Base.getCallIndex(),
206
105k
                            Base.getVersion());
207
105k
}
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.34M
  LV() { PathLength = (unsigned)-1; }
234
1.33M
  ~LV() { resizePath(0); }
235
236
2.67M
  void resizePath(unsigned Length) {
237
2.67M
    if (Length == PathLength)
238
1.26M
      return;
239
1.41M
    if (hasPathPtr())
240
148
      delete [] PathPtr;
241
1.41M
    PathLength = Length;
242
1.41M
    if (hasPathPtr())
243
148
      PathPtr = new LValuePathEntry[Length];
244
1.41M
  }
245
246
8.22M
  bool hasPath() const { return PathLength != (unsigned)-1; }
247
5.78M
  bool hasPathPtr() const { return hasPath() && 
PathLength > InlinePathSpace4.44M
; }
248
249
1.33M
  LValuePathEntry *getPath() { return hasPathPtr() ? 
PathPtr148
:
Path1.33M
; }
250
1.60M
  const LValuePathEntry *getPath() const {
251
1.60M
    return hasPathPtr() ? 
PathPtr343
:
Path1.60M
;
252
1.60M
  }
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.11k
  MemberPointerData() { PathLength = 0; }
272
1.58k
  ~MemberPointerData() { resizePath(0); }
273
274
3.70k
  void resizePath(unsigned Length) {
275
3.70k
    if (Length == PathLength)
276
3.06k
      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.11k
  PathElem *getPath() { return hasPathPtr() ? 
PathPtr91
:
Path2.02k
; }
287
1.09k
  const PathElem *getPath() const {
288
1.09k
    return hasPathPtr() ? 
PathPtr168
:
Path923
;
289
1.09k
  }
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
15.9k
  NumElts(NumElts), ArrSize(Size) {}
297
14.0k
APValue::Arr::~Arr() { delete [] Elts; }
298
299
APValue::StructData::StructData(unsigned NumBases, unsigned NumFields) :
300
  Elts(new APValue[NumBases+NumFields]),
301
63.4k
  NumBases(NumBases), NumFields(NumFields) {}
302
53.4k
APValue::StructData::~StructData() {
303
53.4k
  delete [] Elts;
304
53.4k
}
305
306
2.94k
APValue::UnionData::UnionData() : Field(nullptr), Value(new APValue) {}
307
2.63k
APValue::UnionData::~UnionData () {
308
2.63k
  delete Value;
309
2.63k
}
310
311
9.30M
APValue::APValue(const APValue &RHS) : Kind(None) {
312
9.30M
  switch (RHS.getKind()) {
313
9.37k
  case None:
314
10.5k
  case Indeterminate:
315
10.5k
    Kind = RHS.getKind();
316
10.5k
    break;
317
9.22M
  case Int:
318
9.22M
    MakeInt();
319
9.22M
    setInt(RHS.getInt());
320
9.22M
    break;
321
18.5k
  case Float:
322
18.5k
    MakeFloat();
323
18.5k
    setFloat(RHS.getFloat());
324
18.5k
    break;
325
6
  case FixedPoint: {
326
6
    APFixedPoint FXCopy = RHS.getFixedPoint();
327
6
    MakeFixedPoint(std::move(FXCopy));
328
6
    break;
329
9.37k
  }
330
3.58k
  case Vector:
331
3.58k
    MakeVector();
332
3.58k
    setVector(((const Vec *)(const char *)&RHS.Data)->Elts,
333
3.58k
              RHS.getVectorLength());
334
3.58k
    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.5k
  case LValue:
344
31.5k
    MakeLValue();
345
31.5k
    if (RHS.hasLValuePath())
346
31.1k
      setLValue(RHS.getLValueBase(), RHS.getLValueOffset(), RHS.getLValuePath(),
347
31.1k
                RHS.isLValueOnePastTheEnd(), RHS.isNullPointer());
348
366
    else
349
366
      setLValue(RHS.getLValueBase(), RHS.getLValueOffset(), NoLValuePath(),
350
366
                RHS.isNullPointer());
351
31.5k
    break;
352
1.32k
  case Array:
353
1.32k
    MakeArray(RHS.getArrayInitializedElts(), RHS.getArraySize());
354
6.77k
    for (unsigned I = 0, N = RHS.getArrayInitializedElts(); I != N; 
++I5.45k
)
355
5.45k
      getArrayInitializedElt(I) = RHS.getArrayInitializedElt(I);
356
1.32k
    if (RHS.hasArrayFiller())
357
410
      getArrayFiller() = RHS.getArrayFiller();
358
1.32k
    break;
359
4.65k
  case Struct:
360
4.65k
    MakeStruct(RHS.getStructNumBases(), RHS.getStructNumFields());
361
5.12k
    for (unsigned I = 0, N = RHS.getStructNumBases(); I != N; 
++I470
)
362
470
      getStructBase(I) = RHS.getStructBase(I);
363
11.8k
    for (unsigned I = 0, N = RHS.getStructNumFields(); I != N; 
++I7.16k
)
364
7.16k
      getStructField(I) = RHS.getStructField(I);
365
4.65k
    break;
366
554
  case Union:
367
554
    MakeUnion();
368
554
    setUnion(RHS.getUnionField(), RHS.getUnionValue());
369
554
    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.30M
  }
380
9.30M
}
381
382
94.0k
APValue::APValue(APValue &&RHS) : Kind(RHS.Kind), Data(RHS.Data) {
383
94.0k
  RHS.Kind = None;
384
94.0k
}
385
386
3.50M
APValue &APValue::operator=(const APValue &RHS) {
387
3.50M
  if (this != &RHS)
388
3.50M
    *this = APValue(RHS);
389
3.50M
  return *this;
390
3.50M
}
391
392
35.8M
APValue &APValue::operator=(APValue &&RHS) {
393
35.8M
  if (Kind != None && 
Kind != Indeterminate2.32M
)
394
2.32M
    DestroyDataAndMakeUninit();
395
35.8M
  Kind = RHS.Kind;
396
35.8M
  Data = RHS.Data;
397
35.8M
  RHS.Kind = None;
398
35.8M
  return *this;
399
35.8M
}
400
401
41.2M
void APValue::DestroyDataAndMakeUninit() {
402
41.2M
  if (Kind == Int)
403
39.7M
    ((APSInt *)(char *)&Data)->~APSInt();
404
1.47M
  else if (Kind == Float)
405
61.6k
    ((APFloat *)(char *)&Data)->~APFloat();
406
1.41M
  else if (Kind == FixedPoint)
407
2.90k
    ((APFixedPoint *)(char *)&Data)->~APFixedPoint();
408
1.41M
  else if (Kind == Vector)
409
8.76k
    ((Vec *)(char *)&Data)->~Vec();
410
1.40M
  else if (Kind == ComplexInt)
411
284
    ((ComplexAPSInt *)(char *)&Data)->~ComplexAPSInt();
412
1.40M
  else if (Kind == ComplexFloat)
413
384
    ((ComplexAPFloat *)(char *)&Data)->~ComplexAPFloat();
414
1.40M
  else if (Kind == LValue)
415
1.33M
    ((LV *)(char *)&Data)->~LV();
416
71.7k
  else if (Kind == Array)
417
14.0k
    ((Arr *)(char *)&Data)->~Arr();
418
57.6k
  else if (Kind == Struct)
419
53.4k
    ((StructData *)(char *)&Data)->~StructData();
420
4.27k
  else if (Kind == Union)
421
2.63k
    ((UnionData *)(char *)&Data)->~UnionData();
422
1.64k
  else if (Kind == MemberPointer)
423
1.58k
    ((MemberPointerData *)(char *)&Data)->~MemberPointerData();
424
56
  else if (Kind == AddrLabelDiff)
425
56
    ((AddrLabelDiffData *)(char *)&Data)->~AddrLabelDiffData();
426
41.2M
  Kind = None;
427
41.2M
}
428
429
320k
bool APValue::needsCleanup() const {
430
320k
  switch (getKind()) {
431
3
  case None:
432
3
  case Indeterminate:
433
11
  case AddrLabelDiff:
434
11
    return false;
435
14.8k
  case Struct:
436
15.1k
  case Union:
437
19.8k
  case Array:
438
21.0k
  case Vector:
439
21.0k
    return true;
440
287k
  case Int:
441
287k
    return getInt().needsCleanup();
442
2.00k
  case Float:
443
2.00k
    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.38k
  case LValue:
459
8.38k
    return reinterpret_cast<const LV *>(&Data)->hasPathPtr();
460
539
  case MemberPointer:
461
539
    return reinterpret_cast<const MemberPointerData *>(&Data)->hasPathPtr();
462
320k
  }
463
0
  llvm_unreachable("Unknown APValue kind!");
464
0
}
465
466
12.6M
void APValue::swap(APValue &RHS) {
467
12.6M
  std::swap(Kind, RHS.Kind);
468
12.6M
  std::swap(Data, RHS.Data);
469
12.6M
}
470
471
/// Profile the value of an APInt, excluding its bit-width.
472
994
static void profileIntValue(llvm::FoldingSetNodeID &ID, const llvm::APInt &V) {
473
2.04k
  for (unsigned I = 0, N = V.getBitWidth(); I < N; 
I += 321.04k
)
474
1.04k
    ID.AddInteger((uint32_t)V.extractBitsAsZExtValue(std::min(32u, N - I), I));
475
994
}
476
477
1.71k
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.71k
  ID.AddInteger(Kind);
484
485
1.71k
  switch (Kind) {
486
32
  case None:
487
32
  case Indeterminate:
488
32
    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
428
  case Struct:
496
448
    for (unsigned I = 0, N = getStructNumBases(); I != N; 
++I20
)
497
20
      getStructBase(I).Profile(ID);
498
1.03k
    for (unsigned I = 0, N = getStructNumFields(); I != N; 
++I611
)
499
611
      getStructField(I).Profile(ID);
500
428
    return;
501
502
50
  case Union:
503
50
    if (!getUnionField()) {
504
9
      ID.AddInteger(0);
505
9
      return;
506
9
    }
507
41
    ID.AddInteger(getUnionField()->getFieldIndex() + 1);
508
41
    getUnionValue().Profile(ID);
509
41
    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()83
525
122
                      : 
getArrayInitializedElt(getArrayInitializedElts() - 1)39
)
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
186
    while (true) {
535
186
      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
167
      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
64
      ++NumFillers;
557
64
      --N;
558
64
    }
559
560
    // Emit the remaining elements.
561
383
    for (; N != 0; 
--N261
)
562
261
      getArrayInitializedElt(N - 1).Profile(ID);
563
122
    return;
564
122
  }
565
566
34
  case Vector:
567
133
    for (unsigned I = 0, N = getVectorLength(); I != N; 
++I99
)
568
99
      getVectorElt(I).Profile(ID);
569
34
    return;
570
571
833
  case Int:
572
833
    profileIntValue(ID, getInt());
573
833
    return;
574
575
61
  case Float:
576
61
    profileIntValue(ID, getFloat().bitcastToAPInt());
577
61
    return;
578
579
0
  case FixedPoint:
580
0
    profileIntValue(ID, getFixedPoint().getValue());
581
0
    return;
582
583
25
  case ComplexFloat:
584
25
    profileIntValue(ID, getComplexFloatReal().bitcastToAPInt());
585
25
    profileIntValue(ID, getComplexFloatImag().bitcastToAPInt());
586
25
    return;
587
588
25
  case ComplexInt:
589
25
    profileIntValue(ID, getComplexIntReal());
590
25
    profileIntValue(ID, getComplexIntImag());
591
25
    return;
592
593
72
  case LValue:
594
72
    getLValueBase().Profile(ID);
595
72
    ID.AddInteger(getLValueOffset().getQuantity());
596
72
    ID.AddInteger((isNullPointer() ? 
122
:
050
) |
597
72
                  (isLValueOnePastTheEnd() ? 
22
:
070
) |
598
72
                  (hasLValuePath() ? 
463
:
09
));
599
72
    if (hasLValuePath()) {
600
63
      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
63
      for (LValuePathEntry E : getLValuePath())
605
56
        E.Profile(ID);
606
63
    }
607
72
    return;
608
609
37
  case MemberPointer:
610
37
    ID.AddPointer(getMemberPointerDecl());
611
37
    ID.AddInteger(isMemberPointerToDerivedMember());
612
37
    for (const CXXRecordDecl *D : getMemberPointerPath())
613
9
      ID.AddPointer(D);
614
37
    return;
615
1.71k
  }
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.23k
                          QualType Ty) const {
630
3.23k
  printPretty(Out, Ctx.getPrintingPolicy(), Ty, &Ctx);
631
3.23k
}
632
633
void APValue::printPretty(raw_ostream &Out, const PrintingPolicy &Policy,
634
3.34k
                          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.34k
  if (Ty->isVoidType()) {
638
0
    Out << "void()";
639
0
    return;
640
0
  }
641
642
3.34k
  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.81k
  case APValue::LValue: {
680
1.81k
    bool IsReference = Ty->isReferenceType();
681
1.81k
    QualType InnerTy
682
1.81k
      = IsReference ? 
Ty.getNonReferenceType()794
:
Ty->getPointeeType()1.02k
;
683
1.81k
    if (InnerTy.isNull())
684
805
      InnerTy = Ty;
685
686
1.81k
    LValueBase Base = getLValueBase();
687
1.81k
    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.71k
    if (!hasLValuePath()) {
701
      // No lvalue path: just print the offset.
702
2
      CharUnits O = getLValueOffset();
703
2
      CharUnits S = Ctx ? Ctx->getTypeSizeInChars(InnerTy) : 
CharUnits::Zero()0
;
704
2
      if (!O.isZero()) {
705
2
        if (IsReference)
706
0
          Out << "*(";
707
2
        if (S.isZero() || O % S) {
708
2
          Out << "(char*)";
709
2
          S = CharUnits::One();
710
2
        }
711
2
        Out << '&';
712
2
      } else 
if (0
!IsReference0
) {
713
0
        Out << '&';
714
0
      }
715
716
2
      if (const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>())
717
2
        Out << *VD;
718
0
      else if (TypeInfoLValue TI = Base.dyn_cast<TypeInfoLValue>()) {
719
0
        TI.print(Out, Policy);
720
0
      } else if (DynamicAllocLValue DA = Base.dyn_cast<DynamicAllocLValue>()) {
721
0
        Out << "{*new "
722
0
            << Base.getDynamicAllocType().stream(Policy) << "#"
723
0
            << DA.getIndex() << "}";
724
0
      } else {
725
0
        assert(Base.get<const Expr *>() != nullptr &&
726
0
               "Expecting non-null Expr");
727
0
        Base.get<const Expr*>()->printPretty(Out, nullptr, Policy);
728
0
      }
729
730
2
      if (!O.isZero()) {
731
2
        Out << " + " << (O / S);
732
2
        if (IsReference)
733
0
          Out << ')';
734
2
      }
735
2
      return;
736
2
    }
737
738
    // We have an lvalue path. Print it out nicely.
739
1.71k
    if (!IsReference)
740
918
      Out << '&';
741
794
    else if (isLValueOnePastTheEnd())
742
0
      Out << "*(&";
743
744
1.71k
    QualType ElemTy = Base.getType();
745
1.71k
    if (const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>()) {
746
1.43k
      Out << *VD;
747
1.43k
    } else 
if (TypeInfoLValue 277
TI277
= Base.dyn_cast<TypeInfoLValue>()) {
748
45
      TI.print(Out, Policy);
749
232
    } else if (DynamicAllocLValue DA = Base.dyn_cast<DynamicAllocLValue>()) {
750
17
      Out << "{*new " << Base.getDynamicAllocType().stream(Policy) << "#"
751
17
          << DA.getIndex() << "}";
752
215
    } else {
753
215
      const Expr *E = Base.get<const Expr*>();
754
215
      assert(E != nullptr && "Expecting non-null Expr");
755
0
      E->printPretty(Out, nullptr, Policy);
756
215
    }
757
758
0
    ArrayRef<LValuePathEntry> Path = getLValuePath();
759
1.71k
    const CXXRecordDecl *CastToBase = nullptr;
760
1.89k
    for (unsigned I = 0, N = Path.size(); I != N; 
++I185
) {
761
185
      if (ElemTy->isRecordType()) {
762
        // The lvalue refers to a class type, so the next path entry is a base
763
        // or member.
764
88
        const Decl *BaseOrMember = Path[I].getAsBaseOrMember().getPointer();
765
88
        if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(BaseOrMember)) {
766
54
          CastToBase = RD;
767
          // Leave ElemTy referring to the most-derived class. The actual type
768
          // doesn't matter except for array types.
769
54
        } else {
770
34
          const ValueDecl *VD = cast<ValueDecl>(BaseOrMember);
771
34
          Out << ".";
772
34
          if (CastToBase)
773
4
            Out << *CastToBase << "::";
774
34
          Out << *VD;
775
34
          ElemTy = VD->getType();
776
34
        }
777
97
      } else {
778
        // The lvalue must refer to an array.
779
97
        Out << '[' << Path[I].getAsArrayIndex() << ']';
780
97
        ElemTy = ElemTy->castAsArrayTypeUnsafe()->getElementType();
781
97
      }
782
185
    }
783
784
    // Handle formatting of one-past-the-end lvalues.
785
1.71k
    if (isLValueOnePastTheEnd()) {
786
      // FIXME: If CastToBase is non-0, we should prefix the output with
787
      // "(CastToBase*)".
788
4
      Out << " + 1";
789
4
      if (IsReference)
790
0
        Out << ')';
791
4
    }
792
1.71k
    return;
793
1.71k
  }
794
16
  case APValue::Array: {
795
16
    const ArrayType *AT = Ty->castAsArrayTypeUnsafe();
796
16
    QualType ElemTy = AT->getElementType();
797
16
    Out << '{';
798
16
    if (unsigned N = getArrayInitializedElts()) {
799
12
      getArrayInitializedElt(0).printPretty(Out, Policy, ElemTy, Ctx);
800
46
      for (unsigned I = 1; I != N; 
++I34
) {
801
36
        Out << ", ";
802
36
        if (I == 10) {
803
          // Avoid printing out the entire contents of large arrays.
804
2
          Out << "...";
805
2
          break;
806
2
        }
807
34
        getArrayInitializedElt(I).printPretty(Out, Policy, ElemTy, Ctx);
808
34
      }
809
12
    }
810
16
    Out << '}';
811
16
    return;
812
1.71k
  }
813
56
  case APValue::Struct: {
814
56
    Out << '{';
815
56
    const RecordDecl *RD = Ty->castAs<RecordType>()->getDecl();
816
56
    bool First = true;
817
56
    if (unsigned N = getStructNumBases()) {
818
2
      const CXXRecordDecl *CD = cast<CXXRecordDecl>(RD);
819
2
      CXXRecordDecl::base_class_const_iterator BI = CD->bases_begin();
820
4
      for (unsigned I = 0; I != N; 
++I, ++BI2
) {
821
2
        assert(BI != CD->bases_end());
822
2
        if (!First)
823
0
          Out << ", ";
824
2
        getStructBase(I).printPretty(Out, Policy, BI->getType(), Ctx);
825
2
        First = false;
826
2
      }
827
2
    }
828
56
    for (const auto *FI : RD->fields()) {
829
46
      if (!First)
830
13
        Out << ", ";
831
46
      if (FI->isUnnamedBitfield()) 
continue0
;
832
46
      getStructField(FI->getFieldIndex()).
833
46
        printPretty(Out, Policy, FI->getType(), Ctx);
834
46
      First = false;
835
46
    }
836
56
    Out << '}';
837
56
    return;
838
1.71k
  }
839
11
  case APValue::Union:
840
11
    Out << '{';
841
11
    if (const FieldDecl *FD = getUnionField()) {
842
11
      Out << "." << *FD << " = ";
843
11
      getUnionValue().printPretty(Out, Policy, FD->getType(), Ctx);
844
11
    }
845
11
    Out << '}';
846
11
    return;
847
2
  case APValue::MemberPointer:
848
    // FIXME: This is not enough to unambiguously identify the member in a
849
    // multiple-inheritance scenario.
850
2
    if (const ValueDecl *VD = getMemberPointerDecl()) {
851
2
      Out << '&' << *cast<CXXRecordDecl>(VD->getDeclContext()) << "::" << *VD;
852
2
      return;
853
2
    }
854
0
    Out << "0";
855
0
    return;
856
2
  case APValue::AddrLabelDiff:
857
2
    Out << "&&" << getAddrLabelDiffLHS()->getLabel()->getName();
858
2
    Out << " - ";
859
2
    Out << "&&" << getAddrLabelDiffRHS()->getLabel()->getName();
860
2
    return;
861
3.34k
  }
862
0
  llvm_unreachable("Unknown APValue kind!");
863
0
}
864
865
561
std::string APValue::getAsString(const ASTContext &Ctx, QualType Ty) const {
866
561
  std::string Result;
867
561
  llvm::raw_string_ostream Out(Result);
868
561
  printPretty(Out, Ctx, Ty);
869
561
  Out.flush();
870
561
  return Result;
871
561
}
872
873
bool APValue::toIntegralConstant(APSInt &Result, QualType SrcTy,
874
1.06k
                                 const ASTContext &Ctx) const {
875
1.06k
  if (isInt()) {
876
277
    Result = getInt();
877
277
    return true;
878
277
  }
879
880
789
  if (isLValue() && isNullPointer()) {
881
371
    Result = Ctx.MakeIntValue(Ctx.getTargetNullPointerValue(SrcTy), SrcTy);
882
371
    return true;
883
371
  }
884
885
418
  if (isLValue() && !getLValueBase()) {
886
417
    Result = Ctx.MakeIntValue(getLValueOffset().getQuantity(), SrcTy);
887
417
    return true;
888
417
  }
889
890
1
  return false;
891
418
}
892
893
2.43M
const APValue::LValueBase APValue::getLValueBase() const {
894
2.43M
  assert(isLValue() && "Invalid accessor");
895
0
  return ((const LV *)(const void *)&Data)->Base;
896
2.43M
}
897
898
825k
bool APValue::isLValueOnePastTheEnd() const {
899
825k
  assert(isLValue() && "Invalid accessor");
900
0
  return ((const LV *)(const void *)&Data)->IsOnePastTheEnd;
901
825k
}
902
903
835k
CharUnits &APValue::getLValueOffset() {
904
835k
  assert(isLValue() && "Invalid accessor");
905
0
  return ((LV *)(void *)&Data)->Offset;
906
835k
}
907
908
2.43M
bool APValue::hasLValuePath() const {
909
2.43M
  assert(isLValue() && "Invalid accessor");
910
0
  return ((const LV *)(const char *)&Data)->hasPath();
911
2.43M
}
912
913
1.60M
ArrayRef<APValue::LValuePathEntry> APValue::getLValuePath() const {
914
1.60M
  assert(isLValue() && hasLValuePath() && "Invalid accessor");
915
0
  const LV &LVal = *((const LV *)(const char *)&Data);
916
1.60M
  return llvm::makeArrayRef(LVal.getPath(), LVal.PathLength);
917
1.60M
}
918
919
0
unsigned APValue::getLValueCallIndex() const {
920
0
  assert(isLValue() && "Invalid accessor");
921
0
  return ((const LV *)(const char *)&Data)->Base.getCallIndex();
922
0
}
923
924
0
unsigned APValue::getLValueVersion() const {
925
0
  assert(isLValue() && "Invalid accessor");
926
0
  return ((const LV *)(const char *)&Data)->Base.getVersion();
927
0
}
928
929
829k
bool APValue::isNullPointer() const {
930
829k
  assert(isLValue() && "Invalid usage");
931
0
  return ((const LV *)(const char *)&Data)->IsNullPtr;
932
829k
}
933
934
void APValue::setLValue(LValueBase B, const CharUnits &O, NoLValuePath,
935
6.52k
                        bool IsNullPtr) {
936
6.52k
  assert(isLValue() && "Invalid accessor");
937
0
  LV &LVal = *((LV *)(char *)&Data);
938
6.52k
  LVal.Base = B;
939
6.52k
  LVal.IsOnePastTheEnd = false;
940
6.52k
  LVal.Offset = O;
941
6.52k
  LVal.resizePath((unsigned)-1);
942
6.52k
  LVal.IsNullPtr = IsNullPtr;
943
6.52k
}
944
945
MutableArrayRef<APValue::LValuePathEntry>
946
APValue::setLValueUninit(LValueBase B, const CharUnits &O, unsigned Size,
947
1.33M
                         bool IsOnePastTheEnd, bool IsNullPtr) {
948
1.33M
  assert(isLValue() && "Invalid accessor");
949
0
  LV &LVal = *((LV *)(char *)&Data);
950
1.33M
  LVal.Base = B;
951
1.33M
  LVal.IsOnePastTheEnd = IsOnePastTheEnd;
952
1.33M
  LVal.Offset = O;
953
1.33M
  LVal.IsNullPtr = IsNullPtr;
954
1.33M
  LVal.resizePath(Size);
955
1.33M
  return {LVal.getPath(), Size};
956
1.33M
}
957
958
void APValue::setLValue(LValueBase B, const CharUnits &O,
959
                        ArrayRef<LValuePathEntry> Path, bool IsOnePastTheEnd,
960
1.33M
                        bool IsNullPtr) {
961
1.33M
  MutableArrayRef<APValue::LValuePathEntry> InternalPath =
962
1.33M
      setLValueUninit(B, O, Path.size(), IsOnePastTheEnd, IsNullPtr);
963
1.33M
  if (Path.size()) {
964
75.0k
    memcpy(InternalPath.data(), Path.data(),
965
75.0k
           Path.size() * sizeof(LValuePathEntry));
966
75.0k
  }
967
1.33M
}
968
969
3.01k
void APValue::setUnion(const FieldDecl *Field, const APValue &Value) {
970
3.01k
  assert(isUnion() && "Invalid accessor");
971
0
  ((UnionData *)(char *)&Data)->Field =
972
3.01k
      Field ? 
Field->getCanonicalDecl()2.26k
:
nullptr748
;
973
3.01k
  *((UnionData *)(char *)&Data)->Value = Value;
974
3.01k
}
975
976
2.95k
const ValueDecl *APValue::getMemberPointerDecl() const {
977
2.95k
  assert(isMemberPointer() && "Invalid accessor");
978
0
  const MemberPointerData &MPD =
979
2.95k
      *((const MemberPointerData *)(const char *)&Data);
980
2.95k
  return MPD.MemberAndIsDerivedMember.getPointer();
981
2.95k
}
982
983
954
bool APValue::isMemberPointerToDerivedMember() const {
984
954
  assert(isMemberPointer() && "Invalid accessor");
985
0
  const MemberPointerData &MPD =
986
954
      *((const MemberPointerData *)(const char *)&Data);
987
954
  return MPD.MemberAndIsDerivedMember.getInt();
988
954
}
989
990
1.09k
ArrayRef<const CXXRecordDecl*> APValue::getMemberPointerPath() const {
991
1.09k
  assert(isMemberPointer() && "Invalid accessor");
992
0
  const MemberPointerData &MPD =
993
1.09k
      *((const MemberPointerData *)(const char *)&Data);
994
1.09k
  return llvm::makeArrayRef(MPD.getPath(), MPD.PathLength);
995
1.09k
}
996
997
1.34M
void APValue::MakeLValue() {
998
1.34M
  assert(isAbsent() && "Bad state change");
999
0
  static_assert(sizeof(LV) <= DataSize, "LV too big");
1000
1.34M
  new ((void *)(char *)&Data) LV();
1001
1.34M
  Kind = LValue;
1002
1.34M
}
1003
1004
15.9k
void APValue::MakeArray(unsigned InitElts, unsigned Size) {
1005
15.9k
  assert(isAbsent() && "Bad state change");
1006
0
  new ((void *)(char *)&Data) Arr(InitElts, Size);
1007
15.9k
  Kind = Array;
1008
15.9k
}
1009
1010
MutableArrayRef<APValue::LValuePathEntry>
1011
setLValueUninit(APValue::LValueBase B, const CharUnits &O, unsigned Size,
1012
                bool OnePastTheEnd, bool IsNullPtr);
1013
1014
MutableArrayRef<const CXXRecordDecl *>
1015
APValue::setMemberPointerUninit(const ValueDecl *Member, bool IsDerivedMember,
1016
2.11k
                                unsigned Size) {
1017
2.11k
  assert(isAbsent() && "Bad state change");
1018
0
  MemberPointerData *MPD = new ((void *)(char *)&Data) MemberPointerData;
1019
2.11k
  Kind = MemberPointer;
1020
2.11k
  MPD->MemberAndIsDerivedMember.setPointer(
1021
2.11k
      Member ? 
cast<ValueDecl>(Member->getCanonicalDecl())1.81k
:
nullptr299
);
1022
2.11k
  MPD->MemberAndIsDerivedMember.setInt(IsDerivedMember);
1023
2.11k
  MPD->resizePath(Size);
1024
2.11k
  return {MPD->getPath(), MPD->PathLength};
1025
2.11k
}
1026
1027
void APValue::MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember,
1028
2.11k
                                ArrayRef<const CXXRecordDecl *> Path) {
1029
2.11k
  MutableArrayRef<const CXXRecordDecl *> InternalPath =
1030
2.11k
      setMemberPointerUninit(Member, IsDerivedMember, Path.size());
1031
3.61k
  for (unsigned I = 0; I != Path.size(); 
++I1.49k
)
1032
1.49k
    InternalPath[I] = Path[I]->getCanonicalDecl();
1033
2.11k
}
1034
1035
LinkageInfo LinkageComputer::getLVForValue(const APValue &V,
1036
2.65k
                                           LVComputationKind computation) {
1037
2.65k
  LinkageInfo LV = LinkageInfo::external();
1038
1039
2.65k
  auto MergeLV = [&](LinkageInfo MergeLV) {
1040
2.11k
    LV.merge(MergeLV);
1041
2.11k
    return LV.getLinkage() == InternalLinkage;
1042
2.11k
  };
1043
2.65k
  auto Merge = [&](const APValue &V) {
1044
1.99k
    return MergeLV(getLVForValue(V, computation));
1045
1.99k
  };
1046
1047
2.65k
  switch (V.getKind()) {
1048
120
  case APValue::None:
1049
120
  case APValue::Indeterminate:
1050
1.08k
  case APValue::Int:
1051
1.25k
  case APValue::Float:
1052
1.25k
  case APValue::FixedPoint:
1053
1.33k
  case APValue::ComplexInt:
1054
1.41k
  case APValue::ComplexFloat:
1055
1.52k
  case APValue::Vector:
1056
1.52k
    break;
1057
1058
0
  case APValue::AddrLabelDiff:
1059
    // Even for an inline function, it's not reasonable to treat a difference
1060
    // between the addresses of labels as an external value.
1061
0
    return LinkageInfo::internal();
1062
1063
720
  case APValue::Struct: {
1064
820
    for (unsigned I = 0, N = V.getStructNumBases(); I != N; 
++I100
)
1065
100
      if (Merge(V.getStructBase(I)))
1066
0
        break;
1067
2.19k
    for (unsigned I = 0, N = V.getStructNumFields(); I != N; 
++I1.47k
)
1068
1.47k
      if (Merge(V.getStructField(I)))
1069
0
        break;
1070
720
    break;
1071
1.41k
  }
1072
1073
108
  case APValue::Union:
1074
108
    if (V.getUnionField())
1075
68
      Merge(V.getUnionValue());
1076
108
    break;
1077
1078
114
  case APValue::Array: {
1079
410
    for (unsigned I = 0, N = V.getArrayInitializedElts(); I != N; 
++I296
)
1080
296
      if (Merge(V.getArrayInitializedElt(I)))
1081
0
        break;
1082
114
    if (V.hasArrayFiller())
1083
60
      Merge(V.getArrayFiller());
1084
114
    break;
1085
1.41k
  }
1086
1087
138
  case APValue::LValue: {
1088
138
    if (!V.getLValueBase()) {
1089
      // Null or absolute address: this is external.
1090
88
    } else if (const auto *VD =
1091
88
                   V.getLValueBase().dyn_cast<const ValueDecl *>()) {
1092
88
      if (VD && MergeLV(getLVForDecl(VD, computation)))
1093
0
        break;
1094
88
    } else 
if (const auto 0
TI0
= V.getLValueBase().dyn_cast<TypeInfoLValue>()) {
1095
0
      if (MergeLV(getLVForType(*TI.getType(), computation)))
1096
0
        break;
1097
0
    } else if (const Expr *E = V.getLValueBase().dyn_cast<const Expr *>()) {
1098
      // Almost all expression bases are internal. The exception is
1099
      // lifetime-extended temporaries.
1100
      // FIXME: These should be modeled as having the
1101
      // LifetimeExtendedTemporaryDecl itself as the base.
1102
      // FIXME: If we permit Objective-C object literals in template arguments,
1103
      // they should not imply internal linkage.
1104
0
      auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E);
1105
0
      if (!MTE || MTE->getStorageDuration() == SD_FullExpression)
1106
0
        return LinkageInfo::internal();
1107
0
      if (MergeLV(getLVForDecl(MTE->getExtendingDecl(), computation)))
1108
0
        break;
1109
0
    } else {
1110
0
      assert(V.getLValueBase().is<DynamicAllocLValue>() &&
1111
0
             "unexpected LValueBase kind");
1112
0
      return LinkageInfo::internal();
1113
0
    }
1114
    // The lvalue path doesn't matter: pointers to all subobjects always have
1115
    // the same visibility as pointers to the complete object.
1116
138
    break;
1117
138
  }
1118
1119
138
  case APValue::MemberPointer:
1120
58
    if (const NamedDecl *D = V.getMemberPointerDecl())
1121
33
      MergeLV(getLVForDecl(D, computation));
1122
    // Note that we could have a base-to-derived conversion here to a member of
1123
    // a derived class with less linkage/visibility. That's covered by the
1124
    // linkage and visibility of the value's type.
1125
58
    break;
1126
2.65k
  }
1127
1128
2.65k
  return LV;
1129
2.65k
}