clang 24.0.0git
APValue.cpp
Go to the documentation of this file.
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"
16#include "clang/AST/DeclCXX.h"
17#include "clang/AST/Expr.h"
18#include "clang/AST/ExprCXX.h"
19#include "clang/AST/Type.h"
20#include "llvm/Support/ErrorHandling.h"
21#include "llvm/Support/raw_ostream.h"
22using namespace clang;
23
24static bool visitAPValue(const APValue &Value,
25 llvm::function_ref<bool(const APValue &)> Visitor) {
26 if (!Visitor(Value))
27 return false;
28
29 switch (Value.getKind()) {
30 case APValue::None:
32 case APValue::Int:
33 case APValue::Float:
37 case APValue::LValue:
41 return true;
42
43 case APValue::Vector:
44 for (unsigned I = 0, N = Value.getVectorLength(); I != N; ++I)
45 if (!visitAPValue(Value.getVectorElt(I), Visitor))
46 return false;
47 return true;
48
49 case APValue::Matrix:
50 for (unsigned I = 0, N = Value.getMatrixNumElements(); I != N; ++I)
51 if (!visitAPValue(Value.getMatrixElt(I), Visitor))
52 return false;
53 return true;
54
55 case APValue::Array:
56 for (unsigned I = 0, N = Value.getArrayInitializedElts(); I != N; ++I)
57 if (!visitAPValue(Value.getArrayInitializedElt(I), Visitor))
58 return false;
59 return !Value.hasArrayFiller() ||
60 visitAPValue(Value.getArrayFiller(), Visitor);
61
62 case APValue::Struct:
63 for (unsigned I = 0, N = Value.getStructNumBases(); I != N; ++I)
64 if (!visitAPValue(Value.getStructBase(I), Visitor))
65 return false;
66 for (unsigned I = 0, N = Value.getStructNumFields(); I != N; ++I)
67 if (!visitAPValue(Value.getStructField(I), Visitor))
68 return false;
69 for (unsigned I = 0, N = Value.getStructNumVirtualBases(); I != N; ++I)
70 if (!visitAPValue(Value.getStructVirtualBase(I), Visitor))
71 return false;
72 return true;
73
74 case APValue::Union:
75 return !Value.getUnionField() ||
76 visitAPValue(Value.getUnionValue(), Visitor);
77 }
78 llvm_unreachable("unknown APValue kind");
79}
80
81void APValue::visit(llvm::function_ref<bool(const APValue &)> Visitor) const {
82 visitAPValue(*this, Visitor);
83}
84
85/// The identity of a type_info object depends on the canonical unqualified
86/// type only.
88 : T(T->getCanonicalTypeUnqualified().getTypePtr()) {}
89
90void TypeInfoLValue::print(llvm::raw_ostream &Out,
91 const PrintingPolicy &Policy) const {
92 Out << "typeid(";
93 QualType(getType(), 0).print(Out, Policy);
94 Out << ")";
95}
96
97static_assert(
99 alignof(Type),
100 "Type is insufficiently aligned");
101
102APValue::LValueBase::LValueBase(const ValueDecl *P, unsigned I, unsigned V)
103 : Ptr(P ? cast<ValueDecl>(P->getCanonicalDecl()) : nullptr), Local{I, V} {}
104APValue::LValueBase::LValueBase(const Expr *P, unsigned I, unsigned V)
105 : Ptr(P), Local{I, V} {}
106
108 QualType Type) {
110 Base.Ptr = LV;
111 Base.DynamicAllocType = Type.getAsOpaquePtr();
112 return Base;
113}
114
118 Base.Ptr = LV;
119 Base.TypeInfoType = TypeInfo.getAsOpaquePtr();
120 return Base;
121}
122
124 if (!*this) return QualType();
125 if (const ValueDecl *D = dyn_cast<const ValueDecl*>()) {
126 // FIXME: It's unclear where we're supposed to take the type from, and
127 // this actually matters for arrays of unknown bound. Eg:
128 //
129 // extern int arr[]; void f() { extern int arr[3]; };
130 // constexpr int *p = &arr[1]; // valid?
131 //
132 // For now, we take the most complete type we can find.
133 for (auto *Redecl = cast<ValueDecl>(D->getMostRecentDecl()); Redecl;
134 Redecl = cast_or_null<ValueDecl>(Redecl->getPreviousDecl())) {
135 QualType T = Redecl->getType();
136 if (!T->isIncompleteArrayType())
137 return T;
138 }
139 return D->getType();
140 }
141
142 if (is<TypeInfoLValue>())
143 return getTypeInfoType();
144
146 return getDynamicAllocType();
147
148 const Expr *Base = get<const Expr*>();
149
150 // For a materialized temporary, the type of the temporary we materialized
151 // may not be the type of the expression.
152 if (const MaterializeTemporaryExpr *MTE =
153 llvm::dyn_cast<MaterializeTemporaryExpr>(Base)) {
156 const Expr *Temp = MTE->getSubExpr();
157 const Expr *Inner = Temp->skipRValueSubobjectAdjustments(CommaLHSs,
158 Adjustments);
159 // Keep any cv-qualifiers from the reference if we generated a temporary
160 // for it directly. Otherwise use the type after adjustment.
161 if (!Adjustments.empty())
162 return Inner->getType();
163 }
164
165 return Base->getType();
166}
167
170 : Local.CallIndex;
171}
172
174 return (is<TypeInfoLValue>() || is<DynamicAllocLValue>()) ? 0 : Local.Version;
175}
176
178 assert(is<TypeInfoLValue>() && "not a type_info lvalue");
180}
181
183 assert(is<DynamicAllocLValue>() && "not a dynamic allocation lvalue");
185}
186
187void APValue::LValueBase::Profile(llvm::FoldingSetNodeID &ID) const {
188 ID.AddPointer(Ptr.getOpaqueValue());
190 return;
191 ID.AddInteger(Local.CallIndex);
192 ID.AddInteger(Local.Version);
193}
194
195namespace clang {
197 const APValue::LValueBase &RHS) {
198 if (LHS.Ptr != RHS.Ptr)
199 return false;
200 if (LHS.is<TypeInfoLValue>() || LHS.is<DynamicAllocLValue>())
201 return true;
202 return LHS.Local.CallIndex == RHS.Local.CallIndex &&
203 LHS.Local.Version == RHS.Local.Version;
204}
205}
206
208 if (const Decl *D = BaseOrMember.getPointer())
209 BaseOrMember.setPointer(D->getCanonicalDecl());
210 Value = reinterpret_cast<uintptr_t>(BaseOrMember.getOpaqueValue());
211}
212
213void APValue::LValuePathEntry::Profile(llvm::FoldingSetNodeID &ID) const {
214 ID.AddInteger(Value);
215}
216
220
224
225namespace {
226 struct LVBase {
228 CharUnits Offset;
229 unsigned PathLength;
230 bool IsNullPtr : 1;
231 bool IsOnePastTheEnd : 1;
232 };
233}
234
236 return Ptr.getOpaqueValue();
237}
238
240 return Ptr.isNull();
241}
242
243APValue::LValueBase::operator bool () const {
244 return static_cast<bool>(Ptr);
245}
246
247namespace clang {
248llvm::hash_code hash_value(const APValue::LValueBase &Base) {
249 if (Base.is<TypeInfoLValue>() || Base.is<DynamicAllocLValue>())
250 return llvm::hash_value(Base.getOpaqueValue());
251 return llvm::hash_combine(Base.getOpaqueValue(), Base.getCallIndex(),
252 Base.getVersion());
253}
254}
255
256unsigned llvm::DenseMapInfo<clang::APValue::LValueBase>::getHashValue(
258 return hash_value(Base);
259}
260
261bool llvm::DenseMapInfo<clang::APValue::LValueBase>::isEqual(
263 const clang::APValue::LValueBase &RHS) {
264 return LHS == RHS;
265}
266
267struct APValue::LV : LVBase {
268 static const unsigned InlinePathSpace =
269 (DataSize - sizeof(LVBase)) / sizeof(LValuePathEntry);
270
271 /// Path - The sequence of base classes, fields and array indices to follow to
272 /// walk from Base to the subobject. When performing GCC-style folding, there
273 /// may not be such a path.
274 union {
277 };
278
279 LV() { PathLength = (unsigned)-1; }
280 ~LV() { resizePath(0); }
281
282 void resizePath(unsigned Length) {
283 if (Length == PathLength)
284 return;
285 if (hasPathPtr())
286 delete [] PathPtr;
287 PathLength = Length;
288 if (hasPathPtr())
289 PathPtr = new LValuePathEntry[Length];
290 }
291
292 bool hasPath() const { return PathLength != (unsigned)-1; }
293 bool hasPathPtr() const { return hasPath() && PathLength > InlinePathSpace; }
294
296 const LValuePathEntry *getPath() const {
297 return hasPathPtr() ? PathPtr : Path;
298 }
299};
300
301namespace {
302 struct MemberPointerBase {
303 llvm::PointerIntPair<const ValueDecl*, 1, bool> MemberAndIsDerivedMember;
304 unsigned PathLength;
305 };
306}
307
308struct APValue::MemberPointerData : MemberPointerBase {
309 static const unsigned InlinePathSpace =
310 (DataSize - sizeof(MemberPointerBase)) / sizeof(const CXXRecordDecl*);
311 typedef const CXXRecordDecl *PathElem;
312 union {
315 };
316
317 MemberPointerData() { PathLength = 0; }
319
320 void resizePath(unsigned Length) {
321 if (Length == PathLength)
322 return;
323 if (hasPathPtr())
324 delete [] PathPtr;
325 PathLength = Length;
326 if (hasPathPtr())
327 PathPtr = new PathElem[Length];
328 }
329
330 bool hasPathPtr() const { return PathLength > InlinePathSpace; }
331
333 const PathElem *getPath() const {
334 return hasPathPtr() ? PathPtr : Path;
335 }
336};
337
338// FIXME: Reduce the malloc traffic here.
339
340APValue::Arr::Arr(unsigned NumElts, unsigned Size) :
341 Elts(new APValue[NumElts + (NumElts != Size ? 1 : 0)]),
342 NumElts(NumElts), ArrSize(Size) {}
343APValue::Arr::~Arr() { delete [] Elts; }
344
345APValue::StructData::StructData(unsigned NumBases, unsigned NumFields,
346 unsigned NumVirtualBases)
347 : Elts(new APValue[NumBases + NumFields + NumVirtualBases]),
348 NumBases(NumBases), NumFields(NumFields),
349 NumVirtualBases(NumVirtualBases) {}
350
351APValue::StructData::~StructData() {
352 delete [] Elts;
353}
354
355APValue::UnionData::UnionData() : Field(nullptr), Value(new APValue) {}
356APValue::UnionData::~UnionData () {
357 delete Value;
358}
359
361 : Kind(None), AllowConstexprUnknown(RHS.AllowConstexprUnknown) {
362 switch (RHS.getKind()) {
363 case None:
364 case Indeterminate:
365 Kind = RHS.getKind();
366 break;
367 case Int:
368 MakeInt(RHS.getInt());
369 break;
370 case Float:
371 MakeFloat(RHS.getFloat());
372 break;
373 case FixedPoint: {
374 APFixedPoint FXCopy = RHS.getFixedPoint();
375 MakeFixedPoint(std::move(FXCopy));
376 break;
377 }
378 case Vector:
379 MakeVector();
380 setVector(((const Vec *)(const char *)&RHS.Data)->Elts,
381 RHS.getVectorLength());
382 break;
383 case Matrix:
384 MakeMatrix();
385 setMatrix(((const Mat *)(const char *)&RHS.Data)->Elts,
387 break;
388 case ComplexInt:
389 MakeComplexInt();
391 break;
392 case ComplexFloat:
393 MakeComplexFloat();
395 break;
396 case LValue:
397 MakeLValue();
398 if (RHS.hasLValuePath())
401 else
403 RHS.isNullPointer());
404 break;
405 case Array:
406 MakeArray(RHS.getArrayInitializedElts(), RHS.getArraySize());
407 for (unsigned I = 0, N = RHS.getArrayInitializedElts(); I != N; ++I)
409 if (RHS.hasArrayFiller())
411 break;
412 case Struct:
413 MakeStruct(RHS.getStructNumBases(), RHS.getStructNumFields(),
415 for (unsigned I = 0, N = RHS.getStructNumBases(); I != N; ++I)
416 getStructBase(I) = RHS.getStructBase(I);
417 for (unsigned I = 0, N = RHS.getStructNumFields(); I != N; ++I)
418 getStructField(I) = RHS.getStructField(I);
419 for (unsigned I = 0, N = RHS.getStructNumVirtualBases(); I != N; ++I)
421 break;
422 case Union:
423 MakeUnion();
425 break;
426 case MemberPointer:
427 MakeMemberPointer(RHS.getMemberPointerDecl(),
430 break;
431 case AddrLabelDiff:
432 MakeAddrLabelDiff();
434 break;
435 case Reflection:
436 MakeReflection(RHS.getReflectionOperandKind(),
438 break;
439 }
440}
441
443 : Kind(RHS.Kind), AllowConstexprUnknown(RHS.AllowConstexprUnknown),
444 Data(RHS.Data) {
445 RHS.Kind = None;
446}
447
449 if (this != &RHS)
450 *this = APValue(RHS);
451
452 return *this;
453}
454
456 if (this != &RHS) {
457 if (Kind != None && Kind != Indeterminate)
458 DestroyDataAndMakeUninit();
459 Kind = RHS.Kind;
460 Data = RHS.Data;
461 AllowConstexprUnknown = RHS.AllowConstexprUnknown;
462 RHS.Kind = None;
463 }
464 return *this;
465}
466
467void APValue::DestroyDataAndMakeUninit() {
468 if (Kind == Int)
469 ((APSInt *)(char *)&Data)->~APSInt();
470 else if (Kind == Float)
471 ((APFloat *)(char *)&Data)->~APFloat();
472 else if (Kind == FixedPoint)
473 ((APFixedPoint *)(char *)&Data)->~APFixedPoint();
474 else if (Kind == Vector)
475 ((Vec *)(char *)&Data)->~Vec();
476 else if (Kind == Matrix)
477 ((Mat *)(char *)&Data)->~Mat();
478 else if (Kind == ComplexInt)
479 ((ComplexAPSInt *)(char *)&Data)->~ComplexAPSInt();
480 else if (Kind == ComplexFloat)
481 ((ComplexAPFloat *)(char *)&Data)->~ComplexAPFloat();
482 else if (Kind == LValue)
483 ((LV *)(char *)&Data)->~LV();
484 else if (Kind == Array)
485 ((Arr *)(char *)&Data)->~Arr();
486 else if (Kind == Struct)
487 ((StructData *)(char *)&Data)->~StructData();
488 else if (Kind == Union)
489 ((UnionData *)(char *)&Data)->~UnionData();
490 else if (Kind == MemberPointer)
491 ((MemberPointerData *)(char *)&Data)->~MemberPointerData();
492 else if (Kind == AddrLabelDiff)
493 ((AddrLabelDiffData *)(char *)&Data)->~AddrLabelDiffData();
494 else if (Kind == Reflection)
495 ((ReflectionData *)(char *)&Data)->~ReflectionData();
496 Kind = None;
497 AllowConstexprUnknown = false;
498}
499
501 switch (getKind()) {
502 case None:
503 case Indeterminate:
504 case AddrLabelDiff:
505 case Reflection:
506 return false;
507 case Struct:
508 case Union:
509 case Array:
510 case Vector:
511 case Matrix:
512 return true;
513 case Int:
514 return getInt().needsCleanup();
515 case Float:
516 return getFloat().needsCleanup();
517 case FixedPoint:
518 return getFixedPoint().getValue().needsCleanup();
519 case ComplexFloat:
522 "In _Complex float types, real and imaginary values always have the "
523 "same size.");
524 return getComplexFloatReal().needsCleanup();
525 case ComplexInt:
526 assert(getComplexIntImag().needsCleanup() ==
528 "In _Complex int types, real and imaginary values must have the "
529 "same size.");
530 return getComplexIntReal().needsCleanup();
531 case LValue:
532 return reinterpret_cast<const LV *>(&Data)->hasPathPtr();
533 case MemberPointer:
534 return reinterpret_cast<const MemberPointerData *>(&Data)->hasPathPtr();
535 }
536 llvm_unreachable("Unknown APValue kind!");
537}
538
540 std::swap(Kind, RHS.Kind);
541 std::swap(Data, RHS.Data);
542 // We can't use std::swap w/ bit-fields
543 bool tmp = AllowConstexprUnknown;
544 AllowConstexprUnknown = RHS.AllowConstexprUnknown;
545 RHS.AllowConstexprUnknown = tmp;
546}
547
548/// Profile the value of an APInt, excluding its bit-width.
549static void profileIntValue(llvm::FoldingSetNodeID &ID, const llvm::APInt &V) {
550 for (unsigned I = 0, N = V.getBitWidth(); I < N; I += 32)
551 ID.AddInteger((uint32_t)V.extractBitsAsZExtValue(std::min(32u, N - I), I));
552}
553
554/// Unwrap reflected type for profiling
555static void profileTypeReflection(llvm::FoldingSetNodeID &ID, QualType QT) {
556 // TODO(Reflection)
557
559 if (const auto *TDT = QT->getAs<TypedefType>()) {
560 ID.AddBoolean(true);
561 ID.AddPointer(TDT->getDecl()->getCanonicalDecl());
562 return;
563 }
564 }
565
566 ID.AddBoolean(false);
567 QT.getCanonicalType().Profile(ID);
568}
569
570static void profileReflection(llvm::FoldingSetNodeID &ID, APValue V) {
571 ID.AddInteger(static_cast<int>(V.getReflectionOperandKind()));
572 switch (V.getReflectionOperandKind()) {
574 return;
576 const TypeSourceInfo *Info =
577 static_cast<const TypeSourceInfo *>(V.getReflectionOpaqueOperand());
578 profileTypeReflection(ID, Info->getType());
579 return;
580 }
581 }
582 assert(false && "unknown or unimplemented reflection entities");
583}
584
585void APValue::Profile(llvm::FoldingSetNodeID &ID) const {
586 // Note that our profiling assumes that only APValues of the same type are
587 // ever compared. As a result, we don't consider collisions that could only
588 // happen if the types are different. (For example, structs with different
589 // numbers of members could profile the same.)
590
591 ID.AddInteger(Kind);
592
593 switch (Kind) {
594 case None:
595 case Indeterminate:
596 return;
597
598 case AddrLabelDiff:
599 ID.AddPointer(getAddrLabelDiffLHS()->getLabel()->getCanonicalDecl());
600 ID.AddPointer(getAddrLabelDiffRHS()->getLabel()->getCanonicalDecl());
601 return;
602
603 case Struct:
604 for (unsigned I = 0, N = getStructNumBases(); I != N; ++I)
605 getStructBase(I).Profile(ID);
606 for (unsigned I = 0, N = getStructNumFields(); I != N; ++I)
607 getStructField(I).Profile(ID);
608 for (unsigned I = 0, N = getStructNumVirtualBases(); I != N; ++I)
610 return;
611
612 case Union:
613 if (!getUnionField()) {
614 ID.AddInteger(0);
615 return;
616 }
617 ID.AddInteger(getUnionField()->getFieldIndex() + 1);
619 return;
620
621 case Array: {
622 if (getArraySize() == 0)
623 return;
624
625 // The profile should not depend on whether the array is expanded or
626 // not, but we don't want to profile the array filler many times for
627 // a large array. So treat all equal trailing elements as the filler.
628 // Elements are profiled in reverse order to support this, and the
629 // first profiled element is followed by a count. For example:
630 //
631 // ['a', 'c', 'x', 'x', 'x'] is profiled as
632 // [5, 'x', 3, 'c', 'a']
633 llvm::FoldingSetNodeID FillerID;
636 .Profile(FillerID);
637 ID.AddNodeID(FillerID);
638 unsigned NumFillers = getArraySize() - getArrayInitializedElts();
639 unsigned N = getArrayInitializedElts();
640
641 // Count the number of elements equal to the last one. This loop ends
642 // by adding an integer indicating the number of such elements, with
643 // N set to the number of elements left to profile.
644 while (true) {
645 if (N == 0) {
646 // All elements are fillers.
647 assert(NumFillers == getArraySize());
648 ID.AddInteger(NumFillers);
649 break;
650 }
651
652 // No need to check if the last element is equal to the last
653 // element.
654 if (N != getArraySize()) {
655 llvm::FoldingSetNodeID ElemID;
656 getArrayInitializedElt(N - 1).Profile(ElemID);
657 if (ElemID != FillerID) {
658 ID.AddInteger(NumFillers);
659 ID.AddNodeID(ElemID);
660 --N;
661 break;
662 }
663 }
664
665 // This is a filler.
666 ++NumFillers;
667 --N;
668 }
669
670 // Emit the remaining elements.
671 for (; N != 0; --N)
673 return;
674 }
675
676 case Vector:
677 for (unsigned I = 0, N = getVectorLength(); I != N; ++I)
678 getVectorElt(I).Profile(ID);
679 return;
680
681 case Matrix:
682 for (unsigned R = 0, N = getMatrixNumRows(); R != N; ++R)
683 for (unsigned C = 0, M = getMatrixNumColumns(); C != M; ++C)
684 getMatrixElt(R, C).Profile(ID);
685 return;
686
687 case Int:
688 profileIntValue(ID, getInt());
689 return;
690
691 case Float:
692 profileIntValue(ID, getFloat().bitcastToAPInt());
693 return;
694
695 case FixedPoint:
696 profileIntValue(ID, getFixedPoint().getValue());
697 return;
698
699 case ComplexFloat:
700 profileIntValue(ID, getComplexFloatReal().bitcastToAPInt());
701 profileIntValue(ID, getComplexFloatImag().bitcastToAPInt());
702 return;
703
704 case ComplexInt:
707 return;
708
709 case LValue:
711 ID.AddInteger(getLValueOffset().getQuantity());
712 ID.AddInteger((isNullPointer() ? 1 : 0) |
713 (isLValueOnePastTheEnd() ? 2 : 0) |
714 (hasLValuePath() ? 4 : 0));
715 if (hasLValuePath()) {
716 ID.AddInteger(getLValuePath().size());
717 // For uniqueness, we only need to profile the entries corresponding
718 // to union members, but we don't have the type here so we don't know
719 // how to interpret the entries.
721 E.Profile(ID);
722 }
723 return;
724
725 case MemberPointer:
726 ID.AddPointer(getMemberPointerDecl());
727 ID.AddInteger(isMemberPointerToDerivedMember());
728 for (const CXXRecordDecl *D : getMemberPointerPath())
729 ID.AddPointer(D);
730 return;
731 case Reflection:
732 profileReflection(ID, *this);
733 return;
734 }
735
736 llvm_unreachable("Unknown APValue kind!");
737}
738
739static double GetApproxValue(const llvm::APFloat &F) {
740 llvm::APFloat V = F;
741 bool ignored;
742 V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven,
743 &ignored);
744 return V.convertToDouble();
745}
746
747static bool TryPrintAsStringLiteral(raw_ostream &Out,
748 const PrintingPolicy &Policy,
749 const ArrayType *ATy,
751 if (Inits.empty())
752 return false;
753
754 QualType Ty = ATy->getElementType();
755 if (!Ty->isAnyCharacterType())
756 return false;
757
758 // Nothing we can do about a sequence that is not null-terminated
759 if (!Inits.back().isInt() || !Inits.back().getInt().isZero())
760 return false;
761
762 Inits = Inits.drop_back();
763
765 Buf.push_back('"');
766
767 // Better than printing a two-digit sequence of 10 integers.
768 constexpr size_t MaxN = 36;
769 StringRef Ellipsis;
770 if (Inits.size() > MaxN && !Policy.EntireContentsOfLargeArray) {
771 Ellipsis = "[...]";
772 Inits =
773 Inits.take_front(std::min(MaxN - Ellipsis.size() / 2, Inits.size()));
774 }
775
776 for (auto &Val : Inits) {
777 if (!Val.isInt())
778 return false;
779 int64_t Char64 = Val.getInt().getExtValue();
780 if (!isASCII(Char64))
781 return false; // Bye bye, see you in integers.
782 auto Ch = static_cast<unsigned char>(Char64);
783 // The diagnostic message is 'quoted'
784 StringRef Escaped = escapeCStyle<EscapeChar::SingleAndDouble>(Ch);
785 if (Escaped.empty()) {
786 if (!isPrintable(Ch))
787 return false;
788 Buf.emplace_back(Ch);
789 } else {
790 Buf.append(Escaped);
791 }
792 }
793
794 Buf.append(Ellipsis);
795 Buf.push_back('"');
796
797 if (Ty->isWideCharType())
798 Out << 'L';
799 else if (Ty->isChar8Type())
800 Out << "u8";
801 else if (Ty->isChar16Type())
802 Out << 'u';
803 else if (Ty->isChar32Type())
804 Out << 'U';
805
806 Out << Buf;
807 return true;
808}
809
810void APValue::printPretty(raw_ostream &Out, const ASTContext &Ctx,
811 QualType Ty) const {
812 printPretty(Out, Ctx.getPrintingPolicy(), Ty, &Ctx);
813}
814
815void APValue::printPretty(raw_ostream &Out, const PrintingPolicy &Policy,
816 QualType Ty, const ASTContext *Ctx) const {
817 // There are no objects of type 'void', but values of this type can be
818 // returned from functions.
819 if (Ty->isVoidType()) {
820 Out << "void()";
821 return;
822 }
823
824 if (const auto *AT = Ty->getAs<AtomicType>())
825 Ty = AT->getValueType();
826
827 switch (getKind()) {
828 case APValue::None:
829 Out << "<out of lifetime>";
830 return;
832 Out << "<uninitialized>";
833 return;
834 case APValue::Int:
835 if (Ty->isBooleanType())
836 Out << (getInt().getBoolValue() ? "true" : "false");
837 else
838 Out << getInt();
839 return;
840 case APValue::Float:
841 Out << GetApproxValue(getFloat());
842 return;
844 Out << getFixedPoint();
845 return;
846 case APValue::Vector: {
847 Out << '{';
848 QualType ElemTy = Ty->castAs<VectorType>()->getElementType();
849 getVectorElt(0).printPretty(Out, Policy, ElemTy, Ctx);
850 for (unsigned i = 1; i != getVectorLength(); ++i) {
851 Out << ", ";
852 getVectorElt(i).printPretty(Out, Policy, ElemTy, Ctx);
853 }
854 Out << '}';
855 return;
856 }
857 case APValue::Matrix: {
858 const auto *MT = Ty->castAs<ConstantMatrixType>();
859 QualType ElemTy = MT->getElementType();
860 Out << '{';
861 for (unsigned R = 0; R < getMatrixNumRows(); ++R) {
862 if (R != 0)
863 Out << ", ";
864 Out << '{';
865 for (unsigned C = 0; C < getMatrixNumColumns(); ++C) {
866 if (C != 0)
867 Out << ", ";
868 getMatrixElt(R, C).printPretty(Out, Policy, ElemTy, Ctx);
869 }
870 Out << '}';
871 }
872 Out << '}';
873 return;
874 }
876 Out << getComplexIntReal() << "+" << getComplexIntImag() << "i";
877 return;
879 Out << GetApproxValue(getComplexFloatReal()) << "+"
881 return;
882 case APValue::LValue: {
883 bool IsReference = Ty->isReferenceType();
884 QualType InnerTy
885 = IsReference ? Ty.getNonReferenceType() : Ty->getPointeeType();
886 if (InnerTy.isNull())
887 InnerTy = Ty;
888
890 if (!Base) {
891 if (isNullPointer()) {
892 Out << (Policy.Nullptr ? "nullptr" : "0");
893 } else if (IsReference) {
894 Out << "*(" << InnerTy.stream(Policy) << "*)"
896 } else {
897 Out << "(" << Ty.stream(Policy) << ")"
899 }
900 return;
901 }
902
903 if (!hasLValuePath()) {
904 // No lvalue path: just print the offset.
906 CharUnits S = Ctx ? Ctx->getTypeSizeInCharsIfKnown(InnerTy).value_or(
908 : CharUnits::Zero();
909 if (!O.isZero()) {
910 if (IsReference)
911 Out << "*(";
912 if (S.isZero() || !O.isMultipleOf(S)) {
913 Out << "(char*)";
914 S = CharUnits::One();
915 }
916 Out << '&';
917 } else if (!IsReference) {
918 Out << '&';
919 }
920
921 if (const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>())
922 Out << *VD;
923 else if (TypeInfoLValue TI = Base.dyn_cast<TypeInfoLValue>()) {
924 TI.print(Out, Policy);
925 } else if (DynamicAllocLValue DA = Base.dyn_cast<DynamicAllocLValue>()) {
926 Out << "{*new "
927 << Base.getDynamicAllocType().stream(Policy) << "#"
928 << DA.getIndex() << "}";
929 } else {
930 assert(Base.get<const Expr *>() != nullptr &&
931 "Expecting non-null Expr");
932 Base.get<const Expr*>()->printPretty(Out, nullptr, Policy);
933 }
934
935 if (!O.isZero()) {
936 Out << " + " << (O / S);
937 if (IsReference)
938 Out << ')';
939 }
940 return;
941 }
942
943 // We have an lvalue path. Print it out nicely.
944 if (!IsReference)
945 Out << '&';
946 else if (isLValueOnePastTheEnd())
947 Out << "*(&";
948
949 QualType ElemTy = Base.getType().getNonReferenceType();
950 if (const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>()) {
951 Out << *VD;
952 } else if (TypeInfoLValue TI = Base.dyn_cast<TypeInfoLValue>()) {
953 TI.print(Out, Policy);
954 } else if (DynamicAllocLValue DA = Base.dyn_cast<DynamicAllocLValue>()) {
955 Out << "{*new " << Base.getDynamicAllocType().stream(Policy) << "#"
956 << DA.getIndex() << "}";
957 } else {
958 const Expr *E = Base.get<const Expr*>();
959 assert(E != nullptr && "Expecting non-null Expr");
960 E->printPretty(Out, nullptr, Policy);
961 }
962
964 const CXXRecordDecl *CastToBase = nullptr;
965 for (unsigned I = 0, N = Path.size(); I != N; ++I) {
966 if (ElemTy->isRecordType()) {
967 // The lvalue refers to a class type, so the next path entry is a base
968 // or member.
969 const Decl *BaseOrMember = Path[I].getAsBaseOrMember().getPointer();
970 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(BaseOrMember)) {
971 CastToBase = RD;
972 // Leave ElemTy referring to the most-derived class. The actual type
973 // doesn't matter except for array types.
974 } else {
975 const ValueDecl *VD = cast<ValueDecl>(BaseOrMember);
976 Out << ".";
977 if (CastToBase)
978 Out << *CastToBase << "::";
979 Out << *VD;
980 ElemTy = VD->getType();
981 }
982 } else if (ElemTy->isAnyComplexType()) {
983 // The lvalue refers to a complex type
984 Out << (Path[I].getAsArrayIndex() == 0 ? ".real" : ".imag");
985 ElemTy = ElemTy->castAs<ComplexType>()->getElementType();
986 } else {
987 // The lvalue must refer to an array.
988 Out << '[' << Path[I].getAsArrayIndex() << ']';
989 ElemTy = ElemTy->castAsArrayTypeUnsafe()->getElementType();
990 }
991 }
992
993 // Handle formatting of one-past-the-end lvalues.
994 if (isLValueOnePastTheEnd()) {
995 // FIXME: If CastToBase is non-0, we should prefix the output with
996 // "(CastToBase*)".
997 Out << " + 1";
998 if (IsReference)
999 Out << ')';
1000 }
1001 return;
1002 }
1003 case APValue::Array: {
1004 const ArrayType *AT = Ty->castAsArrayTypeUnsafe();
1005 unsigned N = getArrayInitializedElts();
1006 if (N != 0 && TryPrintAsStringLiteral(Out, Policy, AT,
1007 {&getArrayInitializedElt(0), N}))
1008 return;
1009 QualType ElemTy = AT->getElementType();
1010 Out << '{';
1011 unsigned I = 0;
1012 switch (N) {
1013 case 0:
1014 for (; I != N; ++I) {
1015 Out << ", ";
1016 if (I == 10 && !Policy.EntireContentsOfLargeArray) {
1017 Out << "...}";
1018 return;
1019 }
1020 [[fallthrough]];
1021 default:
1022 getArrayInitializedElt(I).printPretty(Out, Policy, ElemTy, Ctx);
1023 }
1024 }
1025 Out << '}';
1026 return;
1027 }
1028 case APValue::Struct: {
1029 Out << '{';
1030 llvm::ListSeparator Comma;
1031 const auto *RD = Ty->castAsRecordDecl();
1032 if (unsigned N = getStructNumBases()) {
1033 const CXXRecordDecl *CD = cast<CXXRecordDecl>(RD);
1035 for (unsigned I = 0; I != N; ++I, ++BI) {
1036 assert(BI != CD->bases_end());
1037 Out << Comma;
1038 getStructBase(I).printPretty(Out, Policy, BI->getType(), Ctx);
1039 }
1040 }
1041 for (const auto *FI : RD->fields()) {
1042 Out << Comma;
1043 if (FI->isUnnamedBitField())
1044 continue;
1045 getStructField(FI->getFieldIndex())
1046 .printPretty(Out, Policy, FI->getType(), Ctx);
1047 }
1048 if (unsigned N = getStructNumVirtualBases()) {
1049 const CXXRecordDecl *CD = cast<CXXRecordDecl>(RD);
1051 for (unsigned I = 0; I != N; ++I, ++BI) {
1052 assert(BI != CD->vbases_end());
1053 Out << Comma;
1054 getStructVirtualBase(I).printPretty(Out, Policy, BI->getType(), Ctx);
1055 }
1056 }
1057 Out << '}';
1058 return;
1059 }
1060 case APValue::Union:
1061 Out << '{';
1062 if (const FieldDecl *FD = getUnionField()) {
1063 Out << "." << *FD << " = ";
1064 getUnionValue().printPretty(Out, Policy, FD->getType(), Ctx);
1065 }
1066 Out << '}';
1067 return;
1069 // FIXME: This is not enough to unambiguously identify the member in a
1070 // multiple-inheritance scenario.
1071 if (const ValueDecl *VD = getMemberPointerDecl()) {
1072 Out << '&' << *cast<CXXRecordDecl>(VD->getDeclContext()) << "::" << *VD;
1073 return;
1074 }
1075 Out << "0";
1076 return;
1078 Out << "&&" << getAddrLabelDiffLHS()->getLabel()->getName();
1079 Out << " - ";
1080 Out << "&&" << getAddrLabelDiffRHS()->getLabel()->getName();
1081 return;
1083 switch (getReflectionOperandKind()) {
1085 Out << "std::meta::info{}";
1086 break;
1087 case ReflectionKind::Type: {
1088 const auto *TInfo =
1089 static_cast<const TypeSourceInfo *>(getReflectionOpaqueOperand());
1090 Out << "^^" << TInfo->getType().stream(Policy);
1091 break;
1092 }
1093 }
1094 return;
1095 }
1096 llvm_unreachable("Unknown APValue kind!");
1097}
1098
1099std::string APValue::getAsString(const ASTContext &Ctx, QualType Ty) const {
1100 std::string Result;
1101 llvm::raw_string_ostream Out(Result);
1102 printPretty(Out, Ctx, Ty);
1103 return Result;
1104}
1105
1107 const ASTContext &Ctx) const {
1108 if (isInt()) {
1109 Result = getInt();
1110 return true;
1111 }
1112
1113 if (isLValue() && isNullPointer()) {
1114 Result = Ctx.MakeIntValue(Ctx.getTargetNullPointerValue(SrcTy), SrcTy);
1115 return true;
1116 }
1117
1118 if (isLValue() && !getLValueBase()) {
1119 Result = Ctx.MakeIntValue(getLValueOffset().getQuantity(), SrcTy);
1120 return true;
1121 }
1122
1123 return false;
1124}
1125
1127 assert(isLValue() && "Invalid accessor");
1128 return ((const LV *)(const void *)&Data)->Base;
1129}
1130
1132 assert(isLValue() && "Invalid accessor");
1133 return ((const LV *)(const void *)&Data)->IsOnePastTheEnd;
1134}
1135
1137 assert(isLValue() && "Invalid accessor");
1138 return ((LV *)(void *)&Data)->Offset;
1139}
1140
1142 assert(isLValue() && "Invalid accessor");
1143 return ((const LV *)(const char *)&Data)->hasPath();
1144}
1145
1147 assert(isLValue() && hasLValuePath() && "Invalid accessor");
1148 const LV &LVal = *((const LV *)(const char *)&Data);
1149 return {LVal.getPath(), LVal.PathLength};
1150}
1151
1153 assert(isLValue() && "Invalid accessor");
1154 return ((const LV *)(const char *)&Data)->Base.getCallIndex();
1155}
1156
1158 assert(isLValue() && "Invalid accessor");
1159 return ((const LV *)(const char *)&Data)->Base.getVersion();
1160}
1161
1163 assert(isLValue() && "Invalid usage");
1164 return ((const LV *)(const char *)&Data)->IsNullPtr;
1165}
1166
1168 bool IsNullPtr) {
1169 assert(isLValue() && "Invalid accessor");
1170 LV &LVal = *((LV *)(char *)&Data);
1171 LVal.Base = B;
1172 LVal.IsOnePastTheEnd = false;
1173 LVal.Offset = O;
1174 LVal.resizePath((unsigned)-1);
1175 LVal.IsNullPtr = IsNullPtr;
1176}
1177
1179APValue::setLValueUninit(LValueBase B, CharUnits O, unsigned Size,
1180 bool IsOnePastTheEnd, bool IsNullPtr) {
1181 assert(isLValue() && "Invalid accessor");
1182 LV &LVal = *((LV *)(char *)&Data);
1183 LVal.Base = B;
1184 LVal.IsOnePastTheEnd = IsOnePastTheEnd;
1185 LVal.Offset = O;
1186 LVal.IsNullPtr = IsNullPtr;
1187 LVal.resizePath(Size);
1188 return {LVal.getPath(), Size};
1189}
1190
1192 ArrayRef<LValuePathEntry> Path, bool IsOnePastTheEnd,
1193 bool IsNullPtr) {
1195 setLValueUninit(B, O, Path.size(), IsOnePastTheEnd, IsNullPtr);
1196 if (Path.size()) {
1197 memcpy(InternalPath.data(), Path.data(),
1198 Path.size() * sizeof(LValuePathEntry));
1199 }
1200}
1201
1202void APValue::setUnion(const FieldDecl *Field, const APValue &Value) {
1203 assert(isUnion() && "Invalid accessor");
1204 ((UnionData *)(char *)&Data)->Field =
1205 Field ? Field->getCanonicalDecl() : nullptr;
1206 *((UnionData *)(char *)&Data)->Value = Value;
1207}
1208
1210 assert(isMemberPointer() && "Invalid accessor");
1211 const MemberPointerData &MPD =
1212 *((const MemberPointerData *)(const char *)&Data);
1213 return MPD.MemberAndIsDerivedMember.getPointer();
1214}
1215
1217 assert(isMemberPointer() && "Invalid accessor");
1218 const MemberPointerData &MPD =
1219 *((const MemberPointerData *)(const char *)&Data);
1220 return MPD.MemberAndIsDerivedMember.getInt();
1221}
1222
1224 assert(isMemberPointer() && "Invalid accessor");
1225 const MemberPointerData &MPD =
1226 *((const MemberPointerData *)(const char *)&Data);
1227 return {MPD.getPath(), MPD.PathLength};
1228}
1229
1230void APValue::MakeLValue() {
1231 assert(isAbsent() && "Bad state change");
1232 static_assert(sizeof(LV) <= DataSize, "LV too big");
1233 new ((void *)(char *)&Data) LV();
1234 Kind = LValue;
1235}
1236
1237void APValue::MakeArray(unsigned InitElts, unsigned Size) {
1238 assert(isAbsent() && "Bad state change");
1239 new ((void *)(char *)&Data) Arr(InitElts, Size);
1240 Kind = Array;
1241}
1242
1244APValue::setMemberPointerUninit(const ValueDecl *Member, bool IsDerivedMember,
1245 unsigned Size) {
1246 assert(isAbsent() && "Bad state change");
1247 MemberPointerData *MPD = new ((void *)(char *)&Data) MemberPointerData;
1248 Kind = MemberPointer;
1249 MPD->MemberAndIsDerivedMember.setPointer(
1250 Member ? cast<ValueDecl>(Member->getCanonicalDecl()) : nullptr);
1251 MPD->MemberAndIsDerivedMember.setInt(IsDerivedMember);
1252 MPD->resizePath(Size);
1253 return {MPD->getPath(), MPD->PathLength};
1254}
1255
1256void APValue::MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember,
1258 MutableArrayRef<const CXXRecordDecl *> InternalPath =
1259 setMemberPointerUninit(Member, IsDerivedMember, Path.size());
1260 for (unsigned I = 0; I != Path.size(); ++I)
1261 InternalPath[I] = Path[I]->getCanonicalDecl();
1262}
1263
1264LinkageInfo LinkageComputer::getLVForValue(const APValue &V,
1265 LVComputationKind computation) {
1266 LinkageInfo LV = LinkageInfo::external();
1267
1268 auto MergeLV = [&](LinkageInfo MergeLV) { LV.merge(MergeLV); };
1269 V.visit([&](const APValue &Value) {
1270 switch (Value.getKind()) {
1272 // Even for an inline function, it's not reasonable to treat a difference
1273 // between the addresses of labels as an external value.
1274 LV = LinkageInfo::internal();
1275 return false;
1276
1277 case APValue::LValue:
1278 if (!Value.getLValueBase()) {
1279 // Null or absolute address: this is external.
1280 } else if (const auto *VD =
1281 Value.getLValueBase().dyn_cast<const ValueDecl *>()) {
1282 MergeLV(getLVForDecl(VD, computation));
1283 } else if (const auto TI =
1284 Value.getLValueBase().dyn_cast<TypeInfoLValue>()) {
1285 MergeLV(getLVForType(*TI.getType(), computation));
1286 } else if (const Expr *E =
1287 Value.getLValueBase().dyn_cast<const Expr *>()) {
1288 // Almost all expression bases are internal. The exception is
1289 // lifetime-extended temporaries.
1290 // FIXME: These should be modeled as having the
1291 // LifetimeExtendedTemporaryDecl itself as the base.
1292 // FIXME: If we permit Objective-C object literals in template
1293 // arguments, they should not imply internal linkage.
1294 auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E);
1295 if (!MTE || MTE->getStorageDuration() == SD_FullExpression)
1296 LV = LinkageInfo::internal();
1297 else
1298 MergeLV(getLVForDecl(MTE->getExtendingDecl(), computation));
1299 } else {
1300 assert(Value.getLValueBase().is<DynamicAllocLValue>() &&
1301 "unexpected LValueBase kind");
1302 LV = LinkageInfo::internal();
1303 }
1304 // The lvalue path doesn't matter: pointers to all subobjects always have
1305 // the same visibility as pointers to the complete object.
1306 return LV.getLinkage() != Linkage::Internal;
1307
1309 if (const NamedDecl *D = Value.getMemberPointerDecl())
1310 MergeLV(getLVForDecl(D, computation));
1311 // Note that we could have a base-to-derived conversion here to a member
1312 // of a derived class with less linkage/visibility. That's covered by the
1313 // linkage and visibility of the value's type.
1314 return LV.getLinkage() != Linkage::Internal;
1315
1316 default:
1317 return true;
1318 }
1319 });
1320
1321 return LV;
1322}
static double GetApproxValue(const llvm::APFloat &F)
Definition APValue.cpp:739
static bool visitAPValue(const APValue &Value, llvm::function_ref< bool(const APValue &)> Visitor)
Definition APValue.cpp:24
static void profileIntValue(llvm::FoldingSetNodeID &ID, const llvm::APInt &V)
Profile the value of an APInt, excluding its bit-width.
Definition APValue.cpp:549
static void profileReflection(llvm::FoldingSetNodeID &ID, APValue V)
Definition APValue.cpp:570
static void profileTypeReflection(llvm::FoldingSetNodeID &ID, QualType QT)
Unwrap reflected type for profiling.
Definition APValue.cpp:555
static bool TryPrintAsStringLiteral(raw_ostream &Out, const PrintingPolicy &Policy, const ArrayType *ATy, ArrayRef< APValue > Inits)
Definition APValue.cpp:747
Defines the clang::ASTContext interface.
#define V(N, I)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Expr interface and subclasses for C++ expressions.
static const Decl * getCanonicalDecl(const Decl *D)
llvm::json::Array Array
C Language Family Type Representation.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
void Profile(llvm::FoldingSetNodeID &ID) const
Definition APValue.cpp:187
QualType getType() const
Definition APValue.cpp:123
unsigned getVersion() const
Definition APValue.cpp:173
QualType getDynamicAllocType() const
Definition APValue.cpp:182
QualType getTypeInfoType() const
Definition APValue.cpp:177
void * DynamicAllocType
The QualType, if this is a DynamicAllocLValue.
Definition APValue.h:236
static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo)
Definition APValue.cpp:115
static LValueBase getDynamicAlloc(DynamicAllocLValue LV, QualType Type)
Definition APValue.cpp:107
void * TypeInfoType
The type std::type_info, if this is a TypeInfoLValue.
Definition APValue.h:234
void * getOpaqueValue() const
Definition APValue.cpp:235
unsigned getCallIndex() const
Definition APValue.cpp:168
A non-discriminated union of a base, field, or array index.
Definition APValue.h:245
void Profile(llvm::FoldingSetNodeID &ID) const
Definition APValue.cpp:213
ArrayRef< LValuePathEntry > Path
Definition APValue.h:281
LValuePathSerializationHelper(ArrayRef< LValuePathEntry >, QualType)
Definition APValue.cpp:217
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:158
bool hasArrayFiller() const
Definition APValue.h:699
const LValueBase getLValueBase() const
Definition APValue.cpp:1126
APValue & getArrayInitializedElt(unsigned I)
Definition APValue.h:691
ArrayRef< LValuePathEntry > getLValuePath() const
Definition APValue.cpp:1146
void swap(APValue &RHS)
Swaps the contents of this and the given APValue.
Definition APValue.cpp:539
const void * getReflectionOpaqueOperand() const
Definition APValue.h:787
APSInt & getInt()
Definition APValue.h:573
APValue & getStructField(unsigned i)
Definition APValue.h:736
unsigned getMatrixNumColumns() const
Definition APValue.h:664
const FieldDecl * getUnionField() const
Definition APValue.h:757
APSInt & getComplexIntImag()
Definition APValue.h:611
unsigned getStructNumFields() const
Definition APValue.h:723
bool isAbsent() const
Definition APValue.h:545
llvm::PointerIntPair< const Decl *, 1, bool > BaseOrMemberType
A FieldDecl or CXXRecordDecl, along with a flag indicating whether we mean a virtual or non-virtual b...
Definition APValue.h:242
ValueKind getKind() const
Definition APValue.h:537
ReflectionKind getReflectionOperandKind() const
Definition APValue.h:782
bool isLValueOnePastTheEnd() const
Definition APValue.cpp:1131
APValue & getStructVirtualBase(unsigned i)
Definition APValue.h:741
unsigned getLValueVersion() const
Definition APValue.cpp:1157
bool isMemberPointerToDerivedMember() const
Definition APValue.cpp:1216
unsigned getArrayInitializedElts() const
Definition APValue.h:710
void setLValue(LValueBase B, CharUnits O, NoLValuePath, bool IsNullPtr)
Definition APValue.cpp:1167
void setComplexInt(APSInt R, APSInt I)
Definition APValue.h:814
void Profile(llvm::FoldingSetNodeID &ID) const
profile this value.
Definition APValue.cpp:585
unsigned getStructNumBases() const
Definition APValue.h:719
APFixedPoint & getFixedPoint()
Definition APValue.h:595
bool needsCleanup() const
Returns whether the object performed allocations.
Definition APValue.cpp:500
unsigned getStructNumVirtualBases() const
Definition APValue.h:727
bool hasLValuePath() const
Definition APValue.cpp:1141
const ValueDecl * getMemberPointerDecl() const
Definition APValue.cpp:1209
APValue & getUnionValue()
Definition APValue.h:761
void setMatrix(const APValue *E, unsigned NumRows, unsigned NumCols)
Definition APValue.h:809
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition APValue.h:777
CharUnits & getLValueOffset()
Definition APValue.cpp:1136
void printPretty(raw_ostream &OS, const ASTContext &Ctx, QualType Ty) const
Definition APValue.cpp:810
void setAddrLabelDiff(const AddrLabelExpr *LHSExpr, const AddrLabelExpr *RHSExpr)
Definition APValue.h:832
void setComplexFloat(APFloat R, APFloat I)
Definition APValue.h:821
APValue & getVectorElt(unsigned I)
Definition APValue.h:647
APValue & getArrayFiller()
Definition APValue.h:702
void visit(llvm::function_ref< bool(const APValue &)> Visitor) const
Visit this value and every recursively nested value.
Definition APValue.cpp:81
unsigned getVectorLength() const
Definition APValue.h:655
bool isLValue() const
Definition APValue.h:554
void setUnion(const FieldDecl *Field, const APValue &Value)
Definition APValue.cpp:1202
unsigned getMatrixNumRows() const
Definition APValue.h:660
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition APValue.cpp:1223
bool isMemberPointer() const
Definition APValue.h:560
bool isInt() const
Definition APValue.h:549
unsigned getArraySize() const
Definition APValue.h:714
bool isUnion() const
Definition APValue.h:559
bool toIntegralConstant(APSInt &Result, QualType SrcTy, const ASTContext &Ctx) const
Try to convert this value to an integral constant.
Definition APValue.cpp:1106
std::string getAsString(const ASTContext &Ctx, QualType Ty) const
Definition APValue.cpp:1099
APValue & operator=(const APValue &RHS)
Definition APValue.cpp:448
unsigned getLValueCallIndex() const
Definition APValue.cpp:1152
void setVector(const APValue *E, unsigned N)
Definition APValue.h:804
APValue & getMatrixElt(unsigned Idx)
Definition APValue.h:671
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
Definition APValue.h:167
@ None
There is no such object (it's outside its lifetime).
Definition APValue.h:165
bool isNullPointer() const
Definition APValue.cpp:1162
APSInt & getComplexIntReal()
Definition APValue.h:603
APFloat & getComplexFloatImag()
Definition APValue.h:627
APFloat & getComplexFloatReal()
Definition APValue.h:619
APFloat & getFloat()
Definition APValue.h:587
APValue & getStructBase(unsigned i)
Definition APValue.h:731
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition APValue.h:773
APValue()
Creates an empty APValue of type None.
Definition APValue.h:385
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:245
uint64_t getTargetNullPointerValue(QualType QT) const
Get target-dependent integer value for null pointer which is used for constant folding.
const clang::PrintingPolicy & getPrintingPolicy() const
Definition ASTContext.h:909
llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const
Make an APSInt of the appropriate width and signedness for the given Value and integer Type.
std::optional< CharUnits > getTypeSizeInCharsIfKnown(QualType Ty) const
LabelDecl * getLabel() const
Definition Expr.h:4621
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3820
QualType getElementType() const
Definition TypeBase.h:3832
QualType getType() const
Retrieves the type of the base class.
Definition DeclCXX.h:249
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
base_class_iterator bases_end()
Definition DeclCXX.h:618
base_class_iterator bases_begin()
Definition DeclCXX.h:616
const CXXBaseSpecifier * base_class_const_iterator
Iterator that traverses the base classes of a class.
Definition DeclCXX.h:521
base_class_iterator vbases_begin()
Definition DeclCXX.h:633
base_class_iterator vbases_end()
Definition DeclCXX.h:635
This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
bool isZero() const
Test whether the quantity equals zero.
Definition CharUnits.h:101
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
Definition CharUnits.h:155
static CharUnits One()
Construct a CharUnits quantity of one.
Definition CharUnits.h:55
bool isMultipleOf(CharUnits N) const
Test whether this is a multiple of the other value.
Definition CharUnits.h:122
static CharUnits Zero()
Construct a CharUnits quantity of zero.
Definition CharUnits.h:52
Complex values, per C99 6.2.5p11.
Definition TypeBase.h:3362
Represents a concrete matrix type with constant number of rows and columns.
Definition TypeBase.h:4490
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Symbolic representation of a dynamic allocation.
Definition APValue.h:79
This represents one expression.
Definition Expr.h:113
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
Definition Expr.cpp:85
QualType getType() const
Definition Expr.h:145
Represents a member of a struct/union/class.
Definition Decl.h:3299
LinkageInfo getLVForDecl(const NamedDecl *D, LVComputationKind computation)
getLVForDecl - Get the linkage and visibility for the given declaration.
Definition Decl.cpp:1579
static LinkageInfo external()
Definition Visibility.h:72
Linkage getLinkage() const
Definition Visibility.h:88
static LinkageInfo internal()
Definition Visibility.h:75
void merge(LinkageInfo other)
Merge both linkage and visibility.
Definition Visibility.h:137
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4974
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:302
A (possibly-)qualified type.
Definition TypeBase.h:938
void Profile(llvm::FoldingSetNodeID &ID) const
Definition TypeBase.h:1414
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1005
static QualType getFromOpaquePtr(const void *Ptr)
Definition TypeBase.h:987
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
Definition TypeBase.h:8631
QualType getCanonicalType() const
Definition TypeBase.h:8498
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Definition TypeBase.h:1404
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
Symbolic representation of typeid(T) for some type T.
Definition APValue.h:48
const Type * getType() const
Definition APValue.h:55
void print(llvm::raw_ostream &Out, const PrintingPolicy &Policy) const
Definition APValue.cpp:90
A container of type source information.
Definition TypeBase.h:8417
QualType getType() const
Return the type wrapped by this type source info.
Definition TypeBase.h:8428
The base class of the type hierarchy.
Definition TypeBase.h:1879
bool isVoidType() const
Definition TypeBase.h:9068
bool isBooleanType() const
Definition TypeBase.h:9209
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type.
Definition TypeBase.h:9375
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9366
bool isReferenceType() const
Definition TypeBase.h:8707
bool isChar8Type() const
Definition Type.cpp:2335
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:885
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition Type.cpp:2355
RecordDecl * castAsRecordDecl() const
Definition Type.h:48
bool isChar16Type() const
Definition Type.cpp:2341
bool isAnyComplexType() const
Definition TypeBase.h:8818
bool isChar32Type() const
Definition Type.cpp:2347
bool isWideCharType() const
Definition Type.cpp:2328
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9299
bool isRecordType() const
Definition TypeBase.h:8810
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:713
QualType getType() const
Definition Decl.h:724
Kind getKind() const
Definition Value.h:137
Represents a GCC generic vector type.
Definition TypeBase.h:4273
Top level wrappers for InstallAPI frontend operations.
LLVM_READNONE bool isASCII(char c)
Returns true if a byte is an ASCII character.
Definition CharInfo.h:41
LLVM_READONLY bool isPrintable(unsigned char c)
Return true if this character is an ASCII printable character; that is, a character that should take ...
Definition CharInfo.h:160
LLVM_READONLY auto escapeCStyle(CharT Ch) -> StringRef
Return C-style escaped string for special characters, or an empty string if there is no such mapping.
Definition CharInfo.h:191
@ Vector
'vector' clause, allowed on 'loop', Combined, and 'routine' directives.
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
Definition CallGraph.h:218
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ Internal
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition Linkage.h:35
@ SD_FullExpression
Full-expression storage duration (for temporaries).
Definition Specifiers.h:342
@ Result
The result type of a method or function.
Definition TypeBase.h:906
const FunctionProtoType * T
llvm::hash_code hash_value(const CustomizableOptional< T > &O)
U cast(CodeGen::Address addr)
Definition Address.h:327
@ Struct
The "struct" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6016
@ Union
The "union" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6022
bool isTypeAliasAsReflectionName(QualType QT)
[expr.reflect] p5, if a reflect-expression R matches the form ^^reflection-name it is interpreted as ...
Definition Reflection.h:58
hash_code hash_value(const clang::dependencies::ModuleID &ID)
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
LValuePathEntry Path[InlinePathSpace]
Definition APValue.cpp:275
bool hasPathPtr() const
Definition APValue.cpp:293
void resizePath(unsigned Length)
Definition APValue.cpp:282
bool hasPath() const
Definition APValue.cpp:292
LValuePathEntry * PathPtr
Definition APValue.cpp:276
static const unsigned InlinePathSpace
Definition APValue.cpp:268
const LValuePathEntry * getPath() const
Definition APValue.cpp:296
LValuePathEntry * getPath()
Definition APValue.cpp:295
PathElem Path[InlinePathSpace]
Definition APValue.cpp:313
static const unsigned InlinePathSpace
Definition APValue.cpp:309
const CXXRecordDecl * PathElem
Definition APValue.cpp:311
void resizePath(unsigned Length)
Definition APValue.cpp:320
const PathElem * getPath() const
Definition APValue.cpp:333
Kinds of LV computation.
Definition Linkage.h:29
Describes how types, statements, expressions, and declarations should be printed.
unsigned Nullptr
Whether we should use 'nullptr' rather than '0' as a null pointer constant.
unsigned EntireContentsOfLargeArray
Whether to print the entire array initializers, especially on non-type template parameters,...