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/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.
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(Out, Policy);
34 Out << ")";
35}
36
37static_assert(
39 alignof(Type),
40 "Type is insufficiently aligned");
41
42APValue::LValueBase::LValueBase(const ValueDecl *P, unsigned I, unsigned V)
43 : Ptr(P ? cast<ValueDecl>(P->getCanonicalDecl()) : nullptr), Local{I, V} {}
44APValue::LValueBase::LValueBase(const Expr *P, unsigned I, unsigned V)
45 : Ptr(P), Local{I, V} {}
46
48 QualType Type) {
50 Base.Ptr = LV;
51 Base.DynamicAllocType = Type.getAsOpaquePtr();
52 return Base;
53}
54
58 Base.Ptr = LV;
59 Base.TypeInfoType = TypeInfo.getAsOpaquePtr();
60 return Base;
61}
62
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>(D->getMostRecentDecl()); Redecl;
74 Redecl = cast_or_null<ValueDecl>(Redecl->getPreviousDecl())) {
75 QualType T = Redecl->getType();
76 if (!T->isIncompleteArrayType())
77 return T;
78 }
79 return D->getType();
80 }
81
83 return getTypeInfoType();
84
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>(Base)) {
96 const Expr *Temp = MTE->getSubExpr();
97 const Expr *Inner = Temp->skipRValueSubobjectAdjustments(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
110 : Local.CallIndex;
111}
112
114 return (is<TypeInfoLValue>() || is<DynamicAllocLValue>()) ? 0 : Local.Version;
115}
116
118 assert(is<TypeInfoLValue>() && "not a type_info lvalue");
120}
121
123 assert(is<DynamicAllocLValue>() && "not a dynamic allocation lvalue");
125}
126
127void APValue::LValueBase::Profile(llvm::FoldingSetNodeID &ID) const {
128 ID.AddPointer(Ptr.getOpaqueValue());
130 return;
131 ID.AddInteger(Local.CallIndex);
132 ID.AddInteger(Local.Version);
133}
134
135namespace clang {
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
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(Value);
155}
156
160
164
165namespace {
166 struct LVBase {
168 CharUnits Offset;
169 unsigned PathLength;
170 bool IsNullPtr : 1;
171 bool IsOnePastTheEnd : 1;
172 };
173}
174
176 return Ptr.getOpaqueValue();
177}
178
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(Base.getOpaqueValue());
191 return llvm::hash_combine(Base.getOpaqueValue(), Base.getCallIndex(),
192 Base.getVersion());
193}
194}
195
196unsigned llvm::DenseMapInfo<clang::APValue::LValueBase>::getHashValue(
198 return hash_value(Base);
199}
200
201bool llvm::DenseMapInfo<clang::APValue::LValueBase>::isEqual(
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 {
217 };
218
219 LV() { PathLength = (unsigned)-1; }
220 ~LV() { resizePath(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
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 {
255 };
256
257 MemberPointerData() { PathLength = 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
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
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(RHS.getInt());
309 break;
310 case Float:
311 MakeFloat(RHS.getFloat());
312 break;
313 case FixedPoint: {
314 APFixedPoint FXCopy = RHS.getFixedPoint();
315 MakeFixedPoint(std::move(FXCopy));
316 break;
317 }
318 case Vector:
319 MakeVector();
320 setVector(((const Vec *)(const char *)&RHS.Data)->Elts,
321 RHS.getVectorLength());
322 break;
323 case Matrix:
324 MakeMatrix();
325 setMatrix(((const Mat *)(const char *)&RHS.Data)->Elts,
327 break;
328 case ComplexInt:
329 MakeComplexInt();
331 break;
332 case ComplexFloat:
333 MakeComplexFloat();
335 break;
336 case LValue:
337 MakeLValue();
338 if (RHS.hasLValuePath())
341 else
343 RHS.isNullPointer());
344 break;
345 case Array:
346 MakeArray(RHS.getArrayInitializedElts(), RHS.getArraySize());
347 for (unsigned I = 0, N = RHS.getArrayInitializedElts(); I != N; ++I)
349 if (RHS.hasArrayFiller())
351 break;
352 case Struct:
353 MakeStruct(RHS.getStructNumBases(), RHS.getStructNumFields(),
355 for (unsigned I = 0, N = RHS.getStructNumBases(); I != N; ++I)
356 getStructBase(I) = RHS.getStructBase(I);
357 for (unsigned I = 0, N = RHS.getStructNumFields(); I != N; ++I)
358 getStructField(I) = RHS.getStructField(I);
359 for (unsigned I = 0, N = RHS.getStructNumVirtualBases(); I != N; ++I)
361 break;
362 case Union:
363 MakeUnion();
365 break;
366 case MemberPointer:
367 MakeMemberPointer(RHS.getMemberPointerDecl(),
370 break;
371 case AddrLabelDiff:
372 MakeAddrLabelDiff();
374 break;
375 }
376}
377
379 : Kind(RHS.Kind), AllowConstexprUnknown(RHS.AllowConstexprUnknown),
380 Data(RHS.Data) {
381 RHS.Kind = None;
382}
383
385 if (this != &RHS)
386 *this = APValue(RHS);
387
388 return *this;
389}
390
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
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:
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() ==
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
473 std::swap(Kind, RHS.Kind);
474 std::swap(Data, 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((uint32_t)V.extractBitsAsZExtValue(std::min(32u, N - I), 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(Kind);
494
495 switch (Kind) {
496 case None:
497 case Indeterminate:
498 return;
499
500 case AddrLabelDiff:
501 ID.AddPointer(getAddrLabelDiffLHS()->getLabel()->getCanonicalDecl());
502 ID.AddPointer(getAddrLabelDiffRHS()->getLabel()->getCanonicalDecl());
503 return;
504
505 case Struct:
506 for (unsigned I = 0, N = getStructNumBases(); I != N; ++I)
507 getStructBase(I).Profile(ID);
508 for (unsigned I = 0, N = getStructNumFields(); I != N; ++I)
509 getStructField(I).Profile(ID);
510 for (unsigned I = 0, N = getStructNumVirtualBases(); I != N; ++I)
512 return;
513
514 case Union:
515 if (!getUnionField()) {
516 ID.AddInteger(0);
517 return;
518 }
519 ID.AddInteger(getUnionField()->getFieldIndex() + 1);
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;
538 .Profile(FillerID);
539 ID.AddNodeID(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(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(N - 1).Profile(ElemID);
559 if (ElemID != FillerID) {
560 ID.AddInteger(NumFillers);
561 ID.AddNodeID(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)
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(R, C).Profile(ID);
587 return;
588
589 case Int:
590 profileIntValue(ID, getInt());
591 return;
592
593 case Float:
594 profileIntValue(ID, getFloat().bitcastToAPInt());
595 return;
596
597 case FixedPoint:
598 profileIntValue(ID, getFixedPoint().getValue());
599 return;
600
601 case ComplexFloat:
602 profileIntValue(ID, getComplexFloatReal().bitcastToAPInt());
603 profileIntValue(ID, getComplexFloatImag().bitcastToAPInt());
604 return;
605
606 case ComplexInt:
609 return;
610
611 case LValue:
613 ID.AddInteger(getLValueOffset().getQuantity());
614 ID.AddInteger((isNullPointer() ? 1 : 0) |
615 (isLValueOnePastTheEnd() ? 2 : 0) |
616 (hasLValuePath() ? 4 : 0));
617 if (hasLValuePath()) {
618 ID.AddInteger(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.
623 E.Profile(ID);
624 }
625 return;
626
627 case MemberPointer:
628 ID.AddPointer(getMemberPointerDecl());
629 ID.AddInteger(isMemberPointerToDerivedMember());
630 for (const CXXRecordDecl *D : getMemberPointerPath())
631 ID.AddPointer(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(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven,
642 &ignored);
643 return V.convertToDouble();
644}
645
646static bool TryPrintAsStringLiteral(raw_ostream &Out,
647 const PrintingPolicy &Policy,
648 const ArrayType *ATy,
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
664 Buf.push_back('"');
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(std::min(MaxN - Ellipsis.size() / 2, 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(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(Ch))
686 return false;
687 Buf.emplace_back(Ch);
688 } else {
689 Buf.append(Escaped);
690 }
691 }
692
693 Buf.append(Ellipsis);
694 Buf.push_back('"');
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(Out, Ctx.getPrintingPolicy(), Ty, &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;
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(getFloat());
741 return;
743 Out << getFixedPoint();
744 return;
745 case APValue::Vector: {
746 Out << '{';
747 QualType ElemTy = Ty->castAs<VectorType>()->getElementType();
748 getVectorElt(0).printPretty(Out, Policy, ElemTy, Ctx);
749 for (unsigned i = 1; i != getVectorLength(); ++i) {
750 Out << ", ";
751 getVectorElt(i).printPretty(Out, Policy, 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(R, C).printPretty(Out, Policy, ElemTy, Ctx);
768 }
769 Out << '}';
770 }
771 Out << '}';
772 return;
773 }
775 Out << getComplexIntReal() << "+" << getComplexIntImag() << "i";
776 return;
778 Out << GetApproxValue(getComplexFloatReal()) << "+"
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
789 if (!Base) {
790 if (isNullPointer()) {
791 Out << (Policy.Nullptr ? "nullptr" : "0");
792 } else if (IsReference) {
793 Out << "*(" << InnerTy.stream(Policy) << "*)"
795 } else {
796 Out << "(" << Ty.stream(Policy) << ")"
798 }
799 return;
800 }
801
802 if (!hasLValuePath()) {
803 // No lvalue path: just print the offset.
805 CharUnits S = Ctx ? Ctx->getTypeSizeInCharsIfKnown(InnerTy).value_or(
807 : CharUnits::Zero();
808 if (!O.isZero()) {
809 if (IsReference)
810 Out << "*(";
811 if (S.isZero() || !O.isMultipleOf(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(Out, 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(Out, nullptr, Policy);
860 }
861
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>(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>(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, AT,
906 {&getArrayInitializedElt(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, 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>(RD);
934 for (unsigned I = 0; I != N; ++I, ++BI) {
935 assert(BI != CD->bases_end());
936 if (!First)
937 Out << ", ";
938 getStructBase(I).printPretty(Out, Policy, 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(FI->getFieldIndex()).
948 printPretty(Out, Policy, FI->getType(), Ctx);
949 First = false;
950 }
951 if (unsigned N = getStructNumVirtualBases()) {
952 const CXXRecordDecl *CD = cast<CXXRecordDecl>(RD);
954 for (unsigned I = 0; I != N; ++I, ++BI) {
955 assert(BI != CD->vbases_end());
956 if (!First)
957 Out << ", ";
958 getStructVirtualBase(I).printPretty(Out, Policy, 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, FD->getType(), Ctx);
970 }
971 Out << '}';
972 return;
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>(VD->getDeclContext()) << "::" << *VD;
978 return;
979 }
980 Out << "0";
981 return;
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
999 const ASTContext &Ctx) const {
1000 if (isInt()) {
1001 Result = getInt();
1002 return true;
1003 }
1004
1005 if (isLValue() && isNullPointer()) {
1006 Result = Ctx.MakeIntValue(Ctx.getTargetNullPointerValue(SrcTy), SrcTy);
1007 return true;
1008 }
1009
1010 if (isLValue() && !getLValueBase()) {
1011 Result = Ctx.MakeIntValue(getLValueOffset().getQuantity(), SrcTy);
1012 return true;
1013 }
1014
1015 return false;
1016}
1017
1019 assert(isLValue() && "Invalid accessor");
1020 return ((const LV *)(const void *)&Data)->Base;
1021}
1022
1024 assert(isLValue() && "Invalid accessor");
1025 return ((const LV *)(const void *)&Data)->IsOnePastTheEnd;
1026}
1027
1029 assert(isLValue() && "Invalid accessor");
1030 return ((LV *)(void *)&Data)->Offset;
1031}
1032
1034 assert(isLValue() && "Invalid accessor");
1035 return ((const LV *)(const char *)&Data)->hasPath();
1036}
1037
1039 assert(isLValue() && hasLValuePath() && "Invalid accessor");
1040 const LV &LVal = *((const LV *)(const char *)&Data);
1041 return {LVal.getPath(), LVal.PathLength};
1042}
1043
1045 assert(isLValue() && "Invalid accessor");
1046 return ((const LV *)(const char *)&Data)->Base.getCallIndex();
1047}
1048
1050 assert(isLValue() && "Invalid accessor");
1051 return ((const LV *)(const char *)&Data)->Base.getVersion();
1052}
1053
1055 assert(isLValue() && "Invalid usage");
1056 return ((const LV *)(const char *)&Data)->IsNullPtr;
1057}
1058
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((unsigned)-1);
1067 LVal.IsNullPtr = IsNullPtr;
1068}
1069
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(Size);
1080 return {LVal.getPath(), Size};
1081}
1082
1084 ArrayRef<LValuePathEntry> Path, bool IsOnePastTheEnd,
1085 bool IsNullPtr) {
1087 setLValueUninit(B, O, Path.size(), IsOnePastTheEnd, IsNullPtr);
1088 if (Path.size()) {
1089 memcpy(InternalPath.data(), Path.data(),
1090 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
1102 assert(isMemberPointer() && "Invalid accessor");
1103 const MemberPointerData &MPD =
1104 *((const MemberPointerData *)(const char *)&Data);
1105 return MPD.MemberAndIsDerivedMember.getPointer();
1106}
1107
1109 assert(isMemberPointer() && "Invalid accessor");
1110 const MemberPointerData &MPD =
1111 *((const MemberPointerData *)(const char *)&Data);
1112 return MPD.MemberAndIsDerivedMember.getInt();
1113}
1114
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
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>(Member->getCanonicalDecl()) : nullptr);
1143 MPD->MemberAndIsDerivedMember.setInt(IsDerivedMember);
1144 MPD->resizePath(Size);
1145 return {MPD->getPath(), MPD->PathLength};
1146}
1147
1148void APValue::MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember,
1150 MutableArrayRef<const CXXRecordDecl *> InternalPath =
1151 setMemberPointerUninit(Member, IsDerivedMember, 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(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:
1171 case APValue::Int:
1172 case APValue::Float:
1176 case APValue::Vector:
1177 case APValue::Matrix:
1178 break;
1179
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)))
1188 break;
1189 for (unsigned I = 0, N = V.getStructNumFields(); I != N; ++I)
1190 if (Merge(V.getStructField(I)))
1191 break;
1192 for (unsigned I = 0, N = V.getStructNumVirtualBases(); I != N; ++I)
1193 if (Merge(V.getStructVirtualBase(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(VD, computation)))
1218 break;
1219 } else if (const auto TI = V.getLValueBase().dyn_cast<TypeInfoLValue>()) {
1220 if (MergeLV(getLVForType(*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>(E);
1230 if (!MTE || MTE->getStorageDuration() == SD_FullExpression)
1231 return LinkageInfo::internal();
1232 if (MergeLV(getLVForDecl(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
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}
static double GetApproxValue(const llvm::APFloat &F)
Definition APValue.cpp:638
static void profileIntValue(llvm::FoldingSetNodeID &ID, const llvm::APInt &V)
Profile the value of an APInt, excluding its bit-width.
Definition APValue.cpp:482
static bool TryPrintAsStringLiteral(raw_ostream &Out, const PrintingPolicy &Policy, const ArrayType *ATy, ArrayRef< APValue > Inits)
Definition APValue.cpp:646
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:127
QualType getType() const
Definition APValue.cpp:63
unsigned getVersion() const
Definition APValue.cpp:113
QualType getDynamicAllocType() const
Definition APValue.cpp:122
QualType getTypeInfoType() const
Definition APValue.cpp:117
void * DynamicAllocType
The QualType, if this is a DynamicAllocLValue.
Definition APValue.h:199
static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo)
Definition APValue.cpp:55
static LValueBase getDynamicAlloc(DynamicAllocLValue LV, QualType Type)
Definition APValue.cpp:47
void * TypeInfoType
The type std::type_info, if this is a TypeInfoLValue.
Definition APValue.h:197
void * getOpaqueValue() const
Definition APValue.cpp:175
unsigned getCallIndex() const
Definition APValue.cpp:108
A non-discriminated union of a base, field, or array index.
Definition APValue.h:208
void Profile(llvm::FoldingSetNodeID &ID) const
Definition APValue.cpp:153
ArrayRef< LValuePathEntry > Path
Definition APValue.h:244
LValuePathSerializationHelper(ArrayRef< LValuePathEntry >, QualType)
Definition APValue.cpp:157
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition APValue.h:122
bool hasArrayFiller() const
Definition APValue.h:637
const LValueBase getLValueBase() const
Definition APValue.cpp:1018
APValue & getArrayInitializedElt(unsigned I)
Definition APValue.h:629
ArrayRef< LValuePathEntry > getLValuePath() const
Definition APValue.cpp:1038
void swap(APValue &RHS)
Swaps the contents of this and the given APValue.
Definition APValue.cpp:472
APSInt & getInt()
Definition APValue.h:511
APValue & getStructField(unsigned i)
Definition APValue.h:674
unsigned getMatrixNumColumns() const
Definition APValue.h:602
const FieldDecl * getUnionField() const
Definition APValue.h:695
APSInt & getComplexIntImag()
Definition APValue.h:549
unsigned getStructNumFields() const
Definition APValue.h:661
bool isAbsent() const
Definition APValue.h:484
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:205
ValueKind getKind() const
Definition APValue.h:482
bool isLValueOnePastTheEnd() const
Definition APValue.cpp:1023
APValue & getStructVirtualBase(unsigned i)
Definition APValue.h:679
unsigned getLValueVersion() const
Definition APValue.cpp:1049
bool isMemberPointerToDerivedMember() const
Definition APValue.cpp:1108
unsigned getArrayInitializedElts() const
Definition APValue.h:648
void setComplexInt(APSInt R, APSInt I)
Definition APValue.h:742
void Profile(llvm::FoldingSetNodeID &ID) const
profile this value.
Definition APValue.cpp:487
unsigned getStructNumBases() const
Definition APValue.h:657
APFixedPoint & getFixedPoint()
Definition APValue.h:533
bool needsCleanup() const
Returns whether the object performed allocations.
Definition APValue.cpp:434
unsigned getStructNumVirtualBases() const
Definition APValue.h:665
bool hasLValuePath() const
Definition APValue.cpp:1033
const ValueDecl * getMemberPointerDecl() const
Definition APValue.cpp:1101
APValue & getUnionValue()
Definition APValue.h:699
void setMatrix(const APValue *E, unsigned NumRows, unsigned NumCols)
Definition APValue.h:737
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition APValue.h:715
CharUnits & getLValueOffset()
Definition APValue.cpp:1028
void printPretty(raw_ostream &OS, const ASTContext &Ctx, QualType Ty) const
Definition APValue.cpp:709
void setAddrLabelDiff(const AddrLabelExpr *LHSExpr, const AddrLabelExpr *RHSExpr)
Definition APValue.h:762
void setComplexFloat(APFloat R, APFloat I)
Definition APValue.h:749
APValue & getVectorElt(unsigned I)
Definition APValue.h:585
APValue & getArrayFiller()
Definition APValue.h:640
unsigned getVectorLength() const
Definition APValue.h:593
bool isLValue() const
Definition APValue.h:493
void setUnion(const FieldDecl *Field, const APValue &Value)
Definition APValue.cpp:1094
unsigned getMatrixNumRows() const
Definition APValue.h:598
void setLValue(LValueBase B, const CharUnits &O, NoLValuePath, bool IsNullPtr)
Definition APValue.cpp:1059
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition APValue.cpp:1115
bool isMemberPointer() const
Definition APValue.h:499
bool isInt() const
Definition APValue.h:488
unsigned getArraySize() const
Definition APValue.h:652
bool isUnion() const
Definition APValue.h:498
bool toIntegralConstant(APSInt &Result, QualType SrcTy, const ASTContext &Ctx) const
Try to convert this value to an integral constant.
Definition APValue.cpp:998
std::string getAsString(const ASTContext &Ctx, QualType Ty) const
Definition APValue.cpp:991
APValue & operator=(const APValue &RHS)
Definition APValue.cpp:384
unsigned getLValueCallIndex() const
Definition APValue.cpp:1044
void setVector(const APValue *E, unsigned N)
Definition APValue.h:732
APValue & getMatrixElt(unsigned Idx)
Definition APValue.h:609
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
Definition APValue.h:131
@ None
There is no such object (it's outside its lifetime).
Definition APValue.h:129
bool isNullPointer() const
Definition APValue.cpp:1054
APSInt & getComplexIntReal()
Definition APValue.h:541
APFloat & getComplexFloatImag()
Definition APValue.h:565
APFloat & getComplexFloatReal()
Definition APValue.h:557
APFloat & getFloat()
Definition APValue.h:525
APValue & getStructBase(unsigned i)
Definition APValue.h:669
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition APValue.h:711
APValue()
Creates an empty APValue of type None.
Definition APValue.h:337
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
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:881
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:4617
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3836
QualType getElementType() const
Definition TypeBase.h:3848
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:617
base_class_iterator bases_begin()
Definition DeclCXX.h:615
const CXXBaseSpecifier * base_class_const_iterator
Iterator that traverses the base classes of a class.
Definition DeclCXX.h:520
base_class_iterator vbases_begin()
Definition DeclCXX.h:632
base_class_iterator vbases_end()
Definition DeclCXX.h:634
CharUnits - This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
bool isZero() const
isZero - Test whether the quantity equals zero.
Definition CharUnits.h:122
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition CharUnits.h:185
static CharUnits One()
One - Construct a CharUnits quantity of one.
Definition CharUnits.h:58
bool isMultipleOf(CharUnits N) const
Test whether this is a multiple of the other value.
Definition CharUnits.h:143
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Definition CharUnits.h:53
Complex values, per C99 6.2.5p11.
Definition TypeBase.h:3355
Represents a concrete matrix type with constant number of rows and columns.
Definition TypeBase.h:4501
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Symbolic representation of a dynamic allocation.
Definition APValue.h:65
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:3295
LinkageInfo getLVForDecl(const NamedDecl *D, LVComputationKind computation)
getLVForDecl - Get the linkage and visibility for the given declaration.
Definition Decl.cpp:1581
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:4973
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
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:8686
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:44
const Type * getType() const
Definition APValue.h:51
void print(llvm::raw_ostream &Out, const PrintingPolicy &Policy) const
Definition APValue.cpp:30
The base class of the type hierarchy.
Definition TypeBase.h:1879
bool isVoidType() const
Definition TypeBase.h:9110
bool isBooleanType() const
Definition TypeBase.h:9247
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type.
Definition TypeBase.h:9413
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9404
bool isReferenceType() const
Definition TypeBase.h:8762
bool isChar8Type() const
Definition Type.cpp:2239
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:789
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition Type.cpp:2259
RecordDecl * castAsRecordDecl() const
Definition Type.h:48
bool isChar16Type() const
Definition Type.cpp:2245
bool isAnyComplexType() const
Definition TypeBase.h:8873
bool isChar32Type() const
Definition Type.cpp:2251
bool isWideCharType() const
Definition Type.cpp:2232
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9337
bool isRecordType() const
Definition TypeBase.h:8865
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
Represents a GCC generic vector type.
Definition TypeBase.h:4289
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:339
@ 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
@ None
The alignment was not explicit in code.
Definition ASTContext.h:176
@ Struct
The "struct" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6021
@ Union
The "union" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6027
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...
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
LValuePathEntry Path[InlinePathSpace]
Definition APValue.cpp:215
bool hasPathPtr() const
Definition APValue.cpp:233
void resizePath(unsigned Length)
Definition APValue.cpp:222
bool hasPath() const
Definition APValue.cpp:232
LValuePathEntry * PathPtr
Definition APValue.cpp:216
static const unsigned InlinePathSpace
Definition APValue.cpp:208
const LValuePathEntry * getPath() const
Definition APValue.cpp:236
LValuePathEntry * getPath()
Definition APValue.cpp:235
PathElem Path[InlinePathSpace]
Definition APValue.cpp:253
static const unsigned InlinePathSpace
Definition APValue.cpp:249
const CXXRecordDecl * PathElem
Definition APValue.cpp:251
void resizePath(unsigned Length)
Definition APValue.cpp:260
const PathElem * getPath() const
Definition APValue.cpp:273
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,...