clang 19.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();
77 return T;
78 }
79 return D->getType();
80 }
81
82 if (is<TypeInfoLValue>())
83 return getTypeInfoType();
84
85 if (is<DynamicAllocLValue>())
86 return getDynamicAllocType();
87
88 const Expr *Base = get<const Expr*>();
89
90 // For a materialized temporary, the type of the temporary we materialized
91 // may not be the type of the expression.
92 if (const MaterializeTemporaryExpr *MTE =
93 llvm::dyn_cast<MaterializeTemporaryExpr>(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
109 return (is<TypeInfoLValue>() || is<DynamicAllocLValue>()) ? 0
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");
119 return QualType::getFromOpaquePtr(TypeInfoType);
120}
121
123 assert(is<DynamicAllocLValue>() && "not a dynamic allocation lvalue");
124 return QualType::getFromOpaquePtr(DynamicAllocType);
125}
126
127void APValue::LValueBase::Profile(llvm::FoldingSetNodeID &ID) const {
128 ID.AddPointer(Ptr.getOpaqueValue());
129 if (is<TypeInfoLValue>() || is<DynamicAllocLValue>())
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
159 : Ty((const void *)ElemTy.getTypePtrOrNull()), Path(Path) {}
160
163}
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 {
229 LValuePathEntry Path[InlinePathSpace];
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
249 LValuePathEntry *getPath() { return hasPathPtr() ? PathPtr : Path; }
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 {
267 PathElem Path[InlinePathSpace];
269 };
270
271 MemberPointerData() { PathLength = 0; }
272 ~MemberPointerData() { resizePath(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
286 PathElem *getPath() { return hasPathPtr() ? PathPtr : Path; }
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
311APValue::APValue(const APValue &RHS) : Kind(None) {
312 switch (RHS.getKind()) {
313 case None:
314 case Indeterminate:
315 Kind = RHS.getKind();
316 break;
317 case Int:
318 MakeInt();
319 setInt(RHS.getInt());
320 break;
321 case Float:
322 MakeFloat();
323 setFloat(RHS.getFloat());
324 break;
325 case FixedPoint: {
326 APFixedPoint FXCopy = RHS.getFixedPoint();
327 MakeFixedPoint(std::move(FXCopy));
328 break;
329 }
330 case Vector:
331 MakeVector();
332 setVector(((const Vec *)(const char *)&RHS.Data)->Elts,
333 RHS.getVectorLength());
334 break;
335 case ComplexInt:
336 MakeComplexInt();
338 break;
339 case ComplexFloat:
340 MakeComplexFloat();
342 break;
343 case LValue:
344 MakeLValue();
345 if (RHS.hasLValuePath())
348 else
350 RHS.isNullPointer());
351 break;
352 case Array:
353 MakeArray(RHS.getArrayInitializedElts(), RHS.getArraySize());
354 for (unsigned I = 0, N = RHS.getArrayInitializedElts(); I != N; ++I)
356 if (RHS.hasArrayFiller())
358 break;
359 case Struct:
360 MakeStruct(RHS.getStructNumBases(), RHS.getStructNumFields());
361 for (unsigned I = 0, N = RHS.getStructNumBases(); I != N; ++I)
362 getStructBase(I) = RHS.getStructBase(I);
363 for (unsigned I = 0, N = RHS.getStructNumFields(); I != N; ++I)
364 getStructField(I) = RHS.getStructField(I);
365 break;
366 case Union:
367 MakeUnion();
369 break;
370 case MemberPointer:
371 MakeMemberPointer(RHS.getMemberPointerDecl(),
374 break;
375 case AddrLabelDiff:
376 MakeAddrLabelDiff();
378 break;
379 }
380}
381
382APValue::APValue(APValue &&RHS) : Kind(RHS.Kind), Data(RHS.Data) {
383 RHS.Kind = None;
384}
385
387 if (this != &RHS)
388 *this = APValue(RHS);
389 return *this;
390}
391
393 if (this != &RHS) {
394 if (Kind != None && Kind != Indeterminate)
395 DestroyDataAndMakeUninit();
396 Kind = RHS.Kind;
397 Data = RHS.Data;
398 RHS.Kind = None;
399 }
400 return *this;
401}
402
403void APValue::DestroyDataAndMakeUninit() {
404 if (Kind == Int)
405 ((APSInt *)(char *)&Data)->~APSInt();
406 else if (Kind == Float)
407 ((APFloat *)(char *)&Data)->~APFloat();
408 else if (Kind == FixedPoint)
409 ((APFixedPoint *)(char *)&Data)->~APFixedPoint();
410 else if (Kind == Vector)
411 ((Vec *)(char *)&Data)->~Vec();
412 else if (Kind == ComplexInt)
413 ((ComplexAPSInt *)(char *)&Data)->~ComplexAPSInt();
414 else if (Kind == ComplexFloat)
415 ((ComplexAPFloat *)(char *)&Data)->~ComplexAPFloat();
416 else if (Kind == LValue)
417 ((LV *)(char *)&Data)->~LV();
418 else if (Kind == Array)
419 ((Arr *)(char *)&Data)->~Arr();
420 else if (Kind == Struct)
421 ((StructData *)(char *)&Data)->~StructData();
422 else if (Kind == Union)
423 ((UnionData *)(char *)&Data)->~UnionData();
424 else if (Kind == MemberPointer)
425 ((MemberPointerData *)(char *)&Data)->~MemberPointerData();
426 else if (Kind == AddrLabelDiff)
427 ((AddrLabelDiffData *)(char *)&Data)->~AddrLabelDiffData();
428 Kind = None;
429}
430
432 switch (getKind()) {
433 case None:
434 case Indeterminate:
435 case AddrLabelDiff:
436 return false;
437 case Struct:
438 case Union:
439 case Array:
440 case Vector:
441 return true;
442 case Int:
443 return getInt().needsCleanup();
444 case Float:
445 return getFloat().needsCleanup();
446 case FixedPoint:
447 return getFixedPoint().getValue().needsCleanup();
448 case ComplexFloat:
451 "In _Complex float types, real and imaginary values always have the "
452 "same size.");
453 return getComplexFloatReal().needsCleanup();
454 case ComplexInt:
455 assert(getComplexIntImag().needsCleanup() ==
457 "In _Complex int types, real and imaginary values must have the "
458 "same size.");
459 return getComplexIntReal().needsCleanup();
460 case LValue:
461 return reinterpret_cast<const LV *>(&Data)->hasPathPtr();
462 case MemberPointer:
463 return reinterpret_cast<const MemberPointerData *>(&Data)->hasPathPtr();
464 }
465 llvm_unreachable("Unknown APValue kind!");
466}
467
469 std::swap(Kind, RHS.Kind);
470 std::swap(Data, RHS.Data);
471}
472
473/// Profile the value of an APInt, excluding its bit-width.
474static void profileIntValue(llvm::FoldingSetNodeID &ID, const llvm::APInt &V) {
475 for (unsigned I = 0, N = V.getBitWidth(); I < N; I += 32)
476 ID.AddInteger((uint32_t)V.extractBitsAsZExtValue(std::min(32u, N - I), I));
477}
478
479void APValue::Profile(llvm::FoldingSetNodeID &ID) const {
480 // Note that our profiling assumes that only APValues of the same type are
481 // ever compared. As a result, we don't consider collisions that could only
482 // happen if the types are different. (For example, structs with different
483 // numbers of members could profile the same.)
484
485 ID.AddInteger(Kind);
486
487 switch (Kind) {
488 case None:
489 case Indeterminate:
490 return;
491
492 case AddrLabelDiff:
493 ID.AddPointer(getAddrLabelDiffLHS()->getLabel()->getCanonicalDecl());
494 ID.AddPointer(getAddrLabelDiffRHS()->getLabel()->getCanonicalDecl());
495 return;
496
497 case Struct:
498 for (unsigned I = 0, N = getStructNumBases(); I != N; ++I)
499 getStructBase(I).Profile(ID);
500 for (unsigned I = 0, N = getStructNumFields(); I != N; ++I)
501 getStructField(I).Profile(ID);
502 return;
503
504 case Union:
505 if (!getUnionField()) {
506 ID.AddInteger(0);
507 return;
508 }
509 ID.AddInteger(getUnionField()->getFieldIndex() + 1);
511 return;
512
513 case Array: {
514 if (getArraySize() == 0)
515 return;
516
517 // The profile should not depend on whether the array is expanded or
518 // not, but we don't want to profile the array filler many times for
519 // a large array. So treat all equal trailing elements as the filler.
520 // Elements are profiled in reverse order to support this, and the
521 // first profiled element is followed by a count. For example:
522 //
523 // ['a', 'c', 'x', 'x', 'x'] is profiled as
524 // [5, 'x', 3, 'c', 'a']
525 llvm::FoldingSetNodeID FillerID;
528 .Profile(FillerID);
529 ID.AddNodeID(FillerID);
530 unsigned NumFillers = getArraySize() - getArrayInitializedElts();
531 unsigned N = getArrayInitializedElts();
532
533 // Count the number of elements equal to the last one. This loop ends
534 // by adding an integer indicating the number of such elements, with
535 // N set to the number of elements left to profile.
536 while (true) {
537 if (N == 0) {
538 // All elements are fillers.
539 assert(NumFillers == getArraySize());
540 ID.AddInteger(NumFillers);
541 break;
542 }
543
544 // No need to check if the last element is equal to the last
545 // element.
546 if (N != getArraySize()) {
547 llvm::FoldingSetNodeID ElemID;
548 getArrayInitializedElt(N - 1).Profile(ElemID);
549 if (ElemID != FillerID) {
550 ID.AddInteger(NumFillers);
551 ID.AddNodeID(ElemID);
552 --N;
553 break;
554 }
555 }
556
557 // This is a filler.
558 ++NumFillers;
559 --N;
560 }
561
562 // Emit the remaining elements.
563 for (; N != 0; --N)
565 return;
566 }
567
568 case Vector:
569 for (unsigned I = 0, N = getVectorLength(); I != N; ++I)
570 getVectorElt(I).Profile(ID);
571 return;
572
573 case Int:
574 profileIntValue(ID, getInt());
575 return;
576
577 case Float:
578 profileIntValue(ID, getFloat().bitcastToAPInt());
579 return;
580
581 case FixedPoint:
582 profileIntValue(ID, getFixedPoint().getValue());
583 return;
584
585 case ComplexFloat:
586 profileIntValue(ID, getComplexFloatReal().bitcastToAPInt());
587 profileIntValue(ID, getComplexFloatImag().bitcastToAPInt());
588 return;
589
590 case ComplexInt:
593 return;
594
595 case LValue:
597 ID.AddInteger(getLValueOffset().getQuantity());
598 ID.AddInteger((isNullPointer() ? 1 : 0) |
599 (isLValueOnePastTheEnd() ? 2 : 0) |
600 (hasLValuePath() ? 4 : 0));
601 if (hasLValuePath()) {
602 ID.AddInteger(getLValuePath().size());
603 // For uniqueness, we only need to profile the entries corresponding
604 // to union members, but we don't have the type here so we don't know
605 // how to interpret the entries.
607 E.Profile(ID);
608 }
609 return;
610
611 case MemberPointer:
612 ID.AddPointer(getMemberPointerDecl());
613 ID.AddInteger(isMemberPointerToDerivedMember());
614 for (const CXXRecordDecl *D : getMemberPointerPath())
615 ID.AddPointer(D);
616 return;
617 }
618
619 llvm_unreachable("Unknown APValue kind!");
620}
621
622static double GetApproxValue(const llvm::APFloat &F) {
623 llvm::APFloat V = F;
624 bool ignored;
625 V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven,
626 &ignored);
627 return V.convertToDouble();
628}
629
630static bool TryPrintAsStringLiteral(raw_ostream &Out,
631 const PrintingPolicy &Policy,
632 const ArrayType *ATy,
633 ArrayRef<APValue> Inits) {
634 if (Inits.empty())
635 return false;
636
637 QualType Ty = ATy->getElementType();
638 if (!Ty->isAnyCharacterType())
639 return false;
640
641 // Nothing we can do about a sequence that is not null-terminated
642 if (!Inits.back().isInt() || !Inits.back().getInt().isZero())
643 return false;
644
645 Inits = Inits.drop_back();
646
648 Buf.push_back('"');
649
650 // Better than printing a two-digit sequence of 10 integers.
651 constexpr size_t MaxN = 36;
652 StringRef Ellipsis;
653 if (Inits.size() > MaxN && !Policy.EntireContentsOfLargeArray) {
654 Ellipsis = "[...]";
655 Inits =
656 Inits.take_front(std::min(MaxN - Ellipsis.size() / 2, Inits.size()));
657 }
658
659 for (auto &Val : Inits) {
660 if (!Val.isInt())
661 return false;
662 int64_t Char64 = Val.getInt().getExtValue();
663 if (!isASCII(Char64))
664 return false; // Bye bye, see you in integers.
665 auto Ch = static_cast<unsigned char>(Char64);
666 // The diagnostic message is 'quoted'
667 StringRef Escaped = escapeCStyle<EscapeChar::SingleAndDouble>(Ch);
668 if (Escaped.empty()) {
669 if (!isPrintable(Ch))
670 return false;
671 Buf.emplace_back(Ch);
672 } else {
673 Buf.append(Escaped);
674 }
675 }
676
677 Buf.append(Ellipsis);
678 Buf.push_back('"');
679
680 if (Ty->isWideCharType())
681 Out << 'L';
682 else if (Ty->isChar8Type())
683 Out << "u8";
684 else if (Ty->isChar16Type())
685 Out << 'u';
686 else if (Ty->isChar32Type())
687 Out << 'U';
688
689 Out << Buf;
690 return true;
691}
692
693void APValue::printPretty(raw_ostream &Out, const ASTContext &Ctx,
694 QualType Ty) const {
695 printPretty(Out, Ctx.getPrintingPolicy(), Ty, &Ctx);
696}
697
698void APValue::printPretty(raw_ostream &Out, const PrintingPolicy &Policy,
699 QualType Ty, const ASTContext *Ctx) const {
700 // There are no objects of type 'void', but values of this type can be
701 // returned from functions.
702 if (Ty->isVoidType()) {
703 Out << "void()";
704 return;
705 }
706
707 if (const auto *AT = Ty->getAs<AtomicType>())
708 Ty = AT->getValueType();
709
710 switch (getKind()) {
711 case APValue::None:
712 Out << "<out of lifetime>";
713 return;
715 Out << "<uninitialized>";
716 return;
717 case APValue::Int:
718 if (Ty->isBooleanType())
719 Out << (getInt().getBoolValue() ? "true" : "false");
720 else
721 Out << getInt();
722 return;
723 case APValue::Float:
724 Out << GetApproxValue(getFloat());
725 return;
727 Out << getFixedPoint();
728 return;
729 case APValue::Vector: {
730 Out << '{';
731 QualType ElemTy = Ty->castAs<VectorType>()->getElementType();
732 getVectorElt(0).printPretty(Out, Policy, ElemTy, Ctx);
733 for (unsigned i = 1; i != getVectorLength(); ++i) {
734 Out << ", ";
735 getVectorElt(i).printPretty(Out, Policy, ElemTy, Ctx);
736 }
737 Out << '}';
738 return;
739 }
741 Out << getComplexIntReal() << "+" << getComplexIntImag() << "i";
742 return;
744 Out << GetApproxValue(getComplexFloatReal()) << "+"
746 return;
747 case APValue::LValue: {
748 bool IsReference = Ty->isReferenceType();
749 QualType InnerTy
750 = IsReference ? Ty.getNonReferenceType() : Ty->getPointeeType();
751 if (InnerTy.isNull())
752 InnerTy = Ty;
753
755 if (!Base) {
756 if (isNullPointer()) {
757 Out << (Policy.Nullptr ? "nullptr" : "0");
758 } else if (IsReference) {
759 Out << "*(" << InnerTy.stream(Policy) << "*)"
761 } else {
762 Out << "(" << Ty.stream(Policy) << ")"
764 }
765 return;
766 }
767
768 if (!hasLValuePath()) {
769 // No lvalue path: just print the offset.
771 CharUnits S = Ctx ? Ctx->getTypeSizeInCharsIfKnown(InnerTy).value_or(
773 : CharUnits::Zero();
774 if (!O.isZero()) {
775 if (IsReference)
776 Out << "*(";
777 if (S.isZero() || O % S) {
778 Out << "(char*)";
779 S = CharUnits::One();
780 }
781 Out << '&';
782 } else if (!IsReference) {
783 Out << '&';
784 }
785
786 if (const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>())
787 Out << *VD;
788 else if (TypeInfoLValue TI = Base.dyn_cast<TypeInfoLValue>()) {
789 TI.print(Out, Policy);
790 } else if (DynamicAllocLValue DA = Base.dyn_cast<DynamicAllocLValue>()) {
791 Out << "{*new "
792 << Base.getDynamicAllocType().stream(Policy) << "#"
793 << DA.getIndex() << "}";
794 } else {
795 assert(Base.get<const Expr *>() != nullptr &&
796 "Expecting non-null Expr");
797 Base.get<const Expr*>()->printPretty(Out, nullptr, Policy);
798 }
799
800 if (!O.isZero()) {
801 Out << " + " << (O / S);
802 if (IsReference)
803 Out << ')';
804 }
805 return;
806 }
807
808 // We have an lvalue path. Print it out nicely.
809 if (!IsReference)
810 Out << '&';
811 else if (isLValueOnePastTheEnd())
812 Out << "*(&";
813
814 QualType ElemTy = Base.getType();
815 if (const ValueDecl *VD = Base.dyn_cast<const ValueDecl*>()) {
816 Out << *VD;
817 } else if (TypeInfoLValue TI = Base.dyn_cast<TypeInfoLValue>()) {
818 TI.print(Out, Policy);
819 } else if (DynamicAllocLValue DA = Base.dyn_cast<DynamicAllocLValue>()) {
820 Out << "{*new " << Base.getDynamicAllocType().stream(Policy) << "#"
821 << DA.getIndex() << "}";
822 } else {
823 const Expr *E = Base.get<const Expr*>();
824 assert(E != nullptr && "Expecting non-null Expr");
825 E->printPretty(Out, nullptr, Policy);
826 }
827
829 const CXXRecordDecl *CastToBase = nullptr;
830 for (unsigned I = 0, N = Path.size(); I != N; ++I) {
831 if (ElemTy->isRecordType()) {
832 // The lvalue refers to a class type, so the next path entry is a base
833 // or member.
834 const Decl *BaseOrMember = Path[I].getAsBaseOrMember().getPointer();
835 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(BaseOrMember)) {
836 CastToBase = RD;
837 // Leave ElemTy referring to the most-derived class. The actual type
838 // doesn't matter except for array types.
839 } else {
840 const ValueDecl *VD = cast<ValueDecl>(BaseOrMember);
841 Out << ".";
842 if (CastToBase)
843 Out << *CastToBase << "::";
844 Out << *VD;
845 ElemTy = VD->getType();
846 }
847 } else if (ElemTy->isAnyComplexType()) {
848 // The lvalue refers to a complex type
849 Out << (Path[I].getAsArrayIndex() == 0 ? ".real" : ".imag");
850 ElemTy = ElemTy->castAs<ComplexType>()->getElementType();
851 } else {
852 // The lvalue must refer to an array.
853 Out << '[' << Path[I].getAsArrayIndex() << ']';
854 ElemTy = ElemTy->castAsArrayTypeUnsafe()->getElementType();
855 }
856 }
857
858 // Handle formatting of one-past-the-end lvalues.
859 if (isLValueOnePastTheEnd()) {
860 // FIXME: If CastToBase is non-0, we should prefix the output with
861 // "(CastToBase*)".
862 Out << " + 1";
863 if (IsReference)
864 Out << ')';
865 }
866 return;
867 }
868 case APValue::Array: {
869 const ArrayType *AT = Ty->castAsArrayTypeUnsafe();
870 unsigned N = getArrayInitializedElts();
871 if (N != 0 && TryPrintAsStringLiteral(Out, Policy, AT,
872 {&getArrayInitializedElt(0), N}))
873 return;
874 QualType ElemTy = AT->getElementType();
875 Out << '{';
876 unsigned I = 0;
877 switch (N) {
878 case 0:
879 for (; I != N; ++I) {
880 Out << ", ";
881 if (I == 10 && !Policy.EntireContentsOfLargeArray) {
882 Out << "...}";
883 return;
884 }
885 [[fallthrough]];
886 default:
887 getArrayInitializedElt(I).printPretty(Out, Policy, ElemTy, Ctx);
888 }
889 }
890 Out << '}';
891 return;
892 }
893 case APValue::Struct: {
894 Out << '{';
895 const RecordDecl *RD = Ty->castAs<RecordType>()->getDecl();
896 bool First = true;
897 if (unsigned N = getStructNumBases()) {
898 const CXXRecordDecl *CD = cast<CXXRecordDecl>(RD);
900 for (unsigned I = 0; I != N; ++I, ++BI) {
901 assert(BI != CD->bases_end());
902 if (!First)
903 Out << ", ";
904 getStructBase(I).printPretty(Out, Policy, BI->getType(), Ctx);
905 First = false;
906 }
907 }
908 for (const auto *FI : RD->fields()) {
909 if (!First)
910 Out << ", ";
911 if (FI->isUnnamedBitField())
912 continue;
913 getStructField(FI->getFieldIndex()).
914 printPretty(Out, Policy, FI->getType(), Ctx);
915 First = false;
916 }
917 Out << '}';
918 return;
919 }
920 case APValue::Union:
921 Out << '{';
922 if (const FieldDecl *FD = getUnionField()) {
923 Out << "." << *FD << " = ";
924 getUnionValue().printPretty(Out, Policy, FD->getType(), Ctx);
925 }
926 Out << '}';
927 return;
929 // FIXME: This is not enough to unambiguously identify the member in a
930 // multiple-inheritance scenario.
931 if (const ValueDecl *VD = getMemberPointerDecl()) {
932 Out << '&' << *cast<CXXRecordDecl>(VD->getDeclContext()) << "::" << *VD;
933 return;
934 }
935 Out << "0";
936 return;
938 Out << "&&" << getAddrLabelDiffLHS()->getLabel()->getName();
939 Out << " - ";
940 Out << "&&" << getAddrLabelDiffRHS()->getLabel()->getName();
941 return;
942 }
943 llvm_unreachable("Unknown APValue kind!");
944}
945
946std::string APValue::getAsString(const ASTContext &Ctx, QualType Ty) const {
947 std::string Result;
948 llvm::raw_string_ostream Out(Result);
949 printPretty(Out, Ctx, Ty);
950 Out.flush();
951 return Result;
952}
953
955 const ASTContext &Ctx) const {
956 if (isInt()) {
957 Result = getInt();
958 return true;
959 }
960
961 if (isLValue() && isNullPointer()) {
962 Result = Ctx.MakeIntValue(Ctx.getTargetNullPointerValue(SrcTy), SrcTy);
963 return true;
964 }
965
966 if (isLValue() && !getLValueBase()) {
967 Result = Ctx.MakeIntValue(getLValueOffset().getQuantity(), SrcTy);
968 return true;
969 }
970
971 return false;
972}
973
975 assert(isLValue() && "Invalid accessor");
976 return ((const LV *)(const void *)&Data)->Base;
977}
978
980 assert(isLValue() && "Invalid accessor");
981 return ((const LV *)(const void *)&Data)->IsOnePastTheEnd;
982}
983
985 assert(isLValue() && "Invalid accessor");
986 return ((LV *)(void *)&Data)->Offset;
987}
988
990 assert(isLValue() && "Invalid accessor");
991 return ((const LV *)(const char *)&Data)->hasPath();
992}
993
995 assert(isLValue() && hasLValuePath() && "Invalid accessor");
996 const LV &LVal = *((const LV *)(const char *)&Data);
997 return llvm::ArrayRef(LVal.getPath(), LVal.PathLength);
998}
999
1001 assert(isLValue() && "Invalid accessor");
1002 return ((const LV *)(const char *)&Data)->Base.getCallIndex();
1003}
1004
1006 assert(isLValue() && "Invalid accessor");
1007 return ((const LV *)(const char *)&Data)->Base.getVersion();
1008}
1009
1011 assert(isLValue() && "Invalid usage");
1012 return ((const LV *)(const char *)&Data)->IsNullPtr;
1013}
1014
1016 bool IsNullPtr) {
1017 assert(isLValue() && "Invalid accessor");
1018 LV &LVal = *((LV *)(char *)&Data);
1019 LVal.Base = B;
1020 LVal.IsOnePastTheEnd = false;
1021 LVal.Offset = O;
1022 LVal.resizePath((unsigned)-1);
1023 LVal.IsNullPtr = IsNullPtr;
1024}
1025
1027APValue::setLValueUninit(LValueBase B, const CharUnits &O, unsigned Size,
1028 bool IsOnePastTheEnd, bool IsNullPtr) {
1029 assert(isLValue() && "Invalid accessor");
1030 LV &LVal = *((LV *)(char *)&Data);
1031 LVal.Base = B;
1032 LVal.IsOnePastTheEnd = IsOnePastTheEnd;
1033 LVal.Offset = O;
1034 LVal.IsNullPtr = IsNullPtr;
1035 LVal.resizePath(Size);
1036 return {LVal.getPath(), Size};
1037}
1038
1040 ArrayRef<LValuePathEntry> Path, bool IsOnePastTheEnd,
1041 bool IsNullPtr) {
1043 setLValueUninit(B, O, Path.size(), IsOnePastTheEnd, IsNullPtr);
1044 if (Path.size()) {
1045 memcpy(InternalPath.data(), Path.data(),
1046 Path.size() * sizeof(LValuePathEntry));
1047 }
1048}
1049
1050void APValue::setUnion(const FieldDecl *Field, const APValue &Value) {
1051 assert(isUnion() && "Invalid accessor");
1052 ((UnionData *)(char *)&Data)->Field =
1053 Field ? Field->getCanonicalDecl() : nullptr;
1054 *((UnionData *)(char *)&Data)->Value = Value;
1055}
1056
1058 assert(isMemberPointer() && "Invalid accessor");
1059 const MemberPointerData &MPD =
1060 *((const MemberPointerData *)(const char *)&Data);
1061 return MPD.MemberAndIsDerivedMember.getPointer();
1062}
1063
1065 assert(isMemberPointer() && "Invalid accessor");
1066 const MemberPointerData &MPD =
1067 *((const MemberPointerData *)(const char *)&Data);
1068 return MPD.MemberAndIsDerivedMember.getInt();
1069}
1070
1072 assert(isMemberPointer() && "Invalid accessor");
1073 const MemberPointerData &MPD =
1074 *((const MemberPointerData *)(const char *)&Data);
1075 return llvm::ArrayRef(MPD.getPath(), MPD.PathLength);
1076}
1077
1078void APValue::MakeLValue() {
1079 assert(isAbsent() && "Bad state change");
1080 static_assert(sizeof(LV) <= DataSize, "LV too big");
1081 new ((void *)(char *)&Data) LV();
1082 Kind = LValue;
1083}
1084
1085void APValue::MakeArray(unsigned InitElts, unsigned Size) {
1086 assert(isAbsent() && "Bad state change");
1087 new ((void *)(char *)&Data) Arr(InitElts, Size);
1088 Kind = Array;
1089}
1090
1093 bool OnePastTheEnd, bool IsNullPtr);
1094
1096APValue::setMemberPointerUninit(const ValueDecl *Member, bool IsDerivedMember,
1097 unsigned Size) {
1098 assert(isAbsent() && "Bad state change");
1099 MemberPointerData *MPD = new ((void *)(char *)&Data) MemberPointerData;
1100 Kind = MemberPointer;
1101 MPD->MemberAndIsDerivedMember.setPointer(
1102 Member ? cast<ValueDecl>(Member->getCanonicalDecl()) : nullptr);
1103 MPD->MemberAndIsDerivedMember.setInt(IsDerivedMember);
1104 MPD->resizePath(Size);
1105 return {MPD->getPath(), MPD->PathLength};
1106}
1107
1108void APValue::MakeMemberPointer(const ValueDecl *Member, bool IsDerivedMember,
1111 setMemberPointerUninit(Member, IsDerivedMember, Path.size());
1112 for (unsigned I = 0; I != Path.size(); ++I)
1113 InternalPath[I] = Path[I]->getCanonicalDecl();
1114}
1115
1116LinkageInfo LinkageComputer::getLVForValue(const APValue &V,
1117 LVComputationKind computation) {
1119
1120 auto MergeLV = [&](LinkageInfo MergeLV) {
1121 LV.merge(MergeLV);
1122 return LV.getLinkage() == Linkage::Internal;
1123 };
1124 auto Merge = [&](const APValue &V) {
1125 return MergeLV(getLVForValue(V, computation));
1126 };
1127
1128 switch (V.getKind()) {
1129 case APValue::None:
1131 case APValue::Int:
1132 case APValue::Float:
1136 case APValue::Vector:
1137 break;
1138
1140 // Even for an inline function, it's not reasonable to treat a difference
1141 // between the addresses of labels as an external value.
1142 return LinkageInfo::internal();
1143
1144 case APValue::Struct: {
1145 for (unsigned I = 0, N = V.getStructNumBases(); I != N; ++I)
1146 if (Merge(V.getStructBase(I)))
1147 break;
1148 for (unsigned I = 0, N = V.getStructNumFields(); I != N; ++I)
1149 if (Merge(V.getStructField(I)))
1150 break;
1151 break;
1152 }
1153
1154 case APValue::Union:
1155 if (V.getUnionField())
1156 Merge(V.getUnionValue());
1157 break;
1158
1159 case APValue::Array: {
1160 for (unsigned I = 0, N = V.getArrayInitializedElts(); I != N; ++I)
1161 if (Merge(V.getArrayInitializedElt(I)))
1162 break;
1163 if (V.hasArrayFiller())
1164 Merge(V.getArrayFiller());
1165 break;
1166 }
1167
1168 case APValue::LValue: {
1169 if (!V.getLValueBase()) {
1170 // Null or absolute address: this is external.
1171 } else if (const auto *VD =
1172 V.getLValueBase().dyn_cast<const ValueDecl *>()) {
1173 if (VD && MergeLV(getLVForDecl(VD, computation)))
1174 break;
1175 } else if (const auto TI = V.getLValueBase().dyn_cast<TypeInfoLValue>()) {
1176 if (MergeLV(getLVForType(*TI.getType(), computation)))
1177 break;
1178 } else if (const Expr *E = V.getLValueBase().dyn_cast<const Expr *>()) {
1179 // Almost all expression bases are internal. The exception is
1180 // lifetime-extended temporaries.
1181 // FIXME: These should be modeled as having the
1182 // LifetimeExtendedTemporaryDecl itself as the base.
1183 // FIXME: If we permit Objective-C object literals in template arguments,
1184 // they should not imply internal linkage.
1185 auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E);
1186 if (!MTE || MTE->getStorageDuration() == SD_FullExpression)
1187 return LinkageInfo::internal();
1188 if (MergeLV(getLVForDecl(MTE->getExtendingDecl(), computation)))
1189 break;
1190 } else {
1191 assert(V.getLValueBase().is<DynamicAllocLValue>() &&
1192 "unexpected LValueBase kind");
1193 return LinkageInfo::internal();
1194 }
1195 // The lvalue path doesn't matter: pointers to all subobjects always have
1196 // the same visibility as pointers to the complete object.
1197 break;
1198 }
1199
1201 if (const NamedDecl *D = V.getMemberPointerDecl())
1202 MergeLV(getLVForDecl(D, computation));
1203 // Note that we could have a base-to-derived conversion here to a member of
1204 // a derived class with less linkage/visibility. That's covered by the
1205 // linkage and visibility of the value's type.
1206 break;
1207 }
1208
1209 return LV;
1210}
static double GetApproxValue(const llvm::APFloat &F)
Definition: APValue.cpp:622
static void profileIntValue(llvm::FoldingSetNodeID &ID, const llvm::APInt &V)
Profile the value of an APInt, excluding its bit-width.
Definition: APValue.cpp:474
static bool TryPrintAsStringLiteral(raw_ostream &Out, const PrintingPolicy &Policy, const ArrayType *ATy, ArrayRef< APValue > Inits)
Definition: APValue.cpp:630
MutableArrayRef< APValue::LValuePathEntry > setLValueUninit(APValue::LValueBase B, const CharUnits &O, unsigned Size, bool OnePastTheEnd, bool IsNullPtr)
Defines the clang::ASTContext interface.
#define V(N, I)
Definition: ASTContext.h:3323
StringRef P
const Decl * D
IndirectLocalPath & Path
Expr * E
llvm::APSInt APSInt
Definition: Compiler.cpp:22
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
static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo)
Definition: APValue.cpp:55
static LValueBase getDynamicAlloc(DynamicAllocLValue LV, QualType Type)
Definition: APValue.cpp:47
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
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:518
const LValueBase getLValueBase() const
Definition: APValue.cpp:974
void setFloat(APFloat F)
Definition: APValue.h:592
APValue & getArrayInitializedElt(unsigned I)
Definition: APValue.h:510
ArrayRef< LValuePathEntry > getLValuePath() const
Definition: APValue.cpp:994
void swap(APValue &RHS)
Swaps the contents of this and the given APValue.
Definition: APValue.cpp:468
APSInt & getInt()
Definition: APValue.h:423
APValue & getStructField(unsigned i)
Definition: APValue.h:551
void setInt(APSInt I)
Definition: APValue.h:588
const FieldDecl * getUnionField() const
Definition: APValue.h:563
APSInt & getComplexIntImag()
Definition: APValue.h:461
unsigned getStructNumFields() const
Definition: APValue.h:542
bool isAbsent() const
Definition: APValue.h:397
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:395
bool isLValueOnePastTheEnd() const
Definition: APValue.cpp:979
unsigned getLValueVersion() const
Definition: APValue.cpp:1005
bool isMemberPointerToDerivedMember() const
Definition: APValue.cpp:1064
unsigned getArrayInitializedElts() const
Definition: APValue.h:529
void setComplexInt(APSInt R, APSInt I)
Definition: APValue.h:605
void Profile(llvm::FoldingSetNodeID &ID) const
profile this value.
Definition: APValue.cpp:479
unsigned getStructNumBases() const
Definition: APValue.h:538
APFixedPoint & getFixedPoint()
Definition: APValue.h:445
bool needsCleanup() const
Returns whether the object performed allocations.
Definition: APValue.cpp:431
bool hasLValuePath() const
Definition: APValue.cpp:989
const ValueDecl * getMemberPointerDecl() const
Definition: APValue.cpp:1057
APValue & getUnionValue()
Definition: APValue.h:567
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition: APValue.h:583
CharUnits & getLValueOffset()
Definition: APValue.cpp:984
void printPretty(raw_ostream &OS, const ASTContext &Ctx, QualType Ty) const
Definition: APValue.cpp:693
void setAddrLabelDiff(const AddrLabelExpr *LHSExpr, const AddrLabelExpr *RHSExpr)
Definition: APValue.h:625
void setComplexFloat(APFloat R, APFloat I)
Definition: APValue.h:612
APValue & getVectorElt(unsigned I)
Definition: APValue.h:497
APValue & getArrayFiller()
Definition: APValue.h:521
unsigned getVectorLength() const
Definition: APValue.h:505
bool isLValue() const
Definition: APValue.h:406
void setUnion(const FieldDecl *Field, const APValue &Value)
Definition: APValue.cpp:1050
void setLValue(LValueBase B, const CharUnits &O, NoLValuePath, bool IsNullPtr)
Definition: APValue.cpp:1015
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition: APValue.cpp:1071
bool isMemberPointer() const
Definition: APValue.h:411
bool isInt() const
Definition: APValue.h:401
unsigned getArraySize() const
Definition: APValue.h:533
bool isUnion() const
Definition: APValue.h:410
bool toIntegralConstant(APSInt &Result, QualType SrcTy, const ASTContext &Ctx) const
Try to convert this value to an integral constant.
Definition: APValue.cpp:954
std::string getAsString(const ASTContext &Ctx, QualType Ty) const
Definition: APValue.cpp:946
APValue & operator=(const APValue &RHS)
Definition: APValue.cpp:386
unsigned getLValueCallIndex() const
Definition: APValue.cpp:1000
void setVector(const APValue *E, unsigned N)
Definition: APValue.h:600
@ 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:1010
APSInt & getComplexIntReal()
Definition: APValue.h:453
APFloat & getComplexFloatImag()
Definition: APValue.h:477
APFloat & getComplexFloatReal()
Definition: APValue.h:469
APFloat & getFloat()
Definition: APValue.h:437
APValue & getStructBase(unsigned i)
Definition: APValue.h:546
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition: APValue.h:579
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:186
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:709
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.
Definition: ASTContext.h:3067
std::optional< CharUnits > getTypeSizeInCharsIfKnown(QualType Ty) const
Definition: ASTContext.h:2401
LabelDecl * getLabel() const
Definition: Expr.h:4366
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3537
QualType getElementType() const
Definition: Type.h:3549
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
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:628
base_class_iterator bases_begin()
Definition: DeclCXX.h:626
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
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Definition: CharUnits.h:53
Complex values, per C99 6.2.5p11.
Definition: Type.h:3105
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
Definition: DeclBase.h:1055
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:957
Symbolic representation of a dynamic allocation.
Definition: APValue.h:65
This represents one expression.
Definition: Expr.h:110
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:82
Represents a member of a struct/union/class.
Definition: Decl.h:3030
LinkageInfo getLVForDecl(const NamedDecl *D, LVComputationKind computation)
getLVForDecl - Get the linkage and visibility for the given declaration.
Definition: Decl.cpp:1568
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:4726
This represents a decl that may have a name.
Definition: Decl.h:249
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
A (possibly-)qualified type.
Definition: Type.h:942
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:1009
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:991
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: Type.h:7945
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Definition: Type.h:1396
Represents a struct/union/class.
Definition: Decl.h:4141
field_range fields() const
Definition: Decl.h:4347
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5937
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical, bool ProfileLambdaExpr=false) const
Produce a unique representation of the given statement.
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: Type.h:1826
bool isVoidType() const
Definition: Type.h:8296
bool isBooleanType() const
Definition: Type.h:8424
bool isIncompleteArrayType() const
Definition: Type.h:8073
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type.
Definition: Type.h:8593
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:8584
bool isReferenceType() const
Definition: Type.h:8011
bool isChar8Type() const
Definition: Type.cpp:2104
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:705
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
Definition: Type.cpp:2124
bool isChar16Type() const
Definition: Type.cpp:2110
bool isAnyComplexType() const
Definition: Type.h:8101
bool isChar32Type() const
Definition: Type.cpp:2116
bool isWideCharType() const
Definition: Type.cpp:2097
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8517
bool isRecordType() const
Definition: Type.h:8093
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:667
QualType getType() const
Definition: Decl.h:678
Represents a GCC generic vector type.
Definition: Type.h:3988
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
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
Definition: CallGraph.h:207
@ Internal
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
@ SD_FullExpression
Full-expression storage duration (for temporaries).
Definition: Specifiers.h:325
@ Result
The result type of a method or function.
llvm::hash_code hash_value(const CustomizableOptional< T > &O)
const FunctionProtoType * T
U cast(CodeGen::Address addr)
Definition: Address.h:291
hash_code hash_value(const clang::tooling::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...
#define bool
Definition: stdbool.h:24
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
const LValuePathEntry * getPath() const
Definition: APValue.cpp:250
LValuePathEntry * getPath()
Definition: APValue.cpp:249
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.
Definition: PrettyPrinter.h:57
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,...