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