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"
23using namespace clang;
24
25/// The identity of a type_info object depends on the canonical unqualified
26/// type only.
27TypeInfoLValue::TypeInfoLValue(const Type *T)
28 : T(T->getCanonicalTypeUnqualified().getTypePtr()) {}
29
30void TypeInfoLValue::print(llvm::raw_ostream &Out,
31 const PrintingPolicy &Policy) const {
32 Out << "typeid(";
33 QualType(getType(), 0).print(OS&: Out, Policy);
34 Out << ")";
35}
36
37static_assert(
38 1 << llvm::PointerLikeTypeTraits<TypeInfoLValue>::NumLowBitsAvailable <=
39 alignof(Type),
40 "Type is insufficiently aligned");
41
42APValue::LValueBase::LValueBase(const ValueDecl *P, unsigned I, unsigned V)
43 : Ptr(P ? cast<ValueDecl>(Val: P->getCanonicalDecl()) : nullptr), Local{.CallIndex: I, .Version: V} {}
44APValue::LValueBase::LValueBase(const Expr *P, unsigned I, unsigned V)
45 : Ptr(P), Local{.CallIndex: I, .Version: V} {}
46
47APValue::LValueBase APValue::LValueBase::getDynamicAlloc(DynamicAllocLValue LV,
48 QualType Type) {
49 LValueBase Base;
50 Base.Ptr = LV;
51 Base.DynamicAllocType = Type.getAsOpaquePtr();
52 return Base;
53}
54
55APValue::LValueBase APValue::LValueBase::getTypeInfo(TypeInfoLValue LV,
56 QualType TypeInfo) {
57 LValueBase Base;
58 Base.Ptr = LV;
59 Base.TypeInfoType = TypeInfo.getAsOpaquePtr();
60 return Base;
61}
62
63QualType APValue::LValueBase::getType() const {
64 if (!*this) return QualType();
65 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 for (auto *Redecl = cast<ValueDecl>(Val: D->getMostRecentDecl()); Redecl;
74 Redecl = cast_or_null<ValueDecl>(Val: Redecl->getPreviousDecl())) {
75 QualType T = Redecl->getType();
76 if (!T->isIncompleteArrayType())
77 return T;
78 }
79 return D->getType();
80 }
81
82 if (is<TypeInfoLValue>())
83 return getTypeInfoType();
84
85 if (is<DynamicAllocLValue>())
86 return getDynamicAllocType();
87
88 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 if (const MaterializeTemporaryExpr *MTE =
93 llvm::dyn_cast<MaterializeTemporaryExpr>(Val: Base)) {
94 SmallVector<const Expr *, 2> CommaLHSs;
95 SmallVector<SubobjectAdjustment, 2> Adjustments;
96 const Expr *Temp = MTE->getSubExpr();
97 const Expr *Inner = Temp->skipRValueSubobjectAdjustments(CommaLHS&: CommaLHSs,
98 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 if (!Adjustments.empty())
102 return Inner->getType();
103 }
104
105 return Base->getType();
106}
107
108unsigned APValue::LValueBase::getCallIndex() const {
109 return (is<TypeInfoLValue>() || is<DynamicAllocLValue>()) ? 0
110 : Local.CallIndex;
111}
112
113unsigned APValue::LValueBase::getVersion() const {
114 return (is<TypeInfoLValue>() || is<DynamicAllocLValue>()) ? 0 : Local.Version;
115}
116
117QualType APValue::LValueBase::getTypeInfoType() const {
118 assert(is<TypeInfoLValue>() && "not a type_info lvalue");
119 return QualType::getFromOpaquePtr(Ptr: TypeInfoType);
120}
121
122QualType APValue::LValueBase::getDynamicAllocType() const {
123 assert(is<DynamicAllocLValue>() && "not a dynamic allocation lvalue");
124 return QualType::getFromOpaquePtr(Ptr: DynamicAllocType);
125}
126
127void APValue::LValueBase::Profile(llvm::FoldingSetNodeID &ID) const {
128 ID.AddPointer(Ptr: Ptr.getOpaqueValue());
129 if (is<TypeInfoLValue>() || is<DynamicAllocLValue>())
130 return;
131 ID.AddInteger(I: Local.CallIndex);
132 ID.AddInteger(I: Local.Version);
133}
134
135namespace clang {
136bool operator==(const APValue::LValueBase &LHS,
137 const APValue::LValueBase &RHS) {
138 if (LHS.Ptr != RHS.Ptr)
139 return false;
140 if (LHS.is<TypeInfoLValue>() || LHS.is<DynamicAllocLValue>())
141 return true;
142 return LHS.Local.CallIndex == RHS.Local.CallIndex &&
143 LHS.Local.Version == RHS.Local.Version;
144}
145}
146
147APValue::LValuePathEntry::LValuePathEntry(BaseOrMemberType BaseOrMember) {
148 if (const Decl *D = BaseOrMember.getPointer())
149 BaseOrMember.setPointer(D->getCanonicalDecl());
150 Value = reinterpret_cast<uintptr_t>(BaseOrMember.getOpaqueValue());
151}
152
153void APValue::LValuePathEntry::Profile(llvm::FoldingSetNodeID &ID) const {
154 ID.AddInteger(I: Value);
155}
156
157APValue::LValuePathSerializationHelper::LValuePathSerializationHelper(
158 ArrayRef<LValuePathEntry> Path, QualType ElemTy)
159 : Ty((const void *)ElemTy.getTypePtrOrNull()), Path(Path) {}
160
161QualType APValue::LValuePathSerializationHelper::getType() {
162 return QualType::getFromOpaquePtr(Ptr: Ty);
163}
164
165namespace {
166 struct LVBase {
167 APValue::LValueBase Base;
168 CharUnits Offset;
169 unsigned PathLength;
170 bool IsNullPtr : 1;
171 bool IsOnePastTheEnd : 1;
172 };
173}
174
175void *APValue::LValueBase::getOpaqueValue() const {
176 return Ptr.getOpaqueValue();
177}
178
179bool APValue::LValueBase::isNull() const {
180 return Ptr.isNull();
181}
182
183APValue::LValueBase::operator bool () const {
184 return static_cast<bool>(Ptr);
185}
186
187namespace clang {
188llvm::hash_code hash_value(const APValue::LValueBase &Base) {
189 if (Base.is<TypeInfoLValue>() || Base.is<DynamicAllocLValue>())
190 return llvm::hash_value(ptr: Base.getOpaqueValue());
191 return llvm::hash_combine(args: Base.getOpaqueValue(), args: Base.getCallIndex(),
192 args: Base.getVersion());
193}
194}
195
196unsigned llvm::DenseMapInfo<clang::APValue::LValueBase>::getHashValue(
197 const clang::APValue::LValueBase &Base) {
198 return hash_value(Base);
199}
200
201bool llvm::DenseMapInfo<clang::APValue::LValueBase>::isEqual(
202 const clang::APValue::LValueBase &LHS,
203 const clang::APValue::LValueBase &RHS) {
204 return LHS == RHS;
205}
206
207struct APValue::LV : LVBase {
208 static const unsigned InlinePathSpace =
209 (DataSize - sizeof(LVBase)) / sizeof(LValuePathEntry);
210
211 /// Path - The sequence of base classes, fields and array indices to follow to
212 /// walk from Base to the subobject. When performing GCC-style folding, there
213 /// may not be such a path.
214 union {
215 LValuePathEntry Path[InlinePathSpace];
216 LValuePathEntry *PathPtr;
217 };
218
219 LV() { PathLength = (unsigned)-1; }
220 ~LV() { resizePath(Length: 0); }
221
222 void resizePath(unsigned Length) {
223 if (Length == PathLength)
224 return;
225 if (hasPathPtr())
226 delete [] PathPtr;
227 PathLength = Length;
228 if (hasPathPtr())
229 PathPtr = new LValuePathEntry[Length];
230 }
231
232 bool hasPath() const { return PathLength != (unsigned)-1; }
233 bool hasPathPtr() const { return hasPath() && PathLength > InlinePathSpace; }
234
235 LValuePathEntry *getPath() { return hasPathPtr() ? PathPtr : Path; }
236 const LValuePathEntry *getPath() const {
237 return hasPathPtr() ? PathPtr : Path;
238 }
239};
240
241namespace {
242 struct MemberPointerBase {
243 llvm::PointerIntPair<const ValueDecl*, 1, bool> MemberAndIsDerivedMember;
244 unsigned PathLength;
245 };
246}
247
248struct APValue::MemberPointerData : MemberPointerBase {
249 static const unsigned InlinePathSpace =
250 (DataSize - sizeof(MemberPointerBase)) / sizeof(const CXXRecordDecl*);
251 typedef const CXXRecordDecl *PathElem;
252 union {
253 PathElem Path[InlinePathSpace];
254 PathElem *PathPtr;
255 };
256
257 MemberPointerData() { PathLength = 0; }
258 ~MemberPointerData() { resizePath(Length: 0); }
259
260 void resizePath(unsigned Length) {
261 if (Length == PathLength)
262 return;
263 if (hasPathPtr())
264 delete [] PathPtr;
265 PathLength = Length;
266 if (hasPathPtr())
267 PathPtr = new PathElem[Length];
268 }
269
270 bool hasPathPtr() const { return PathLength > InlinePathSpace; }
271
272 PathElem *getPath() { return hasPathPtr() ? PathPtr : Path; }
273 const PathElem *getPath() const {
274 return hasPathPtr() ? PathPtr : Path;
275 }
276};
277
278// FIXME: Reduce the malloc traffic here.
279
280APValue::Arr::Arr(unsigned NumElts, unsigned Size) :
281 Elts(new APValue[NumElts + (NumElts != Size ? 1 : 0)]),
282 NumElts(NumElts), ArrSize(Size) {}
283APValue::Arr::~Arr() { delete [] Elts; }
284
285APValue::StructData::StructData(unsigned NumBases, unsigned NumFields,
286 unsigned NumVirtualBases)
287 : Elts(new APValue[NumBases + NumFields + NumVirtualBases]),
288 NumBases(NumBases), NumFields(NumFields),
289 NumVirtualBases(NumVirtualBases) {}
290
291APValue::StructData::~StructData() {
292 delete [] Elts;
293}
294
295APValue::UnionData::UnionData() : Field(nullptr), Value(new APValue) {}
296APValue::UnionData::~UnionData () {
297 delete Value;
298}
299
300APValue::APValue(const APValue &RHS)
301 : Kind(None), AllowConstexprUnknown(RHS.AllowConstexprUnknown) {
302 switch (RHS.getKind()) {
303 case None:
304 case Indeterminate:
305 Kind = RHS.getKind();
306 break;
307 case Int:
308 MakeInt();
309 setInt(RHS.getInt());
310 break;
311 case Float:
312 MakeFloat();
313 setFloat(RHS.getFloat());
314 break;
315 case FixedPoint: {
316 APFixedPoint FXCopy = RHS.getFixedPoint();
317 MakeFixedPoint(FX: std::move(FXCopy));
318 break;
319 }
320 case Vector:
321 MakeVector();
322 setVector(E: ((const Vec *)(const char *)&RHS.Data)->Elts,
323 N: RHS.getVectorLength());
324 break;
325 case Matrix:
326 MakeMatrix();
327 setMatrix(E: ((const Mat *)(const char *)&RHS.Data)->Elts,
328 NumRows: RHS.getMatrixNumRows(), NumCols: RHS.getMatrixNumColumns());
329 break;
330 case ComplexInt:
331 MakeComplexInt();
332 setComplexInt(R: RHS.getComplexIntReal(), I: RHS.getComplexIntImag());
333 break;
334 case ComplexFloat:
335 MakeComplexFloat();
336 setComplexFloat(R: RHS.getComplexFloatReal(), I: RHS.getComplexFloatImag());
337 break;
338 case LValue:
339 MakeLValue();
340 if (RHS.hasLValuePath())
341 setLValue(B: RHS.getLValueBase(), O: RHS.getLValueOffset(), Path: RHS.getLValuePath(),
342 OnePastTheEnd: RHS.isLValueOnePastTheEnd(), IsNullPtr: RHS.isNullPointer());
343 else
344 setLValue(B: RHS.getLValueBase(), O: RHS.getLValueOffset(), NoLValuePath(),
345 IsNullPtr: RHS.isNullPointer());
346 break;
347 case Array:
348 MakeArray(InitElts: RHS.getArrayInitializedElts(), Size: RHS.getArraySize());
349 for (unsigned I = 0, N = RHS.getArrayInitializedElts(); I != N; ++I)
350 getArrayInitializedElt(I) = RHS.getArrayInitializedElt(I);
351 if (RHS.hasArrayFiller())
352 getArrayFiller() = RHS.getArrayFiller();
353 break;
354 case Struct:
355 MakeStruct(B: RHS.getStructNumBases(), M: RHS.getStructNumFields(),
356 V: RHS.getStructNumVirtualBases());
357 for (unsigned I = 0, N = RHS.getStructNumBases(); I != N; ++I)
358 getStructBase(i: I) = RHS.getStructBase(i: I);
359 for (unsigned I = 0, N = RHS.getStructNumFields(); I != N; ++I)
360 getStructField(i: I) = RHS.getStructField(i: I);
361 for (unsigned I = 0, N = RHS.getStructNumVirtualBases(); I != N; ++I)
362 getStructVirtualBase(i: I) = RHS.getStructVirtualBase(i: I);
363 break;
364 case Union:
365 MakeUnion();
366 setUnion(Field: RHS.getUnionField(), Value: RHS.getUnionValue());
367 break;
368 case MemberPointer:
369 MakeMemberPointer(Member: RHS.getMemberPointerDecl(),
370 IsDerivedMember: RHS.isMemberPointerToDerivedMember(),
371 Path: RHS.getMemberPointerPath());
372 break;
373 case AddrLabelDiff:
374 MakeAddrLabelDiff();
375 setAddrLabelDiff(LHSExpr: RHS.getAddrLabelDiffLHS(), RHSExpr: RHS.getAddrLabelDiffRHS());
376 break;
377 }
378}
379
380APValue::APValue(APValue &&RHS)
381 : Kind(RHS.Kind), AllowConstexprUnknown(RHS.AllowConstexprUnknown),
382 Data(RHS.Data) {
383 RHS.Kind = None;
384}
385
386APValue &APValue::operator=(const APValue &RHS) {
387 if (this != &RHS)
388 *this = APValue(RHS);
389
390 return *this;
391}
392
393APValue &APValue::operator=(APValue &&RHS) {
394 if (this != &RHS) {
395 if (Kind != None && Kind != Indeterminate)
396 DestroyDataAndMakeUninit();
397 Kind = RHS.Kind;
398 Data = RHS.Data;
399 AllowConstexprUnknown = RHS.AllowConstexprUnknown;
400 RHS.Kind = None;
401 }
402 return *this;
403}
404
405void APValue::DestroyDataAndMakeUninit() {
406 if (Kind == Int)
407 ((APSInt *)(char *)&Data)->~APSInt();
408 else if (Kind == Float)
409 ((APFloat *)(char *)&Data)->~APFloat();
410 else if (Kind == FixedPoint)
411 ((APFixedPoint *)(char *)&Data)->~APFixedPoint();
412 else if (Kind == Vector)
413 ((Vec *)(char *)&Data)->~Vec();
414 else if (Kind == Matrix)
415 ((Mat *)(char *)&Data)->~Mat();
416 else if (Kind == ComplexInt)
417 ((ComplexAPSInt *)(char *)&Data)->~ComplexAPSInt();
418 else if (Kind == ComplexFloat)
419 ((ComplexAPFloat *)(char *)&Data)->~ComplexAPFloat();
420 else if (Kind == LValue)
421 ((LV *)(char *)&Data)->~LV();
422 else if (Kind == Array)
423 ((Arr *)(char *)&Data)->~Arr();
424 else if (Kind == Struct)
425 ((StructData *)(char *)&Data)->~StructData();
426 else if (Kind == Union)
427 ((UnionData *)(char *)&Data)->~UnionData();
428 else if (Kind == MemberPointer)
429 ((MemberPointerData *)(char *)&Data)->~MemberPointerData();
430 else if (Kind == AddrLabelDiff)
431 ((AddrLabelDiffData *)(char *)&Data)->~AddrLabelDiffData();
432 Kind = None;
433 AllowConstexprUnknown = false;
434}
435
436bool APValue::needsCleanup() const {
437 switch (getKind()) {
438 case None:
439 case Indeterminate:
440 case AddrLabelDiff:
441 return false;
442 case Struct:
443 case Union:
444 case Array:
445 case Vector:
446 case Matrix:
447 return true;
448 case Int:
449 return getInt().needsCleanup();
450 case Float:
451 return getFloat().needsCleanup();
452 case FixedPoint:
453 return getFixedPoint().getValue().needsCleanup();
454 case ComplexFloat:
455 assert(getComplexFloatImag().needsCleanup() ==
456 getComplexFloatReal().needsCleanup() &&
457 "In _Complex float types, real and imaginary values always have the "
458 "same size.");
459 return getComplexFloatReal().needsCleanup();
460 case ComplexInt:
461 assert(getComplexIntImag().needsCleanup() ==
462 getComplexIntReal().needsCleanup() &&
463 "In _Complex int types, real and imaginary values must have the "
464 "same size.");
465 return getComplexIntReal().needsCleanup();
466 case LValue:
467 return reinterpret_cast<const LV *>(&Data)->hasPathPtr();
468 case MemberPointer:
469 return reinterpret_cast<const MemberPointerData *>(&Data)->hasPathPtr();
470 }
471 llvm_unreachable("Unknown APValue kind!");
472}
473
474void APValue::swap(APValue &RHS) {
475 std::swap(a&: Kind, b&: RHS.Kind);
476 std::swap(a&: Data, b&: RHS.Data);
477 // We can't use std::swap w/ bit-fields
478 bool tmp = AllowConstexprUnknown;
479 AllowConstexprUnknown = RHS.AllowConstexprUnknown;
480 RHS.AllowConstexprUnknown = tmp;
481}
482
483/// Profile the value of an APInt, excluding its bit-width.
484static void profileIntValue(llvm::FoldingSetNodeID &ID, const llvm::APInt &V) {
485 for (unsigned I = 0, N = V.getBitWidth(); I < N; I += 32)
486 ID.AddInteger(I: (uint32_t)V.extractBitsAsZExtValue(numBits: std::min(a: 32u, b: N - I), bitPosition: I));
487}
488
489void APValue::Profile(llvm::FoldingSetNodeID &ID) const {
490 // Note that our profiling assumes that only APValues of the same type are
491 // ever compared. As a result, we don't consider collisions that could only
492 // happen if the types are different. (For example, structs with different
493 // numbers of members could profile the same.)
494
495 ID.AddInteger(I: Kind);
496
497 switch (Kind) {
498 case None:
499 case Indeterminate:
500 return;
501
502 case AddrLabelDiff:
503 ID.AddPointer(Ptr: getAddrLabelDiffLHS()->getLabel()->getCanonicalDecl());
504 ID.AddPointer(Ptr: getAddrLabelDiffRHS()->getLabel()->getCanonicalDecl());
505 return;
506
507 case Struct:
508 for (unsigned I = 0, N = getStructNumBases(); I != N; ++I)
509 getStructBase(i: I).Profile(ID);
510 for (unsigned I = 0, N = getStructNumFields(); I != N; ++I)
511 getStructField(i: I).Profile(ID);
512 for (unsigned I = 0, N = getStructNumVirtualBases(); I != N; ++I)
513 getStructVirtualBase(i: I).Profile(ID);
514 return;
515
516 case Union:
517 if (!getUnionField()) {
518 ID.AddInteger(I: 0);
519 return;
520 }
521 ID.AddInteger(I: getUnionField()->getFieldIndex() + 1);
522 getUnionValue().Profile(ID);
523 return;
524
525 case Array: {
526 if (getArraySize() == 0)
527 return;
528
529 // The profile should not depend on whether the array is expanded or
530 // not, but we don't want to profile the array filler many times for
531 // a large array. So treat all equal trailing elements as the filler.
532 // Elements are profiled in reverse order to support this, and the
533 // first profiled element is followed by a count. For example:
534 //
535 // ['a', 'c', 'x', 'x', 'x'] is profiled as
536 // [5, 'x', 3, 'c', 'a']
537 llvm::FoldingSetNodeID FillerID;
538 (hasArrayFiller() ? getArrayFiller()
539 : getArrayInitializedElt(I: getArrayInitializedElts() - 1))
540 .Profile(ID&: FillerID);
541 ID.AddNodeID(ID: FillerID);
542 unsigned NumFillers = getArraySize() - getArrayInitializedElts();
543 unsigned N = getArrayInitializedElts();
544
545 // Count the number of elements equal to the last one. This loop ends
546 // by adding an integer indicating the number of such elements, with
547 // N set to the number of elements left to profile.
548 while (true) {
549 if (N == 0) {
550 // All elements are fillers.
551 assert(NumFillers == getArraySize());
552 ID.AddInteger(I: NumFillers);
553 break;
554 }
555
556 // No need to check if the last element is equal to the last
557 // element.
558 if (N != getArraySize()) {
559 llvm::FoldingSetNodeID ElemID;
560 getArrayInitializedElt(I: N - 1).Profile(ID&: ElemID);
561 if (ElemID != FillerID) {
562 ID.AddInteger(I: NumFillers);
563 ID.AddNodeID(ID: ElemID);
564 --N;
565 break;
566 }
567 }
568
569 // This is a filler.
570 ++NumFillers;
571 --N;
572 }
573
574 // Emit the remaining elements.
575 for (; N != 0; --N)
576 getArrayInitializedElt(I: N - 1).Profile(ID);
577 return;
578 }
579
580 case Vector:
581 for (unsigned I = 0, N = getVectorLength(); I != N; ++I)
582 getVectorElt(I).Profile(ID);
583 return;
584
585 case Matrix:
586 for (unsigned R = 0, N = getMatrixNumRows(); R != N; ++R)
587 for (unsigned C = 0, M = getMatrixNumColumns(); C != M; ++C)
588 getMatrixElt(Row: R, Col: C).Profile(ID);
589 return;
590
591 case Int:
592 profileIntValue(ID, V: getInt());
593 return;
594
595 case Float:
596 profileIntValue(ID, V: getFloat().bitcastToAPInt());
597 return;
598
599 case FixedPoint:
600 profileIntValue(ID, V: getFixedPoint().getValue());
601 return;
602
603 case ComplexFloat:
604 profileIntValue(ID, V: getComplexFloatReal().bitcastToAPInt());
605 profileIntValue(ID, V: getComplexFloatImag().bitcastToAPInt());
606 return;
607
608 case ComplexInt:
609 profileIntValue(ID, V: getComplexIntReal());
610 profileIntValue(ID, V: getComplexIntImag());
611 return;
612
613 case LValue:
614 getLValueBase().Profile(ID);
615 ID.AddInteger(I: getLValueOffset().getQuantity());
616 ID.AddInteger(I: (isNullPointer() ? 1 : 0) |
617 (isLValueOnePastTheEnd() ? 2 : 0) |
618 (hasLValuePath() ? 4 : 0));
619 if (hasLValuePath()) {
620 ID.AddInteger(I: getLValuePath().size());
621 // For uniqueness, we only need to profile the entries corresponding
622 // to union members, but we don't have the type here so we don't know
623 // how to interpret the entries.
624 for (LValuePathEntry E : getLValuePath())
625 E.Profile(ID);
626 }
627 return;
628
629 case MemberPointer:
630 ID.AddPointer(Ptr: getMemberPointerDecl());
631 ID.AddInteger(I: isMemberPointerToDerivedMember());
632 for (const CXXRecordDecl *D : getMemberPointerPath())
633 ID.AddPointer(Ptr: D);
634 return;
635 }
636
637 llvm_unreachable("Unknown APValue kind!");
638}
639
640static double GetApproxValue(const llvm::APFloat &F) {
641 llvm::APFloat V = F;
642 bool ignored;
643 V.convert(ToSemantics: llvm::APFloat::IEEEdouble(), RM: llvm::APFloat::rmNearestTiesToEven,
644 losesInfo: &ignored);
645 return V.convertToDouble();
646}
647
648static bool TryPrintAsStringLiteral(raw_ostream &Out,
649 const PrintingPolicy &Policy,
650 const ArrayType *ATy,
651 ArrayRef<APValue> Inits) {
652 if (Inits.empty())
653 return false;
654
655 QualType Ty = ATy->getElementType();
656 if (!Ty->isAnyCharacterType())
657 return false;
658
659 // Nothing we can do about a sequence that is not null-terminated
660 if (!Inits.back().isInt() || !Inits.back().getInt().isZero())
661 return false;
662
663 Inits = Inits.drop_back();
664
665 llvm::SmallString<40> Buf;
666 Buf.push_back(Elt: '"');
667
668 // Better than printing a two-digit sequence of 10 integers.
669 constexpr size_t MaxN = 36;
670 StringRef Ellipsis;
671 if (Inits.size() > MaxN && !Policy.EntireContentsOfLargeArray) {
672 Ellipsis = "[...]";
673 Inits =
674 Inits.take_front(N: std::min(a: MaxN - Ellipsis.size() / 2, b: Inits.size()));
675 }
676
677 for (auto &Val : Inits) {
678 if (!Val.isInt())
679 return false;
680 int64_t Char64 = Val.getInt().getExtValue();
681 if (!isASCII(c: Char64))
682 return false; // Bye bye, see you in integers.
683 auto Ch = static_cast<unsigned char>(Char64);
684 // The diagnostic message is 'quoted'
685 StringRef Escaped = escapeCStyle<EscapeChar::SingleAndDouble>(Ch);
686 if (Escaped.empty()) {
687 if (!isPrintable(c: Ch))
688 return false;
689 Buf.emplace_back(Args&: Ch);
690 } else {
691 Buf.append(RHS: Escaped);
692 }
693 }
694
695 Buf.append(RHS: Ellipsis);
696 Buf.push_back(Elt: '"');
697
698 if (Ty->isWideCharType())
699 Out << 'L';
700 else if (Ty->isChar8Type())
701 Out << "u8";
702 else if (Ty->isChar16Type())
703 Out << 'u';
704 else if (Ty->isChar32Type())
705 Out << 'U';
706
707 Out << Buf;
708 return true;
709}
710
711void APValue::printPretty(raw_ostream &Out, const ASTContext &Ctx,
712 QualType Ty) const {
713 printPretty(OS&: Out, Policy: Ctx.getPrintingPolicy(), Ty, Ctx: &Ctx);
714}
715
716void APValue::printPretty(raw_ostream &Out, const PrintingPolicy &Policy,
717 QualType Ty, const ASTContext *Ctx) const {
718 // There are no objects of type 'void', but values of this type can be
719 // returned from functions.
720 if (Ty->isVoidType()) {
721 Out << "void()";
722 return;
723 }
724
725 if (const auto *AT = Ty->getAs<AtomicType>())
726 Ty = AT->getValueType();
727
728 switch (getKind()) {
729 case APValue::None:
730 Out << "<out of lifetime>";
731 return;
732 case APValue::Indeterminate:
733 Out << "<uninitialized>";
734 return;
735 case APValue::Int:
736 if (Ty->isBooleanType())
737 Out << (getInt().getBoolValue() ? "true" : "false");
738 else
739 Out << getInt();
740 return;
741 case APValue::Float:
742 Out << GetApproxValue(F: getFloat());
743 return;
744 case APValue::FixedPoint:
745 Out << getFixedPoint();
746 return;
747 case APValue::Vector: {
748 Out << '{';
749 QualType ElemTy = Ty->castAs<VectorType>()->getElementType();
750 getVectorElt(I: 0).printPretty(Out, Policy, Ty: ElemTy, Ctx);
751 for (unsigned i = 1; i != getVectorLength(); ++i) {
752 Out << ", ";
753 getVectorElt(I: i).printPretty(Out, Policy, Ty: ElemTy, Ctx);
754 }
755 Out << '}';
756 return;
757 }
758 case APValue::Matrix: {
759 const auto *MT = Ty->castAs<ConstantMatrixType>();
760 QualType ElemTy = MT->getElementType();
761 Out << '{';
762 for (unsigned R = 0; R < getMatrixNumRows(); ++R) {
763 if (R != 0)
764 Out << ", ";
765 Out << '{';
766 for (unsigned C = 0; C < getMatrixNumColumns(); ++C) {
767 if (C != 0)
768 Out << ", ";
769 getMatrixElt(Row: R, Col: C).printPretty(Out, Policy, Ty: ElemTy, Ctx);
770 }
771 Out << '}';
772 }
773 Out << '}';
774 return;
775 }
776 case APValue::ComplexInt:
777 Out << getComplexIntReal() << "+" << getComplexIntImag() << "i";
778 return;
779 case APValue::ComplexFloat:
780 Out << GetApproxValue(F: getComplexFloatReal()) << "+"
781 << GetApproxValue(F: getComplexFloatImag()) << "i";
782 return;
783 case APValue::LValue: {
784 bool IsReference = Ty->isReferenceType();
785 QualType InnerTy
786 = IsReference ? Ty.getNonReferenceType() : Ty->getPointeeType();
787 if (InnerTy.isNull())
788 InnerTy = Ty;
789
790 LValueBase Base = getLValueBase();
791 if (!Base) {
792 if (isNullPointer()) {
793 Out << (Policy.Nullptr ? "nullptr" : "0");
794 } else if (IsReference) {
795 Out << "*(" << InnerTy.stream(Policy) << "*)"
796 << getLValueOffset().getQuantity();
797 } else {
798 Out << "(" << Ty.stream(Policy) << ")"
799 << getLValueOffset().getQuantity();
800 }
801 return;
802 }
803
804 if (!hasLValuePath()) {
805 // No lvalue path: just print the offset.
806 CharUnits O = getLValueOffset();
807 CharUnits S = Ctx ? Ctx->getTypeSizeInCharsIfKnown(Ty: InnerTy).value_or(
808 u: CharUnits::Zero())
809 : CharUnits::Zero();
810 if (!O.isZero()) {
811 if (IsReference)
812 Out << "*(";
813 if (S.isZero() || !O.isMultipleOf(N: S)) {
814 Out << "(char*)";
815 S = CharUnits::One();
816 }
817 Out << '&';
818 } else if (!IsReference) {
819 Out << '&';
820 }
821
822 if (const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>())
823 Out << *VD;
824 else if (TypeInfoLValue TI = Base.dyn_cast<TypeInfoLValue>()) {
825 TI.print(Out, Policy);
826 } else if (DynamicAllocLValue DA = Base.dyn_cast<DynamicAllocLValue>()) {
827 Out << "{*new "
828 << Base.getDynamicAllocType().stream(Policy) << "#"
829 << DA.getIndex() << "}";
830 } else {
831 assert(Base.get<const Expr *>() != nullptr &&
832 "Expecting non-null Expr");
833 Base.get<const Expr*>()->printPretty(OS&: Out, Helper: nullptr, Policy);
834 }
835
836 if (!O.isZero()) {
837 Out << " + " << (O / S);
838 if (IsReference)
839 Out << ')';
840 }
841 return;
842 }
843
844 // We have an lvalue path. Print it out nicely.
845 if (!IsReference)
846 Out << '&';
847 else if (isLValueOnePastTheEnd())
848 Out << "*(&";
849
850 QualType ElemTy = Base.getType().getNonReferenceType();
851 if (const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>()) {
852 Out << *VD;
853 } else if (TypeInfoLValue TI = Base.dyn_cast<TypeInfoLValue>()) {
854 TI.print(Out, Policy);
855 } else if (DynamicAllocLValue DA = Base.dyn_cast<DynamicAllocLValue>()) {
856 Out << "{*new " << Base.getDynamicAllocType().stream(Policy) << "#"
857 << DA.getIndex() << "}";
858 } else {
859 const Expr *E = Base.get<const Expr*>();
860 assert(E != nullptr && "Expecting non-null Expr");
861 E->printPretty(OS&: Out, Helper: nullptr, Policy);
862 }
863
864 ArrayRef<LValuePathEntry> Path = getLValuePath();
865 const CXXRecordDecl *CastToBase = nullptr;
866 for (unsigned I = 0, N = Path.size(); I != N; ++I) {
867 if (ElemTy->isRecordType()) {
868 // The lvalue refers to a class type, so the next path entry is a base
869 // or member.
870 const Decl *BaseOrMember = Path[I].getAsBaseOrMember().getPointer();
871 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Val: BaseOrMember)) {
872 CastToBase = RD;
873 // Leave ElemTy referring to the most-derived class. The actual type
874 // doesn't matter except for array types.
875 } else {
876 const ValueDecl *VD = cast<ValueDecl>(Val: BaseOrMember);
877 Out << ".";
878 if (CastToBase)
879 Out << *CastToBase << "::";
880 Out << *VD;
881 ElemTy = VD->getType();
882 }
883 } else if (ElemTy->isAnyComplexType()) {
884 // The lvalue refers to a complex type
885 Out << (Path[I].getAsArrayIndex() == 0 ? ".real" : ".imag");
886 ElemTy = ElemTy->castAs<ComplexType>()->getElementType();
887 } else {
888 // The lvalue must refer to an array.
889 Out << '[' << Path[I].getAsArrayIndex() << ']';
890 ElemTy = ElemTy->castAsArrayTypeUnsafe()->getElementType();
891 }
892 }
893
894 // Handle formatting of one-past-the-end lvalues.
895 if (isLValueOnePastTheEnd()) {
896 // FIXME: If CastToBase is non-0, we should prefix the output with
897 // "(CastToBase*)".
898 Out << " + 1";
899 if (IsReference)
900 Out << ')';
901 }
902 return;
903 }
904 case APValue::Array: {
905 const ArrayType *AT = Ty->castAsArrayTypeUnsafe();
906 unsigned N = getArrayInitializedElts();
907 if (N != 0 && TryPrintAsStringLiteral(Out, Policy, ATy: AT,
908 Inits: {&getArrayInitializedElt(I: 0), N}))
909 return;
910 QualType ElemTy = AT->getElementType();
911 Out << '{';
912 unsigned I = 0;
913 switch (N) {
914 case 0:
915 for (; I != N; ++I) {
916 Out << ", ";
917 if (I == 10 && !Policy.EntireContentsOfLargeArray) {
918 Out << "...}";
919 return;
920 }
921 [[fallthrough]];
922 default:
923 getArrayInitializedElt(I).printPretty(Out, Policy, Ty: ElemTy, Ctx);
924 }
925 }
926 Out << '}';
927 return;
928 }
929 case APValue::Struct: {
930 Out << '{';
931 bool First = true;
932 const auto *RD = Ty->castAsRecordDecl();
933 if (unsigned N = getStructNumBases()) {
934 const CXXRecordDecl *CD = cast<CXXRecordDecl>(Val: RD);
935 CXXRecordDecl::base_class_const_iterator BI = CD->bases_begin();
936 for (unsigned I = 0; I != N; ++I, ++BI) {
937 assert(BI != CD->bases_end());
938 if (!First)
939 Out << ", ";
940 getStructBase(i: I).printPretty(Out, Policy, Ty: BI->getType(), Ctx);
941 First = false;
942 }
943 }
944 for (const auto *FI : RD->fields()) {
945 if (!First)
946 Out << ", ";
947 if (FI->isUnnamedBitField())
948 continue;
949 getStructField(i: FI->getFieldIndex()).
950 printPretty(Out, Policy, Ty: FI->getType(), Ctx);
951 First = false;
952 }
953 if (unsigned N = getStructNumVirtualBases()) {
954 const CXXRecordDecl *CD = cast<CXXRecordDecl>(Val: RD);
955 CXXRecordDecl::base_class_const_iterator BI = CD->vbases_begin();
956 for (unsigned I = 0; I != N; ++I, ++BI) {
957 assert(BI != CD->vbases_end());
958 if (!First)
959 Out << ", ";
960 getStructVirtualBase(i: I).printPretty(Out, Policy, Ty: BI->getType(), Ctx);
961 First = false;
962 }
963 }
964 Out << '}';
965 return;
966 }
967 case APValue::Union:
968 Out << '{';
969 if (const FieldDecl *FD = getUnionField()) {
970 Out << "." << *FD << " = ";
971 getUnionValue().printPretty(Out, Policy, Ty: FD->getType(), Ctx);
972 }
973 Out << '}';
974 return;
975 case APValue::MemberPointer:
976 // FIXME: This is not enough to unambiguously identify the member in a
977 // multiple-inheritance scenario.
978 if (const ValueDecl *VD = getMemberPointerDecl()) {
979 Out << '&' << *cast<CXXRecordDecl>(Val: VD->getDeclContext()) << "::" << *VD;
980 return;
981 }
982 Out << "0";
983 return;
984 case APValue::AddrLabelDiff:
985 Out << "&&" << getAddrLabelDiffLHS()->getLabel()->getName();
986 Out << " - ";
987 Out << "&&" << getAddrLabelDiffRHS()->getLabel()->getName();
988 return;
989 }
990 llvm_unreachable("Unknown APValue kind!");
991}
992
993std::string APValue::getAsString(const ASTContext &Ctx, QualType Ty) const {
994 std::string Result;
995 llvm::raw_string_ostream Out(Result);
996 printPretty(Out, Ctx, Ty);
997 return Result;
998}
999
1000bool APValue::toIntegralConstant(APSInt &Result, QualType SrcTy,
1001 const ASTContext &Ctx) const {
1002 if (isInt()) {
1003 Result = getInt();
1004 return true;
1005 }
1006
1007 if (isLValue() && isNullPointer()) {
1008 Result = Ctx.MakeIntValue(Value: Ctx.getTargetNullPointerValue(QT: SrcTy), Type: SrcTy);
1009 return true;
1010 }
1011
1012 if (isLValue() && !getLValueBase()) {
1013 Result = Ctx.MakeIntValue(Value: getLValueOffset().getQuantity(), Type: SrcTy);
1014 return true;
1015 }
1016
1017 return false;
1018}
1019
1020const APValue::LValueBase APValue::getLValueBase() const {
1021 assert(isLValue() && "Invalid accessor");
1022 return ((const LV *)(const void *)&Data)->Base;
1023}
1024
1025bool APValue::isLValueOnePastTheEnd() const {
1026 assert(isLValue() && "Invalid accessor");
1027 return ((const LV *)(const void *)&Data)->IsOnePastTheEnd;
1028}
1029
1030CharUnits &APValue::getLValueOffset() {
1031 assert(isLValue() && "Invalid accessor");
1032 return ((LV *)(void *)&Data)->Offset;
1033}
1034
1035bool APValue::hasLValuePath() const {
1036 assert(isLValue() && "Invalid accessor");
1037 return ((const LV *)(const char *)&Data)->hasPath();
1038}
1039
1040ArrayRef<APValue::LValuePathEntry> APValue::getLValuePath() const {
1041 assert(isLValue() && hasLValuePath() && "Invalid accessor");
1042 const LV &LVal = *((const LV *)(const char *)&Data);
1043 return {LVal.getPath(), LVal.PathLength};
1044}
1045
1046unsigned APValue::getLValueCallIndex() const {
1047 assert(isLValue() && "Invalid accessor");
1048 return ((const LV *)(const char *)&Data)->Base.getCallIndex();
1049}
1050
1051unsigned APValue::getLValueVersion() const {
1052 assert(isLValue() && "Invalid accessor");
1053 return ((const LV *)(const char *)&Data)->Base.getVersion();
1054}
1055
1056bool APValue::isNullPointer() const {
1057 assert(isLValue() && "Invalid usage");
1058 return ((const LV *)(const char *)&Data)->IsNullPtr;
1059}
1060
1061void APValue::setLValue(LValueBase B, const CharUnits &O, NoLValuePath,
1062 bool IsNullPtr) {
1063 assert(isLValue() && "Invalid accessor");
1064 LV &LVal = *((LV *)(char *)&Data);
1065 LVal.Base = B;
1066 LVal.IsOnePastTheEnd = false;
1067 LVal.Offset = O;
1068 LVal.resizePath(Length: (unsigned)-1);
1069 LVal.IsNullPtr = IsNullPtr;
1070}
1071
1072MutableArrayRef<APValue::LValuePathEntry>
1073APValue::setLValueUninit(LValueBase B, const CharUnits &O, unsigned Size,
1074 bool IsOnePastTheEnd, bool IsNullPtr) {
1075 assert(isLValue() && "Invalid accessor");
1076 LV &LVal = *((LV *)(char *)&Data);
1077 LVal.Base = B;
1078 LVal.IsOnePastTheEnd = IsOnePastTheEnd;
1079 LVal.Offset = O;
1080 LVal.IsNullPtr = IsNullPtr;
1081 LVal.resizePath(Length: Size);
1082 return {LVal.getPath(), Size};
1083}
1084
1085void APValue::setLValue(LValueBase B, const CharUnits &O,
1086 ArrayRef<LValuePathEntry> Path, bool IsOnePastTheEnd,
1087 bool IsNullPtr) {
1088 MutableArrayRef<APValue::LValuePathEntry> InternalPath =
1089 setLValueUninit(B, O, Size: Path.size(), IsOnePastTheEnd, IsNullPtr);
1090 if (Path.size()) {
1091 memcpy(dest: InternalPath.data(), src: Path.data(),
1092 n: Path.size() * sizeof(LValuePathEntry));
1093 }
1094}
1095
1096void APValue::setUnion(const FieldDecl *Field, const APValue &Value) {
1097 assert(isUnion() && "Invalid accessor");
1098 ((UnionData *)(char *)&Data)->Field =
1099 Field ? Field->getCanonicalDecl() : nullptr;
1100 *((UnionData *)(char *)&Data)->Value = Value;
1101}
1102
1103const ValueDecl *APValue::getMemberPointerDecl() const {
1104 assert(isMemberPointer() && "Invalid accessor");
1105 const MemberPointerData &MPD =
1106 *((const MemberPointerData *)(const char *)&Data);
1107 return MPD.MemberAndIsDerivedMember.getPointer();
1108}
1109
1110bool APValue::isMemberPointerToDerivedMember() const {
1111 assert(isMemberPointer() && "Invalid accessor");
1112 const MemberPointerData &MPD =
1113 *((const MemberPointerData *)(const char *)&Data);
1114 return MPD.MemberAndIsDerivedMember.getInt();
1115}
1116
1117ArrayRef<const CXXRecordDecl*> APValue::getMemberPointerPath() const {
1118 assert(isMemberPointer() && "Invalid accessor");
1119 const MemberPointerData &MPD =
1120 *((const MemberPointerData *)(const char *)&Data);
1121 return {MPD.getPath(), MPD.PathLength};
1122}
1123
1124void APValue::MakeLValue() {
1125 assert(isAbsent() && "Bad state change");
1126 static_assert(sizeof(LV) <= DataSize, "LV too big");
1127 new ((void *)(char *)&Data) LV();
1128 Kind = LValue;
1129}
1130
1131void APValue::MakeArray(unsigned InitElts, unsigned Size) {
1132 assert(isAbsent() && "Bad state change");
1133 new ((void *)(char *)&Data) Arr(InitElts, Size);
1134 Kind = Array;
1135}
1136
1137MutableArrayRef<const CXXRecordDecl *>
1138APValue::setMemberPointerUninit(const ValueDecl *Member, bool IsDerivedMember,
1139 unsigned Size) {
1140 assert(isAbsent() && "Bad state change");
1141 MemberPointerData *MPD = new ((void *)(char *)&Data) MemberPointerData;
1142 Kind = MemberPointer;
1143 MPD->MemberAndIsDerivedMember.setPointer(
1144 Member ? cast<ValueDecl>(Val: Member->getCanonicalDecl()) : nullptr);
1145 MPD->MemberAndIsDerivedMember.setInt(IsDerivedMember);
1146 MPD->resizePath(Length: Size);
1147 return {MPD->getPath(), MPD->PathLength};
1148}
1149
1150void APValue::MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember,
1151 ArrayRef<const CXXRecordDecl *> Path) {
1152 MutableArrayRef<const CXXRecordDecl *> InternalPath =
1153 setMemberPointerUninit(Member, IsDerivedMember, Size: Path.size());
1154 for (unsigned I = 0; I != Path.size(); ++I)
1155 InternalPath[I] = Path[I]->getCanonicalDecl();
1156}
1157
1158LinkageInfo LinkageComputer::getLVForValue(const APValue &V,
1159 LVComputationKind computation) {
1160 LinkageInfo LV = LinkageInfo::external();
1161
1162 auto MergeLV = [&](LinkageInfo MergeLV) {
1163 LV.merge(other: MergeLV);
1164 return LV.getLinkage() == Linkage::Internal;
1165 };
1166 auto Merge = [&](const APValue &V) {
1167 return MergeLV(getLVForValue(V, computation));
1168 };
1169
1170 switch (V.getKind()) {
1171 case APValue::None:
1172 case APValue::Indeterminate:
1173 case APValue::Int:
1174 case APValue::Float:
1175 case APValue::FixedPoint:
1176 case APValue::ComplexInt:
1177 case APValue::ComplexFloat:
1178 case APValue::Vector:
1179 case APValue::Matrix:
1180 break;
1181
1182 case APValue::AddrLabelDiff:
1183 // Even for an inline function, it's not reasonable to treat a difference
1184 // between the addresses of labels as an external value.
1185 return LinkageInfo::internal();
1186
1187 case APValue::Struct: {
1188 for (unsigned I = 0, N = V.getStructNumBases(); I != N; ++I)
1189 if (Merge(V.getStructBase(i: I)))
1190 break;
1191 for (unsigned I = 0, N = V.getStructNumFields(); I != N; ++I)
1192 if (Merge(V.getStructField(i: I)))
1193 break;
1194 for (unsigned I = 0, N = V.getStructNumVirtualBases(); I != N; ++I)
1195 if (Merge(V.getStructVirtualBase(i: I)))
1196 break;
1197 break;
1198 }
1199
1200 case APValue::Union:
1201 if (V.getUnionField())
1202 Merge(V.getUnionValue());
1203 break;
1204
1205 case APValue::Array: {
1206 for (unsigned I = 0, N = V.getArrayInitializedElts(); I != N; ++I)
1207 if (Merge(V.getArrayInitializedElt(I)))
1208 break;
1209 if (V.hasArrayFiller())
1210 Merge(V.getArrayFiller());
1211 break;
1212 }
1213
1214 case APValue::LValue: {
1215 if (!V.getLValueBase()) {
1216 // Null or absolute address: this is external.
1217 } else if (const auto *VD =
1218 V.getLValueBase().dyn_cast<const ValueDecl *>()) {
1219 if (VD && MergeLV(getLVForDecl(D: VD, computation)))
1220 break;
1221 } else if (const auto TI = V.getLValueBase().dyn_cast<TypeInfoLValue>()) {
1222 if (MergeLV(getLVForType(T: *TI.getType(), computation)))
1223 break;
1224 } else if (const Expr *E = V.getLValueBase().dyn_cast<const Expr *>()) {
1225 // Almost all expression bases are internal. The exception is
1226 // lifetime-extended temporaries.
1227 // FIXME: These should be modeled as having the
1228 // LifetimeExtendedTemporaryDecl itself as the base.
1229 // FIXME: If we permit Objective-C object literals in template arguments,
1230 // they should not imply internal linkage.
1231 auto *MTE = dyn_cast<MaterializeTemporaryExpr>(Val: E);
1232 if (!MTE || MTE->getStorageDuration() == SD_FullExpression)
1233 return LinkageInfo::internal();
1234 if (MergeLV(getLVForDecl(D: MTE->getExtendingDecl(), computation)))
1235 break;
1236 } else {
1237 assert(V.getLValueBase().is<DynamicAllocLValue>() &&
1238 "unexpected LValueBase kind");
1239 return LinkageInfo::internal();
1240 }
1241 // The lvalue path doesn't matter: pointers to all subobjects always have
1242 // the same visibility as pointers to the complete object.
1243 break;
1244 }
1245
1246 case APValue::MemberPointer:
1247 if (const NamedDecl *D = V.getMemberPointerDecl())
1248 MergeLV(getLVForDecl(D, computation));
1249 // Note that we could have a base-to-derived conversion here to a member of
1250 // a derived class with less linkage/visibility. That's covered by the
1251 // linkage and visibility of the value's type.
1252 break;
1253 }
1254
1255 return LV;
1256}
1257