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