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