Coverage Report

Created: 2021-01-26 06:56

/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.33k
    : 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.7M
    : Ptr(P ? cast<ValueDecl>(P->getCanonicalDecl()) : nullptr), Local{I, V} {}
44
APValue::LValueBase::LValueBase(const Expr *P, unsigned I, unsigned V)
45
1.98M
    : Ptr(P), Local{I, V} {}
46
47
APValue::LValueBase APValue::LValueBase::getDynamicAlloc(DynamicAllocLValue LV,
48
822
                                                         QualType Type) {
49
822
  LValueBase Base;
50
822
  Base.Ptr = LV;
51
822
  Base.DynamicAllocType = Type.getAsOpaquePtr();
52
822
  return Base;
53
822
}
54
55
APValue::LValueBase APValue::LValueBase::getTypeInfo(TypeInfoLValue LV,
56
1.33k
                                                     QualType TypeInfo) {
57
1.33k
  LValueBase Base;
58
1.33k
  Base.Ptr = LV;
59
1.33k
  Base.TypeInfoType = TypeInfo.getAsOpaquePtr();
60
1.33k
  return Base;
61
1.33k
}
62
63
18.0M
QualType APValue::LValueBase::getType() const {
64
18.0M
  if (!*this) 
return QualType()6
;
65
18.0M
  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
15.9M
    for (auto *Redecl = cast<ValueDecl>(D->getMostRecentDecl()); Redecl;
74
15.9M
         
Redecl = cast_or_null<ValueDecl>(Redecl->getPreviousDecl())2.36k
) {
75
15.9M
      QualType T = Redecl->getType();
76
15.9M
      if (!T->isIncompleteArrayType())
77
15.9M
        return T;
78
15.9M
    }
79
1.91k
    return D->getType();
80
2.08M
  }
81
82
2.08M
  if (is<TypeInfoLValue>())
83
2.53k
    return getTypeInfoType();
84
85
2.08M
  if (is<DynamicAllocLValue>())
86
5.99k
    return getDynamicAllocType();
87
88
2.07M
  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.07M
  if (const MaterializeTemporaryExpr *MTE =
93
1.95M
          clang::dyn_cast<MaterializeTemporaryExpr>(Base)) {
94
1.95M
    SmallVector<const Expr *, 2> CommaLHSs;
95
1.95M
    SmallVector<SubobjectAdjustment, 2> Adjustments;
96
1.95M
    const Expr *Temp = MTE->getSubExpr();
97
1.95M
    const Expr *Inner = Temp->skipRValueSubobjectAdjustments(CommaLHSs,
98
1.95M
                                                             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.95M
    if (!Adjustments.empty())
102
3.18k
      return Inner->getType();
103
2.07M
  }
104
105
2.07M
  return Base->getType();
106
2.07M
}
107
108
9.78M
unsigned APValue::LValueBase::getCallIndex() const {
109
9.78M
  return (is<TypeInfoLValue>() || 
is<DynamicAllocLValue>()9.77M
) ?
03.61k
110
9.77M
                                                            : Local.CallIndex;
111
9.78M
}
112
113
4.71M
unsigned APValue::LValueBase::getVersion() const {
114
4.71M
  return (is<TypeInfoLValue>() || 
is<DynamicAllocLValue>()4.71M
) ?
052
:
Local.Version4.71M
;
115
4.71M
}
116
117
2.67k
QualType APValue::LValueBase::getTypeInfoType() const {
118
2.67k
  assert(is<TypeInfoLValue>() && "not a type_info lvalue");
119
2.67k
  return QualType::getFromOpaquePtr(TypeInfoType);
120
2.67k
}
121
122
8.60k
QualType APValue::LValueBase::getDynamicAllocType() const {
123
8.60k
  assert(is<DynamicAllocLValue>() && "not a dynamic allocation lvalue");
124
8.60k
  return QualType::getFromOpaquePtr(DynamicAllocType);
125
8.60k
}
126
127
69
void APValue::LValueBase::Profile(llvm::FoldingSetNodeID &ID) const {
128
69
  ID.AddPointer(Ptr.getOpaqueValue());
129
69
  if (is<TypeInfoLValue>() || is<DynamicAllocLValue>())
130
0
    return;
131
69
  ID.AddInteger(Local.CallIndex);
132
69
  ID.AddInteger(Local.Version);
133
69
}
134
135
namespace clang {
136
bool operator==(const APValue::LValueBase &LHS,
137
6.98M
                const APValue::LValueBase &RHS) {
138
6.98M
  if (LHS.Ptr != RHS.Ptr)
139
5.58M
    return false;
140
1.40M
  if (LHS.is<TypeInfoLValue>() || LHS.is<DynamicAllocLValue>())
141
501
    return true;
142
1.40M
  return LHS.Local.CallIndex == RHS.Local.CallIndex &&
143
1.40M
         LHS.Local.Version == RHS.Local.Version;
144
1.40M
}
145
}
146
147
165k
APValue::LValuePathEntry::LValuePathEntry(BaseOrMemberType BaseOrMember) {
148
165k
  if (const Decl *D = BaseOrMember.getPointer())
149
165k
    BaseOrMember.setPointer(D->getCanonicalDecl());
150
165k
  Value = reinterpret_cast<uintptr_t>(BaseOrMember.getOpaqueValue());
151
165k
}
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
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
107k
void *APValue::LValueBase::getOpaqueValue() const {
176
107k
  return Ptr.getOpaqueValue();
177
107k
}
178
179
5.23k
bool APValue::LValueBase::isNull() const {
180
5.23k
  return Ptr.isNull();
181
5.23k
}
182
183
26.3M
APValue::LValueBase::operator bool () const {
184
26.3M
  return static_cast<bool>(Ptr);
185
26.3M
}
186
187
clang::APValue::LValueBase
188
166k
llvm::DenseMapInfo<clang::APValue::LValueBase>::getEmptyKey() {
189
166k
  clang::APValue::LValueBase B;
190
166k
  B.Ptr = DenseMapInfo<const ValueDecl*>::getEmptyKey();
191
166k
  return B;
192
166k
}
193
194
clang::APValue::LValueBase
195
147k
llvm::DenseMapInfo<clang::APValue::LValueBase>::getTombstoneKey() {
196
147k
  clang::APValue::LValueBase B;
197
147k
  B.Ptr = DenseMapInfo<const ValueDecl*>::getTombstoneKey();
198
147k
  return B;
199
147k
}
200
201
namespace clang {
202
102k
llvm::hash_code hash_value(const APValue::LValueBase &Base) {
203
102k
  if (Base.is<TypeInfoLValue>() || Base.is<DynamicAllocLValue>())
204
713
    return llvm::hash_value(Base.getOpaqueValue());
205
101k
  return llvm::hash_combine(Base.getOpaqueValue(), Base.getCallIndex(),
206
101k
                            Base.getVersion());
207
101k
}
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.22M
  LV() { PathLength = (unsigned)-1; }
234
1.21M
  ~LV() { resizePath(0); }
235
236
2.43M
  void resizePath(unsigned Length) {
237
2.43M
    if (Length == PathLength)
238
1.14M
      return;
239
1.29M
    if (hasPathPtr())
240
82
      delete [] PathPtr;
241
1.29M
    PathLength = Length;
242
1.29M
    if (hasPathPtr())
243
82
      PathPtr = new LValuePathEntry[Length];
244
1.29M
  }
245
246
7.39M
  bool hasPath() const { return PathLength != (unsigned)-1; }
247
5.23M
  bool hasPathPtr() const { return hasPath() && 
PathLength > InlinePathSpace4.00M
; }
248
249
1.21M
  LValuePathEntry *getPath() { return hasPathPtr() ? 
PathPtr82
:
Path1.21M
; }
250
1.42M
  const LValuePathEntry *getPath() const {
251
1.42M
    return hasPathPtr() ? 
PathPtr177
: Path;
252
1.42M
  }
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
1.90k
  MemberPointerData() { PathLength = 0; }
272
1.38k
  ~MemberPointerData() { resizePath(0); }
273
274
3.28k
  void resizePath(unsigned Length) {
275
3.28k
    if (Length == PathLength)
276
2.76k
      return;
277
523
    if (hasPathPtr())
278
31
      delete [] PathPtr;
279
523
    PathLength = Length;
280
523
    if (hasPathPtr())
281
31
      PathPtr = new PathElem[Length];
282
523
  }
283
284
4.33k
  bool hasPathPtr() const { return PathLength > InlinePathSpace; }
285
286
1.90k
  PathElem *getPath() { return hasPathPtr() ? 
PathPtr31
:
Path1.87k
; }
287
862
  const PathElem *getPath() const {
288
806
    return hasPathPtr() ? 
PathPtr56
: Path;
289
862
  }
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.4k
  NumElts(NumElts), ArrSize(Size) {}
297
13.5k
APValue::Arr::~Arr() { delete [] Elts; }
298
299
APValue::StructData::StructData(unsigned NumBases, unsigned NumFields) :
300
  Elts(new APValue[NumBases+NumFields]),
301
61.2k
  NumBases(NumBases), NumFields(NumFields) {}
302
51.5k
APValue::StructData::~StructData() {
303
51.5k
  delete [] Elts;
304
51.5k
}
305
306
2.66k
APValue::UnionData::UnionData() : Field(nullptr), Value(new APValue) {}
307
2.35k
APValue::UnionData::~UnionData () {
308
2.35k
  delete Value;
309
2.35k
}
310
311
5.98M
APValue::APValue(const APValue &RHS) : Kind(None) {
312
5.98M
  switch (RHS.getKind()) {
313
9.79k
  case None:
314
10.9k
  case Indeterminate:
315
10.9k
    Kind = RHS.getKind();
316
10.9k
    break;
317
5.92M
  case Int:
318
5.92M
    MakeInt();
319
5.92M
    setInt(RHS.getInt());
320
5.92M
    break;
321
13.1k
  case Float:
322
13.1k
    MakeFloat();
323
13.1k
    setFloat(RHS.getFloat());
324
13.1k
    break;
325
6
  case FixedPoint: {
326
6
    APFixedPoint FXCopy = RHS.getFixedPoint();
327
6
    MakeFixedPoint(std::move(FXCopy));
328
6
    break;
329
9.79k
  }
330
3.26k
  case Vector:
331
3.26k
    MakeVector();
332
3.26k
    setVector(((const Vec *)(const char *)&RHS.Data)->Elts,
333
3.26k
              RHS.getVectorLength());
334
3.26k
    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
26.5k
  case LValue:
344
26.5k
    MakeLValue();
345
26.5k
    if (RHS.hasLValuePath())
346
26.1k
      setLValue(RHS.getLValueBase(), RHS.getLValueOffset(), RHS.getLValuePath(),
347
26.1k
                RHS.isLValueOnePastTheEnd(), RHS.isNullPointer());
348
348
    else
349
348
      setLValue(RHS.getLValueBase(), RHS.getLValueOffset(), NoLValuePath(),
350
348
                RHS.isNullPointer());
351
26.5k
    break;
352
1.32k
  case Array:
353
1.32k
    MakeArray(RHS.getArrayInitializedElts(), RHS.getArraySize());
354
6.82k
    for (unsigned I = 0, N = RHS.getArrayInitializedElts(); I != N; 
++I5.50k
)
355
5.50k
      getArrayInitializedElt(I) = RHS.getArrayInitializedElt(I);
356
1.32k
    if (RHS.hasArrayFiller())
357
400
      getArrayFiller() = RHS.getArrayFiller();
358
1.32k
    break;
359
4.40k
  case Struct:
360
4.40k
    MakeStruct(RHS.getStructNumBases(), RHS.getStructNumFields());
361
4.86k
    for (unsigned I = 0, N = RHS.getStructNumBases(); I != N; 
++I454
)
362
454
      getStructBase(I) = RHS.getStructBase(I);
363
11.4k
    for (unsigned I = 0, N = RHS.getStructNumFields(); I != N; 
++I7.00k
)
364
7.00k
      getStructField(I) = RHS.getStructField(I);
365
4.40k
    break;
366
534
  case Union:
367
534
    MakeUnion();
368
534
    setUnion(RHS.getUnionField(), RHS.getUnionValue());
369
534
    break;
370
331
  case MemberPointer:
371
331
    MakeMemberPointer(RHS.getMemberPointerDecl(),
372
331
                      RHS.isMemberPointerToDerivedMember(),
373
331
                      RHS.getMemberPointerPath());
374
331
    break;
375
19
  case AddrLabelDiff:
376
19
    MakeAddrLabelDiff();
377
19
    setAddrLabelDiff(RHS.getAddrLabelDiffLHS(), RHS.getAddrLabelDiffRHS());
378
19
    break;
379
5.98M
  }
380
5.98M
}
381
382
94.7k
APValue::APValue(APValue &&RHS) : Kind(RHS.Kind), Data(RHS.Data) {
383
94.7k
  RHS.Kind = None;
384
94.7k
}
385
386
3.46M
APValue &APValue::operator=(const APValue &RHS) {
387
3.46M
  if (this != &RHS)
388
3.46M
    *this = APValue(RHS);
389
3.46M
  return *this;
390
3.46M
}
391
392
36.0M
APValue &APValue::operator=(APValue &&RHS) {
393
36.0M
  if (Kind != None && 
Kind != Indeterminate2.60M
)
394
2.60M
    DestroyDataAndMakeUninit();
395
36.0M
  Kind = RHS.Kind;
396
36.0M
  Data = RHS.Data;
397
36.0M
  RHS.Kind = None;
398
36.0M
  return *this;
399
36.0M
}
400
401
35.0M
void APValue::DestroyDataAndMakeUninit() {
402
35.0M
  if (Kind == Int)
403
33.6M
    ((APSInt *)(char *)&Data)->~APSInt();
404
1.34M
  else if (Kind == Float)
405
53.2k
    ((APFloat *)(char *)&Data)->~APFloat();
406
1.29M
  else if (Kind == FixedPoint)
407
2.90k
    ((APFixedPoint *)(char *)&Data)->~APFixedPoint();
408
1.29M
  else if (Kind == Vector)
409
7.87k
    ((Vec *)(char *)&Data)->~Vec();
410
1.28M
  else if (Kind == ComplexInt)
411
284
    ((ComplexAPSInt *)(char *)&Data)->~ComplexAPSInt();
412
1.28M
  else if (Kind == ComplexFloat)
413
384
    ((ComplexAPFloat *)(char *)&Data)->~ComplexAPFloat();
414
1.28M
  else if (Kind == LValue)
415
1.21M
    ((LV *)(char *)&Data)->~LV();
416
68.8k
  else if (Kind == Array)
417
13.5k
    ((Arr *)(char *)&Data)->~Arr();
418
55.3k
  else if (Kind == Struct)
419
51.5k
    ((StructData *)(char *)&Data)->~StructData();
420
3.79k
  else if (Kind == Union)
421
2.35k
    ((UnionData *)(char *)&Data)->~UnionData();
422
1.43k
  else if (Kind == MemberPointer)
423
1.38k
    ((MemberPointerData *)(char *)&Data)->~MemberPointerData();
424
56
  else if (Kind == AddrLabelDiff)
425
56
    ((AddrLabelDiffData *)(char *)&Data)->~AddrLabelDiffData();
426
35.0M
  Kind = None;
427
35.0M
}
428
429
345k
bool APValue::needsCleanup() const {
430
345k
  switch (getKind()) {
431
3
  case None:
432
3
  case Indeterminate:
433
11
  case AddrLabelDiff:
434
11
    return false;
435
14.0k
  case Struct:
436
14.3k
  case Union:
437
18.9k
  case Array:
438
19.9k
  case Vector:
439
19.9k
    return true;
440
313k
  case Int:
441
313k
    return getInt().needsCleanup();
442
1.97k
  case Float:
443
1.97k
    return getFloat().needsCleanup();
444
350
  case FixedPoint:
445
350
    return getFixedPoint().getValue().needsCleanup();
446
47
  case ComplexFloat:
447
47
    assert(getComplexFloatImag().needsCleanup() ==
448
47
               getComplexFloatReal().needsCleanup() &&
449
47
           "In _Complex float types, real and imaginary values always have the "
450
47
           "same size.");
451
47
    return getComplexFloatReal().needsCleanup();
452
25
  case ComplexInt:
453
25
    assert(getComplexIntImag().needsCleanup() ==
454
25
               getComplexIntReal().needsCleanup() &&
455
25
           "In _Complex int types, real and imaginary values must have the "
456
25
           "same size.");
457
25
    return getComplexIntReal().needsCleanup();
458
8.84k
  case LValue:
459
8.84k
    return reinterpret_cast<const LV *>(&Data)->hasPathPtr();
460
523
  case MemberPointer:
461
523
    return reinterpret_cast<const MemberPointerData *>(&Data)->hasPathPtr();
462
0
  }
463
0
  llvm_unreachable("Unknown APValue kind!");
464
0
}
465
466
12.9M
void APValue::swap(APValue &RHS) {
467
12.9M
  std::swap(Kind, RHS.Kind);
468
12.9M
  std::swap(Data, RHS.Data);
469
12.9M
}
470
471
/// Profile the value of an APInt, excluding its bit-width.
472
973
static void profileIntValue(llvm::FoldingSetNodeID &ID, const llvm::APInt &V) {
473
1.99k
  for (unsigned I = 0, N = V.getBitWidth(); I < N; 
I += 321.02k
)
474
1.02k
    ID.AddInteger((uint32_t)V.extractBitsAsZExtValue(std::min(32u, N - I), I));
475
973
}
476
477
1.65k
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.65k
  ID.AddInteger(Kind);
484
485
1.65k
  switch (Kind) {
486
44
  case None:
487
44
  case Indeterminate:
488
44
    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
372
  case Struct:
496
395
    for (unsigned I = 0, N = getStructNumBases(); I != N; 
++I23
)
497
23
      getStructBase(I).Profile(ID);
498
985
    for (unsigned I = 0, N = getStructNumFields(); I != N; 
++I613
)
499
613
      getStructField(I).Profile(ID);
500
372
    return;
501
502
56
  case Union:
503
56
    if (!getUnionField()) {
504
11
      ID.AddInteger(0);
505
11
      return;
506
11
    }
507
45
    ID.AddInteger(getUnionField()->getFieldIndex() + 1);
508
45
    getUnionValue().Profile(ID);
509
45
    return;
510
511
115
  case Array: {
512
115
    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
115
    llvm::FoldingSetNodeID FillerID;
524
82
    (hasArrayFiller() ? getArrayFiller()
525
33
                      : getArrayInitializedElt(getArrayInitializedElts() - 1))
526
115
        .Profile(FillerID);
527
115
    ID.AddNodeID(FillerID);
528
115
    unsigned NumFillers = getArraySize() - getArrayInitializedElts();
529
115
    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
173
    while (true) {
535
173
      if (N == 0) {
536
        // All elements are fillers.
537
18
        assert(NumFillers == getArraySize());
538
18
        ID.AddInteger(NumFillers);
539
18
        break;
540
18
      }
541
542
      // No need to check if the last element is equal to the last
543
      // element.
544
155
      if (N != getArraySize()) {
545
122
        llvm::FoldingSetNodeID ElemID;
546
122
        getArrayInitializedElt(N - 1).Profile(ElemID);
547
122
        if (ElemID != FillerID) {
548
97
          ID.AddInteger(NumFillers);
549
97
          ID.AddNodeID(ElemID);
550
97
          --N;
551
97
          break;
552
97
        }
553
58
      }
554
555
      // This is a filler.
556
58
      ++NumFillers;
557
58
      --N;
558
58
    }
559
560
    // Emit the remaining elements.
561
363
    for (; N != 0; 
--N248
)
562
248
      getArrayInitializedElt(N - 1).Profile(ID);
563
115
    return;
564
115
  }
565
566
35
  case Vector:
567
140
    for (unsigned I = 0, N = getVectorLength(); I != N; 
++I105
)
568
105
      getVectorElt(I).Profile(ID);
569
35
    return;
570
571
811
  case Int:
572
811
    profileIntValue(ID, getInt());
573
811
    return;
574
575
70
  case Float:
576
70
    profileIntValue(ID, getFloat().bitcastToAPInt());
577
70
    return;
578
579
0
  case FixedPoint:
580
0
    profileIntValue(ID, getFixedPoint().getValue());
581
0
    return;
582
583
23
  case ComplexFloat:
584
23
    profileIntValue(ID, getComplexFloatReal().bitcastToAPInt());
585
23
    profileIntValue(ID, getComplexFloatImag().bitcastToAPInt());
586
23
    return;
587
588
23
  case ComplexInt:
589
23
    profileIntValue(ID, getComplexIntReal());
590
23
    profileIntValue(ID, getComplexIntImag());
591
23
    return;
592
593
69
  case LValue:
594
69
    getLValueBase().Profile(ID);
595
69
    ID.AddInteger(getLValueOffset().getQuantity());
596
46
    ID.AddInteger((isNullPointer() ? 
123
: 0) |
597
67
                  (isLValueOnePastTheEnd() ? 
22
: 0) |
598
63
                  (hasLValuePath() ? 4 : 
06
));
599
69
    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
49
        E.Profile(ID);
606
63
    }
607
69
    return;
608
609
37
  case MemberPointer:
610
37
    ID.AddPointer(getMemberPointerDecl());
611
37
    ID.AddInteger(isMemberPointerToDerivedMember());
612
37
    for (const CXXRecordDecl *D : getMemberPointerPath())
613
8
      ID.AddPointer(D);
614
37
    return;
615
0
  }
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
2.85k
                          QualType Ty) const {
630
2.85k
  printPretty(Out, Ctx.getPrintingPolicy(), Ty, &Ctx);
631
2.85k
}
632
633
void APValue::printPretty(raw_ostream &Out, const PrintingPolicy &Policy,
634
2.96k
                          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
2.96k
  if (Ty->isVoidType()) {
638
0
    Out << "void()";
639
0
    return;
640
0
  }
641
642
2.96k
  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.26k
  case APValue::Int:
650
1.26k
    if (Ty->isBooleanType())
651
30
      Out << (getInt().getBoolValue() ? 
"true"19
:
"false"11
);
652
1.23k
    else
653
1.23k
      Out << getInt();
654
1.26k
    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.59k
  case APValue::LValue: {
680
1.59k
    bool IsReference = Ty->isReferenceType();
681
1.59k
    QualType InnerTy
682
926
      = IsReference ? 
Ty.getNonReferenceType()666
: Ty->getPointeeType();
683
1.59k
    if (InnerTy.isNull())
684
756
      InnerTy = Ty;
685
686
1.59k
    LValueBase Base = getLValueBase();
687
1.59k
    if (!Base) {
688
91
      if (isNullPointer()) {
689
75
        Out << (Policy.Nullptr ? "nullptr" : 
"0"0
);
690
16
      } else if (IsReference) {
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
91
      return;
698
91
    }
699
700
1.50k
    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
0
      } else if (!IsReference) {
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.49k
    if (!IsReference)
740
833
      Out << '&';
741
666
    else if (isLValueOnePastTheEnd())
742
0
      Out << "*(&";
743
744
1.49k
    QualType ElemTy = Base.getType();
745
1.49k
    if (const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>()) {
746
1.25k
      Out << *VD;
747
241
    } else if (TypeInfoLValue TI = Base.dyn_cast<TypeInfoLValue>()) {
748
45
      TI.print(Out, Policy);
749
196
    } else if (DynamicAllocLValue DA = Base.dyn_cast<DynamicAllocLValue>()) {
750
17
      Out << "{*new " << Base.getDynamicAllocType().stream(Policy) << "#"
751
17
          << DA.getIndex() << "}";
752
179
    } else {
753
179
      const Expr *E = Base.get<const Expr*>();
754
179
      assert(E != nullptr && "Expecting non-null Expr");
755
179
      E->printPretty(Out, nullptr, Policy);
756
179
    }
757
758
1.49k
    ArrayRef<LValuePathEntry> Path = getLValuePath();
759
1.49k
    const CXXRecordDecl *CastToBase = nullptr;
760
1.64k
    for (unsigned I = 0, N = Path.size(); I != N; 
++I147
) {
761
147
      if (ElemTy->isRecordType()) {
762
        // The lvalue refers to a class type, so the next path entry is a base
763
        // or member.
764
84
        const Decl *BaseOrMember = Path[I].getAsBaseOrMember().getPointer();
765
84
        if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(BaseOrMember)) {
766
50
          CastToBase = RD;
767
          // Leave ElemTy referring to the most-derived class. The actual type
768
          // doesn't matter except for array types.
769
34
        } 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
63
      } else {
778
        // The lvalue must refer to an array.
779
63
        Out << '[' << Path[I].getAsArrayIndex() << ']';
780
63
        ElemTy = ElemTy->castAsArrayTypeUnsafe()->getElementType();
781
63
      }
782
147
    }
783
784
    // Handle formatting of one-past-the-end lvalues.
785
1.49k
    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.49k
    return;
793
1.49k
  }
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.49k
  }
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
46
    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.49k
  }
839
7
  case APValue::Union:
840
7
    Out << '{';
841
7
    if (const FieldDecl *FD = getUnionField()) {
842
7
      Out << "." << *FD << " = ";
843
7
      getUnionValue().printPretty(Out, Policy, FD->getType(), Ctx);
844
7
    }
845
7
    Out << '}';
846
7
    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
0
  }
862
0
  llvm_unreachable("Unknown APValue kind!");
863
0
}
864
865
530
std::string APValue::getAsString(const ASTContext &Ctx, QualType Ty) const {
866
530
  std::string Result;
867
530
  llvm::raw_string_ostream Out(Result);
868
530
  printPretty(Out, Ctx, Ty);
869
530
  Out.flush();
870
530
  return Result;
871
530
}
872
873
bool APValue::toIntegralConstant(APSInt &Result, QualType SrcTy,
874
1.04k
                                 const ASTContext &Ctx) const {
875
1.04k
  if (isInt()) {
876
277
    Result = getInt();
877
277
    return true;
878
277
  }
879
880
766
  if (isLValue() && isNullPointer()) {
881
364
    Result = Ctx.MakeIntValue(Ctx.getTargetNullPointerValue(SrcTy), SrcTy);
882
364
    return true;
883
364
  }
884
885
402
  if (isLValue() && !getLValueBase()) {
886
401
    Result = Ctx.MakeIntValue(getLValueOffset().getQuantity(), SrcTy);
887
401
    return true;
888
401
  }
889
890
1
  return false;
891
1
}
892
893
2.16M
const APValue::LValueBase APValue::getLValueBase() const {
894
2.16M
  assert(isLValue() && "Invalid accessor");
895
2.16M
  return ((const LV *)(const void *)&Data)->Base;
896
2.16M
}
897
898
730k
bool APValue::isLValueOnePastTheEnd() const {
899
730k
  assert(isLValue() && "Invalid accessor");
900
730k
  return ((const LV *)(const void *)&Data)->IsOnePastTheEnd;
901
730k
}
902
903
743k
CharUnits &APValue::getLValueOffset() {
904
743k
  assert(isLValue() && "Invalid accessor");
905
743k
  return ((LV *)(void *)&Data)->Offset;
906
743k
}
907
908
2.15M
bool APValue::hasLValuePath() const {
909
2.15M
  assert(isLValue() && "Invalid accessor");
910
2.15M
  return ((const LV *)(const char *)&Data)->hasPath();
911
2.15M
}
912
913
1.42M
ArrayRef<APValue::LValuePathEntry> APValue::getLValuePath() const {
914
1.42M
  assert(isLValue() && hasLValuePath() && "Invalid accessor");
915
1.42M
  const LV &LVal = *((const LV *)(const char *)&Data);
916
1.42M
  return llvm::makeArrayRef(LVal.getPath(), LVal.PathLength);
917
1.42M
}
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
735k
bool APValue::isNullPointer() const {
930
735k
  assert(isLValue() && "Invalid usage");
931
735k
  return ((const LV *)(const char *)&Data)->IsNullPtr;
932
735k
}
933
934
void APValue::setLValue(LValueBase B, const CharUnits &O, NoLValuePath,
935
6.48k
                        bool IsNullPtr) {
936
6.48k
  assert(isLValue() && "Invalid accessor");
937
6.48k
  LV &LVal = *((LV *)(char *)&Data);
938
6.48k
  LVal.Base = B;
939
6.48k
  LVal.IsOnePastTheEnd = false;
940
6.48k
  LVal.Offset = O;
941
6.48k
  LVal.resizePath((unsigned)-1);
942
6.48k
  LVal.IsNullPtr = IsNullPtr;
943
6.48k
}
944
945
MutableArrayRef<APValue::LValuePathEntry>
946
APValue::setLValueUninit(LValueBase B, const CharUnits &O, unsigned Size,
947
1.21M
                         bool IsOnePastTheEnd, bool IsNullPtr) {
948
1.21M
  assert(isLValue() && "Invalid accessor");
949
1.21M
  LV &LVal = *((LV *)(char *)&Data);
950
1.21M
  LVal.Base = B;
951
1.21M
  LVal.IsOnePastTheEnd = IsOnePastTheEnd;
952
1.21M
  LVal.Offset = O;
953
1.21M
  LVal.IsNullPtr = IsNullPtr;
954
1.21M
  LVal.resizePath(Size);
955
1.21M
  return {LVal.getPath(), Size};
956
1.21M
}
957
958
void APValue::setLValue(LValueBase B, const CharUnits &O,
959
                        ArrayRef<LValuePathEntry> Path, bool IsOnePastTheEnd,
960
1.21M
                        bool IsNullPtr) {
961
1.21M
  MutableArrayRef<APValue::LValuePathEntry> InternalPath =
962
1.21M
      setLValueUninit(B, O, Path.size(), IsOnePastTheEnd, IsNullPtr);
963
1.21M
  if (Path.size()) {
964
70.5k
    memcpy(InternalPath.data(), Path.data(),
965
70.5k
           Path.size() * sizeof(LValuePathEntry));
966
70.5k
  }
967
1.21M
}
968
969
2.72k
void APValue::setUnion(const FieldDecl *Field, const APValue &Value) {
970
2.72k
  assert(isUnion() && "Invalid accessor");
971
2.72k
  ((UnionData *)(char *)&Data)->Field =
972
2.06k
      Field ? Field->getCanonicalDecl() : 
nullptr655
;
973
2.72k
  *((UnionData *)(char *)&Data)->Value = Value;
974
2.72k
}
975
976
2.60k
const ValueDecl *APValue::getMemberPointerDecl() const {
977
2.60k
  assert(isMemberPointer() && "Invalid accessor");
978
2.60k
  const MemberPointerData &MPD =
979
2.60k
      *((const MemberPointerData *)(const char *)&Data);
980
2.60k
  return MPD.MemberAndIsDerivedMember.getPointer();
981
2.60k
}
982
983
733
bool APValue::isMemberPointerToDerivedMember() const {
984
733
  assert(isMemberPointer() && "Invalid accessor");
985
733
  const MemberPointerData &MPD =
986
733
      *((const MemberPointerData *)(const char *)&Data);
987
733
  return MPD.MemberAndIsDerivedMember.getInt();
988
733
}
989
990
862
ArrayRef<const CXXRecordDecl*> APValue::getMemberPointerPath() const {
991
862
  assert(isMemberPointer() && "Invalid accessor");
992
862
  const MemberPointerData &MPD =
993
862
      *((const MemberPointerData *)(const char *)&Data);
994
862
  return llvm::makeArrayRef(MPD.getPath(), MPD.PathLength);
995
862
}
996
997
1.22M
void APValue::MakeLValue() {
998
1.22M
  assert(isAbsent() && "Bad state change");
999
1.22M
  static_assert(sizeof(LV) <= DataSize, "LV too big");
1000
1.22M
  new ((void *)(char *)&Data) LV();
1001
1.22M
  Kind = LValue;
1002
1.22M
}
1003
1004
15.4k
void APValue::MakeArray(unsigned InitElts, unsigned Size) {
1005
15.4k
  assert(isAbsent() && "Bad state change");
1006
15.4k
  new ((void *)(char *)&Data) Arr(InitElts, Size);
1007
15.4k
  Kind = Array;
1008
15.4k
}
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
1.90k
                                unsigned Size) {
1017
1.90k
  assert(isAbsent() && "Bad state change");
1018
1.90k
  MemberPointerData *MPD = new ((void *)(char *)&Data) MemberPointerData;
1019
1.90k
  Kind = MemberPointer;
1020
1.90k
  MPD->MemberAndIsDerivedMember.setPointer(
1021
1.63k
      Member ? cast<ValueDecl>(Member->getCanonicalDecl()) : 
nullptr268
);
1022
1.90k
  MPD->MemberAndIsDerivedMember.setInt(IsDerivedMember);
1023
1.90k
  MPD->resizePath(Size);
1024
1.90k
  return {MPD->getPath(), MPD->PathLength};
1025
1.90k
}
1026
1027
void APValue::MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember,
1028
1.89k
                                ArrayRef<const CXXRecordDecl *> Path) {
1029
1.89k
  MutableArrayRef<const CXXRecordDecl *> InternalPath =
1030
1.89k
      setMemberPointerUninit(Member, IsDerivedMember, Path.size());
1031
2.65k
  for (unsigned I = 0; I != Path.size(); 
++I754
)
1032
754
    InternalPath[I] = Path[I]->getCanonicalDecl();
1033
1.89k
}
1034
1035
LinkageInfo LinkageComputer::getLVForValue(const APValue &V,
1036
2.64k
                                           LVComputationKind computation) {
1037
2.64k
  LinkageInfo LV = LinkageInfo::external();
1038
1039
2.11k
  auto MergeLV = [&](LinkageInfo MergeLV) {
1040
2.11k
    LV.merge(MergeLV);
1041
2.11k
    return LV.getLinkage() == InternalLinkage;
1042
2.11k
  };
1043
1.99k
  auto Merge = [&](const APValue &V) {
1044
1.99k
    return MergeLV(getLVForValue(V, computation));
1045
1.99k
  };
1046
1047
2.64k
  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
711
  case APValue::Struct: {
1064
811
    for (unsigned I = 0, N = V.getStructNumBases(); I != N; 
++I100
)
1065
100
      if (Merge(V.getStructBase(I)))
1066
0
        break;
1067
2.18k
    for (unsigned I = 0, N = V.getStructNumFields(); I != N; 
++I1.47k
)
1068
1.47k
      if (Merge(V.getStructField(I)))
1069
0
        break;
1070
711
    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
0
    } else if (const auto TI = 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
58
  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.64k
  }
1127
1128
2.64k
  return LV;
1129
2.64k
}