1//===--- Pointer.h - Types for the constexpr VM -----------------*- C++ -*-===//
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// Defines the classes responsible for pointer tracking.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_INTERP_POINTER_H
14#define LLVM_CLANG_AST_INTERP_POINTER_H
15
16#include "Block.h"
17#include "Descriptor.h"
18#include "Function.h"
19#include "InitMap.h"
20#include "clang/AST/ComparisonCategories.h"
21#include "clang/AST/Decl.h"
22#include "clang/AST/DeclCXX.h"
23#include "clang/AST/Expr.h"
24#include "llvm/Support/raw_ostream.h"
25
26namespace clang {
27namespace interp {
28class Block;
29class DeadBlock;
30class Pointer;
31class Context;
32
33class Pointer;
34inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Pointer &P);
35
36struct PtrView {
37 static constexpr unsigned PastEndMark = ~0u;
38
39 Block *Pointee;
40 unsigned Base;
41 uint64_t Offset;
42
43 bool isZero() const { return !Pointee; }
44 bool isLive() const { return Pointee && !Pointee->isDead(); }
45 bool isActive() const { return isRoot() || getInlineDesc()->IsActive; }
46 bool isArrayRoot() const { return inArray() && Offset == Base; }
47 bool isElementPastEnd() const { return Offset == PastEndMark; }
48 bool isZeroSizeArray() const { return getFieldDesc()->isZeroSizeArray(); }
49 bool isMutable() const {
50 return !isRoot() && getInlineDesc()->IsFieldMutable;
51 }
52 bool isConstInMutable() const {
53 return !isRoot() && getInlineDesc()->IsConstInMutable;
54 }
55 bool isExtern() const { return Pointee && Pointee->isExtern(); }
56 bool isVolatile() const {
57 return isRoot() ? getDeclDesc()->IsVolatile : getInlineDesc()->IsVolatile;
58 }
59 bool inUnion() const { return getInlineDesc()->InUnion; };
60 bool inArray() const { return getFieldDesc()->IsArray; }
61 bool inPrimitiveArray() const { return getFieldDesc()->isPrimitiveArray(); }
62 const Block *block() const { return Pointee; }
63
64 bool isRoot() const { return Base == 0; }
65
66 bool isConst() const {
67 return isRoot() ? getDeclDesc()->IsConst : getInlineDesc()->IsConst;
68 }
69
70 InlineDescriptor *getInlineDesc() const {
71 assert(Base <= Pointee->getSize());
72 assert(Base != 0);
73 return getDescriptor(Offset: Base);
74 }
75
76 InlineDescriptor *getDescriptor(unsigned Offset) const {
77 assert(Offset != 0 && "Not a nested pointer");
78 assert(Offset >= sizeof(InlineDescriptor));
79 return reinterpret_cast<InlineDescriptor *>(Pointee->data() + Offset) - 1;
80 }
81
82 const Descriptor *getFieldDesc() const {
83 if (isRoot())
84 return Pointee->getDescriptor();
85 return getInlineDesc()->Desc;
86 }
87
88 const Descriptor *getDeclDesc() const { return Pointee->getDescriptor(); }
89
90 size_t elemSize() const { return getFieldDesc()->getElemSize(); }
91
92 [[nodiscard]] PtrView narrow() const {
93 // Null pointers cannot be narrowed.
94 if (isZero() || isUnknownSizeArray())
95 return *this;
96
97 if (inArray()) {
98 // Pointer is one past end - magic offset marks that.
99 if (isOnePastEnd())
100 return PtrView{.Pointee: Pointee, .Base: Base, .Offset: PastEndMark};
101
102 if (Offset != Base) {
103 // If we're pointing to a primitive array element, there's nothing to
104 // do.
105 if (inPrimitiveArray())
106 return *this;
107 // Pointer is to a composite array element - enter it.
108 return PtrView{.Pointee: Pointee, .Base: static_cast<unsigned>(Offset), .Offset: Offset};
109 }
110 }
111 // Otherwise, we're pointing to a non-array element or
112 // are already narrowed to a composite array element. Nothing to do.
113 return *this;
114 }
115
116 [[nodiscard]] PtrView expand() const {
117 if (isElementPastEnd()) {
118 // Revert to an outer one-past-end pointer.
119 unsigned Adjust;
120 if (inPrimitiveArray())
121 Adjust = sizeof(InitMapPtr);
122 else
123 Adjust = sizeof(InlineDescriptor);
124 return PtrView{.Pointee: Pointee, .Base: Base, .Offset: Base + getSize() + Adjust};
125 }
126
127 // Do not step out of array elements.
128 if (Base != Offset)
129 return *this;
130
131 if (isRoot())
132 return PtrView{.Pointee: Pointee, .Base: Base, .Offset: Base};
133
134 // Step into the containing array, if inside one.
135 unsigned Next = Base - getInlineDesc()->Offset;
136 const Descriptor *Desc =
137 (Next == 0) ? getDeclDesc() : getDescriptor(Offset: Next)->Desc;
138 if (!Desc->IsArray)
139 return *this;
140 return PtrView{.Pointee: Pointee, .Base: Next, .Offset: Offset};
141 }
142
143 [[nodiscard]] PtrView stripBaseCasts() const {
144 PtrView V = *this;
145 while (V.isBaseClass())
146 V = V.getBase();
147 return V;
148 }
149
150 [[nodiscard]] PtrView getArray() const {
151 assert(Offset != Base && "not an array element");
152 return PtrView{.Pointee: Pointee, .Base: Base, .Offset: Base};
153 }
154
155 const Record *getRecord() const { return getFieldDesc()->ElemRecord; }
156 const Record *getElemRecord() const {
157 const Descriptor *ElemDesc = getFieldDesc()->ElemDesc;
158 return ElemDesc ? ElemDesc->ElemRecord : nullptr;
159 }
160 const FieldDecl *getField() const { return getFieldDesc()->asFieldDecl(); }
161
162 bool isField() const {
163 return !isZero() && !isRoot() && getFieldDesc()->asDecl();
164 }
165
166 bool isBaseClass() const { return isField() && getInlineDesc()->IsBase; }
167 bool isVirtualBaseClass() const {
168 return isField() && getInlineDesc()->IsVirtualBase;
169 }
170 bool isUnknownSizeArray() const {
171 return getFieldDesc()->isUnknownSizeArray();
172 }
173
174 bool isPastEnd() const { return Offset > Pointee->getSize(); }
175
176 unsigned getOffset() const {
177 assert(Offset != PastEndMark);
178
179 unsigned Adjust = 0;
180 if (Offset != Base) {
181 if (getFieldDesc()->ElemDesc)
182 Adjust = sizeof(InlineDescriptor);
183 else
184 Adjust = sizeof(InitMapPtr);
185 }
186 return Offset - Base - Adjust;
187 }
188 size_t getSize() const { return getFieldDesc()->getSize(); }
189
190 bool isOnePastEnd() const {
191 if (!Pointee)
192 return false;
193
194 const Descriptor *Desc = getFieldDesc();
195 if (Desc->isUnknownSizeArray())
196 return false;
197
198 if (isPastEnd())
199 return true;
200
201 if (Offset != Base) {
202 unsigned Adjust =
203 Desc->ElemDesc ? sizeof(InlineDescriptor) : sizeof(InitMapPtr);
204 unsigned Off = Offset - Base - Adjust;
205 return Desc->getSize() == Off;
206 }
207
208 return Desc->getSize() == 0;
209 }
210
211 PtrView atIndex(unsigned Idx) const {
212 unsigned Off = Idx * elemSize();
213 if (getFieldDesc()->ElemDesc)
214 Off += sizeof(InlineDescriptor);
215 else
216 Off += sizeof(InitMapPtr);
217 return PtrView{.Pointee: Pointee, .Base: Base, .Offset: Base + Off};
218 }
219
220 int64_t getIndex() const {
221 if (isZero())
222 return 0;
223 // narrow()ed element in a composite array.
224 if (Base != 0 && Base == Offset)
225 return 0;
226
227 if (auto ElemSize = elemSize())
228 return getOffset() / ElemSize;
229 return 0;
230 }
231
232 unsigned getNumElems() const { return getSize() / elemSize(); }
233
234 bool isArrayElement() const {
235 if (inArray() && Base != Offset)
236 return true;
237
238 // Might be a narrow()'ed element in a composite array.
239 // Check the inline descriptor.
240 if (Base != 0 && getInlineDesc()->IsArrayElement)
241 return true;
242
243 return false;
244 }
245
246 template <typename T> T &deref() const {
247 assert(isLive() && "Invalid pointer");
248 assert(Pointee);
249 assert(!isArrayRoot());
250 return *reinterpret_cast<T *>(Pointee->data() + Offset);
251 }
252
253 template <typename T> T &elem(unsigned I) const {
254 assert(isLive() && "Invalid pointer");
255 assert(Pointee);
256 assert(getFieldDesc()->isPrimitiveArray());
257 assert(I < getFieldDesc()->getNumElems());
258
259 unsigned ElemByteOffset = I * getFieldDesc()->getElemSize();
260 unsigned ReadOffset = Base + sizeof(InitMapPtr) + ElemByteOffset;
261 assert(ReadOffset + sizeof(T) <= Pointee->getSize());
262
263 return *reinterpret_cast<T *>(Pointee->data() + ReadOffset);
264 }
265
266 [[nodiscard]] PtrView getBase() const {
267 unsigned NewBase = Base - getInlineDesc()->Offset;
268 return PtrView{.Pointee: Pointee, .Base: NewBase, .Offset: NewBase};
269 }
270
271 [[nodiscard]] PtrView atField(unsigned Offset) const {
272 unsigned F = this->Offset + Offset;
273 return PtrView{.Pointee: Pointee, .Base: F, .Offset: F};
274 }
275
276 QualType getType() const {
277 if (isRoot() && Base == Offset) {
278 // If this pointer points to the root of a declaration, try to consult
279 // the ValueDecl directly, since that has a type with more information,
280 // e.g. the correct ElaboratedTypeKeyword.
281 if (const ValueDecl *VD = getDeclDesc()->asValueDecl())
282 return VD->getType();
283 return getDeclDesc()->getType();
284 }
285 if (inPrimitiveArray() && Offset != Base) {
286 // Unfortunately, complex and vector types are not array types in clang,
287 // but they are for us.
288 if (const auto *AT = getFieldDesc()->getType()->getAsArrayTypeUnsafe())
289 return AT->getElementType();
290 if (const auto *CT = getFieldDesc()->getType()->getAs<ComplexType>())
291 return CT->getElementType();
292 if (const auto *CT = getFieldDesc()->getType()->getAs<VectorType>())
293 return CT->getElementType();
294 }
295
296 return getFieldDesc()->getType();
297 }
298
299 bool isInitialized() const {
300 if (!Pointee->isInitialized())
301 return false;
302
303 if (Offset == 0) {
304 if (Pointee->isGlobal()) {
305 const auto &GD = Pointee->getBlockDesc<GlobalInlineDescriptor>();
306 return GD.InitState == GlobalInitState::Initialized;
307 }
308 if (Pointee->isLocal()) {
309 const auto &LD = Pointee->getBlockDesc<LocalInlineDescriptor>();
310 return LD.IsInitialized;
311 }
312 return true;
313 }
314
315 assert(Pointee && "Cannot check if null pointer was initialized");
316 const Descriptor *Desc = getFieldDesc();
317 assert(Desc);
318 if (Offset != Base && Desc->isPrimitiveArray())
319 return isElementInitialized(Index: getIndex());
320
321 // Field has its bit in an inline descriptor.
322 return getDescriptor(Offset)->IsInitialized;
323 }
324
325 void initializeElement(unsigned Index) const;
326 bool allElementsInitialized() const;
327 bool isElementInitialized(unsigned Index) const;
328 InitMapPtr &getInitMap() const {
329 return *reinterpret_cast<InitMapPtr *>(Pointee->data() + Base);
330 }
331 void initialize() const;
332 void activate() const;
333
334 void setLifeState(Lifetime L) const;
335 Lifetime getLifetime() const;
336 void startLifetime() const { setLifeState(Lifetime::Started); }
337 void endLifetime() const { setLifeState(Lifetime::Ended); }
338
339 bool operator==(const PtrView &Other) const {
340 return Other.Pointee == Pointee && Base == Other.Base &&
341 Offset == Other.Offset;
342 }
343
344 bool operator!=(const PtrView &Other) const { return !(Other == *this); }
345};
346
347struct BlockPointer {
348 /// The block the pointer is pointing to.
349 Block *Pointee;
350 /// Start of the current subfield.
351 unsigned Base;
352 /// Previous link in the pointer chain.
353 Pointer *Prev;
354 /// Next link in the pointer chain.
355 Pointer *Next;
356};
357
358struct IntPointer {
359 llvm::PointerIntPair<const Type *, 1, bool> TypeAndIsNull;
360 uint64_t Value;
361
362 std::optional<IntPointer> atOffset(const Context &Ctx, unsigned Offset) const;
363 IntPointer baseCast(const Context &Ctx, unsigned BaseOffset) const;
364
365 const Type *getType() const { return TypeAndIsNull.getPointer(); }
366 bool isNull() const { return TypeAndIsNull.getInt(); }
367
368 QualType getPointeeType() const {
369 if (!getType())
370 return QualType();
371
372 QualType QT(getType(), 0);
373 if (QT->isPointerOrReferenceType())
374 QT = QT->getPointeeType();
375 else if (QT->isArrayType())
376 QT = QT->getAsArrayTypeUnsafe()->getElementType();
377
378 return QT.IgnoreParens();
379 }
380};
381
382struct FunctionPointer {
383 const Function *Func;
384};
385
386struct TypeidPointer {
387 const Type *TypePtr;
388 const Type *TypeInfoType;
389};
390
391struct StringPointer {
392 const Expr *Base = nullptr;
393 unsigned ID = 0;
394 bool Decayed = false;
395
396 StringPointer decay() const { return StringPointer{.Base: Base, .ID: ID, .Decayed: true}; }
397 const StringLiteral *getLiteral() const {
398 if (const auto *PE = dyn_cast<PredefinedExpr>(Val: Base))
399 return PE->getFunctionName();
400 return cast<StringLiteral>(Val: Base);
401 }
402};
403
404struct PointerPathEntry {
405 enum { Base, Field, Array, NegativeArray } Kind;
406 union {
407 uint64_t Index;
408 const FieldDecl *FD;
409 llvm::PointerIntPair<const CXXRecordDecl *, 1, bool> RD = {};
410 };
411
412 static PointerPathEntry base(const CXXRecordDecl *RD, bool Virtual = false) {
413 PointerPathEntry E;
414 E.Kind = Base;
415 E.RD = {RD, Virtual};
416 return E;
417 }
418
419 static PointerPathEntry array(int64_t Index) {
420 PointerPathEntry E;
421 E.Kind = Array;
422 E.Index = Index;
423 return E;
424 }
425
426 static PointerPathEntry negativeArray(int64_t Index) {
427 PointerPathEntry E;
428 E.Kind = NegativeArray;
429 E.Index = Index;
430 return E;
431 }
432
433 static PointerPathEntry field(const FieldDecl *FD) {
434 PointerPathEntry E;
435 E.Kind = Field;
436 E.FD = FD;
437 return E;
438 }
439};
440
441struct OpaquePointer {
442 DeclOrExpr Base;
443 // FieldType and IsOnePastEnd/IsConstexprUnknown bits.
444 llvm::PointerIntPair<const Type *, 2, unsigned> FieldType = {};
445 const PointerPathEntry *Path = nullptr;
446 unsigned PathLength = 0;
447
448 ArrayRef<PointerPathEntry> path() const { return ArrayRef(Path, PathLength); }
449 bool hasDeclBase() const { return Base.isDecl(); }
450 const ValueDecl *getBaseDecl() const { return Base.asValueDecl(); }
451 const VarDecl *getBaseVarDecl() const { return Base.asVarDecl(); }
452 const Expr *getBaseExpr() const { return Base.asExpr(); }
453 bool hasValidBase() const;
454
455 OpaquePointer
456 withFieldType(const Type *FieldTy,
457 std::optional<bool> PastEnd = std::nullopt) const {
458 unsigned NewBitFieldValue = FieldType.getInt();
459 if (PastEnd)
460 NewBitFieldValue =
461 (isConstexprUnknown() ? 2u : 0u) + static_cast<unsigned>(*PastEnd);
462 return OpaquePointer{.Base: Base, .FieldType: {FieldTy, NewBitFieldValue}, .Path: Path, .PathLength: PathLength};
463 }
464
465 OpaquePointer withPath(const PointerPathEntry *Path, unsigned PathLength,
466 const Type *FieldTy,
467 std::optional<bool> PastEnd = std::nullopt) const {
468 unsigned NewBitFieldValue = FieldType.getInt();
469 if (PastEnd)
470 NewBitFieldValue =
471 (isConstexprUnknown() ? 2u : 0u) + static_cast<unsigned>(*PastEnd);
472 return OpaquePointer{.Base: Base, .FieldType: {FieldTy, NewBitFieldValue}, .Path: Path, .PathLength: PathLength};
473 }
474
475 OpaquePointer withPastEnd(bool PastEnd) const {
476 return OpaquePointer{.Base: Base,
477 .FieldType: {FieldType.getPointer(),
478 FieldType.getInt() | static_cast<unsigned>(PastEnd)},
479 .Path: Path,
480 .PathLength: PathLength};
481 }
482
483 QualType getObjectType() const {
484 QualType T = Base.getType();
485 if (T->isPointerOrReferenceType())
486 return T->getPointeeType();
487 return T;
488 }
489
490 QualType getFieldType() const {
491 if (FieldType.getPointer()->isPointerOrReferenceType() && Base.isDecl())
492 return FieldType.getPointer()->getPointeeType();
493 return QualType(FieldType.getPointer(), 0);
494 }
495
496 bool isArrayElement() const {
497 return PathLength != 0 &&
498 Path[PathLength - 1].Kind == PointerPathEntry::Array;
499 }
500
501 std::optional<size_t> computeLayoutOffset(const ASTContext &ASTCtx) const;
502 /// If this is pointing to an array element, return the array.
503 QualType getSurroundingArray() const;
504
505 bool isOnePastEnd() const { return FieldType.getInt() & 1u; }
506 bool isOnePastEndOrElementPastEnd() const;
507 bool isConstexprUnknown() const { return FieldType.getInt() & 2u; }
508 bool isUnknownSizeArray() const;
509 bool isRoot() const;
510};
511
512enum class Storage { Int, Block, Fn, Typeid, String, Opaque };
513
514/// A pointer to a memory block, live or dead.
515///
516/// This object can be allocated into interpreter stack frames. If pointing to
517/// a live block, it is a link in the chain of pointers pointing to the block.
518///
519/// In the simplest form, a Pointer has a Block* (the pointee) and both Base
520/// and Offset are 0, which means it will point to raw data.
521///
522/// The Base field is used to access metadata about the data. For primitive
523/// arrays, the Base is followed by an InitMap. In a variety of cases, the
524/// Base is preceded by an InlineDescriptor, which is used to track the
525/// initialization state, among other things.
526///
527/// The Offset field is used to access the actual data. In other words, the
528/// data the pointer decribes can be found at
529/// Pointee->data() + Pointer.Offset.
530///
531/// \verbatim
532/// Pointee Offset
533/// │ │
534/// │ │
535/// ▼ ▼
536/// ┌───────┬────────────┬─────────┬────────────────────────────┐
537/// │ Block │ InlineDesc │ InitMap │ Actual Data │
538/// └───────┴────────────┴─────────┴────────────────────────────┘
539/// ▲
540/// │
541/// │
542/// Base
543/// \endverbatim
544class Pointer {
545public:
546 Pointer() : StorageKind(Storage::Int), Int{.TypeAndIsNull: {nullptr, true}, .Value: 0} {}
547 Pointer(IntPointer &&IntPtr)
548 : StorageKind(Storage::Int), Int(std::move(IntPtr)) {}
549 Pointer(Block *B);
550 Pointer(Block *B, uint64_t BaseAndOffset);
551 Pointer(const Pointer &P);
552 Pointer(Pointer &&P);
553 Pointer(uint64_t Address, const Type *Ty, uint64_t Offset = 0,
554 std::optional<bool> IsNull = std::nullopt)
555 : Offset(Offset), StorageKind(Storage::Int),
556 Int{.TypeAndIsNull: {Ty, IsNull.value_or(u: Address == 0)}, .Value: Address} {}
557 Pointer(const Function *F, uint64_t Offset = 0)
558 : Offset(Offset), StorageKind(Storage::Fn), Fn{.Func: F} {}
559 Pointer(const Type *TypePtr, const Type *TypeInfoType, uint64_t Offset = 0)
560 : Offset(Offset), StorageKind(Storage::Typeid) {
561 Typeid.TypePtr = TypePtr;
562 Typeid.TypeInfoType = TypeInfoType;
563 }
564 Pointer(const Expr *Base, unsigned Id)
565 : Offset(0), StorageKind(Storage::String), Str{.Base: Base, .ID: Id} {}
566 Pointer(StringPointer Str, uint64_t Offset = 0)
567 : Offset(Offset), StorageKind(Storage::String), Str(Str) {}
568
569 Pointer(DeclOrExpr DOE, bool ConstexprUnknown = false)
570 : Offset(0), StorageKind(Storage::Opaque) {
571 Opaque.Base = DOE;
572 Opaque.FieldType = {DOE.getType().getTypePtr(), ConstexprUnknown ? 2u : 0u};
573 Opaque.Path = nullptr;
574 Opaque.PathLength = 0;
575 }
576 Pointer(OpaquePointer OP, uint64_t Offset = 0)
577 : Offset(Offset), StorageKind(Storage::Opaque), Opaque(OP) {}
578
579 Pointer(Block *Pointee, unsigned Base, uint64_t Offset);
580 explicit Pointer(PtrView V) : Pointer(V.Pointee, V.Base, V.Offset) {}
581 ~Pointer();
582
583 Pointer &operator=(const Pointer &P);
584 Pointer &operator=(Pointer &&P);
585
586 bool operator==(const Pointer &P) const;
587 bool operator!=(const Pointer &P) const { return !(P == *this); }
588
589 /// Converts the pointer to an APValue.
590 APValue toAPValue(const ASTContext &ASTCtx) const;
591
592 /// Converts the pointer to a string usable in diagnostics.
593 std::string toDiagnosticString(const ASTContext &Ctx) const;
594
595 uint64_t getIntegerRepresentation() const {
596 if (isIntegralPointer())
597 return Int.Value + (Offset * elemSize());
598 if (isFunctionPointer())
599 return reinterpret_cast<uint64_t>(Fn.Func) + Offset;
600 return reinterpret_cast<uint64_t>(BS.Pointee) + Offset;
601 }
602
603 PtrView view() const {
604 assert(isBlockPointer());
605 return PtrView{.Pointee: BS.Pointee, .Base: BS.Base, .Offset: Offset};
606 }
607
608 /// Converts the pointer to an APValue that is an rvalue.
609 std::optional<APValue> toRValue(const Context &Ctx,
610 QualType ResultType) const;
611
612 /// Offsets a pointer inside an array.
613 [[nodiscard]] Pointer atIndex(uint64_t Idx) const {
614 switch (StorageKind) {
615 case Storage::Int:
616 return Pointer(Int.Value, Int.getType(), Idx);
617 case Storage::Block:
618 return Pointer(view().atIndex(Idx));
619 case Storage::Fn:
620 return Pointer(Fn.Func, Idx);
621 case Storage::String:
622 return Pointer(Str, Idx);
623 default:
624 llvm_unreachable("Unexpected pointer type in atIndex()");
625 }
626 }
627
628 /// Creates a pointer to a field.
629 [[nodiscard]] Pointer atField(unsigned Off) const {
630 return Pointer(view().atField(Offset: Off));
631 }
632
633 /// Subtract the given offset from the current Base and Offset
634 /// of the pointer.
635 [[nodiscard]] Pointer atFieldSub(unsigned Off) const {
636 assert(Offset >= Off);
637 unsigned O = Offset - Off;
638 return Pointer(BS.Pointee, O, O);
639 }
640
641 /// Restricts the scope of an array element pointer.
642 [[nodiscard]] Pointer narrow() const {
643 if (!isBlockPointer())
644 return *this;
645 return Pointer(view().narrow());
646 }
647
648 /// Expands a pointer to the containing array, undoing narrowing.
649 [[nodiscard]] Pointer expand() const {
650 if (!isBlockPointer())
651 return *this;
652 return Pointer(view().expand());
653 }
654
655 /// Checks if the pointer is null.
656 bool isZero() const {
657 switch (StorageKind) {
658 case Storage::Int:
659 return Int.isNull();
660 case Storage::Block:
661 return BS.Pointee == nullptr;
662 case Storage::Fn:
663 return !Fn.Func;
664 case Storage::Typeid:
665 case Storage::String:
666 case Storage::Opaque:
667 return false;
668 }
669 llvm_unreachable("Unknown clang::interp::Storage enum");
670 }
671 /// Checks if the pointer is live.
672 bool isLive() const {
673 if (!isBlockPointer())
674 return true;
675 return view().isLive();
676 }
677 /// Checks if the item is a field in an object.
678 bool isField() const {
679 if (!isBlockPointer())
680 return false;
681
682 return view().isField();
683 }
684
685 /// Accessor for information about the declaration site.
686 const Descriptor *getDeclDesc() const {
687 if (!isBlockPointer())
688 return nullptr;
689
690 assert(isBlockPointer());
691 assert(BS.Pointee);
692 return BS.Pointee->Desc;
693 }
694 SourceLocation getDeclLoc() const { return getDeclDesc()->getLocation(); }
695
696 /// Returns the expression or declaration the pointer has been created for.
697 DeclOrExpr getSource() const {
698 if (isBlockPointer())
699 return getDeclDesc()->getSource();
700 if (isFunctionPointer()) {
701 const Function *F = Fn.Func;
702 return F ? F->getDecl() : DeclOrExpr();
703 }
704 llvm_unreachable("Unsupported pointer type in getSource()");
705 return DeclOrExpr();
706 }
707
708 /// Returns a pointer to the object of which this pointer is a field.
709 [[nodiscard]] Pointer getBase() const { return Pointer(view().getBase()); }
710 /// Returns the parent array.
711 [[nodiscard]] Pointer getArray() const { return Pointer(view().getArray()); }
712
713 /// Accessors for information about the innermost field.
714 const Descriptor *getFieldDesc() const {
715 if (!isBlockPointer())
716 return nullptr;
717
718 if (isRoot())
719 return getDeclDesc();
720 return getInlineDesc()->Desc;
721 }
722
723 /// Returns the type of the innermost field.
724 QualType getType() const {
725 switch (StorageKind) {
726 case Storage::Int:
727 return Int.getPointeeType();
728 case Storage::Block:
729 return view().getType();
730 case Storage::Fn:
731 return Fn.Func->getType();
732 case Storage::Typeid:
733 return QualType(Typeid.TypeInfoType, 0);
734 case Storage::String:
735 if (Str.Decayed)
736 return Str.getLiteral()
737 ->getType()
738 ->getAsArrayTypeUnsafe()
739 ->getElementType();
740 return Str.getLiteral()->getType();
741 case Storage::Opaque:
742 return Opaque.getFieldType();
743 }
744 llvm_unreachable("Unhandled StorageKind");
745 }
746
747 const VarDecl *getRootVarDecl() const;
748 const ValueDecl *getRootValueDecl() const;
749 const Expr *getRootExpr() const;
750
751 [[nodiscard]] Pointer getDeclPtr() const { return Pointer(BS.Pointee); }
752
753 /// Returns the element size of the innermost field.
754 size_t elemSize() const {
755 if (isIntegralPointer()) {
756 // FIXME: Remove this and handle int ptrs specially?
757 return 1;
758 }
759 if (isStringPointer())
760 return Str.getLiteral()->getCharByteWidth();
761
762 return view().elemSize();
763 }
764 /// Returns the total size of the innermost field.
765 size_t getSize() const {
766 assert(isBlockPointer());
767 return getFieldDesc()->getSize();
768 }
769
770 /// Returns the offset into an array.
771 unsigned getOffset() const {
772 assert(Offset != PtrView::PastEndMark && "invalid offset");
773 return view().getOffset();
774 }
775
776 /// Whether this array refers to an array, but not
777 /// to the first element.
778 bool isArrayRoot() const {
779 switch (StorageKind) {
780 case Storage::Block:
781 return view().isArrayRoot();
782 case Storage::String:
783 return Offset == 0;
784 case Storage::Opaque:
785 return asOpaquePointer().getFieldType()->isArrayType();
786 default:
787 return false;
788 }
789 llvm_unreachable("Unhandled storage kind");
790 }
791
792 /// Checks if the innermost field is an array.
793 bool inArray() const {
794 switch (StorageKind) {
795 case Storage::Block:
796 return view().inArray();
797 case Storage::String:
798 return true;
799 case Storage::Opaque:
800 return asOpaquePointer().isArrayElement();
801 default:
802 return false;
803 }
804
805 llvm_unreachable("Unhandled storage kind");
806 }
807 bool inUnion() const {
808 if (isBlockPointer() && BS.Base != 0)
809 return view().inUnion();
810 return false;
811 };
812
813 /// Checks if the structure is a primitive array.
814 bool inPrimitiveArray() const {
815 if (isBlockPointer())
816 return view().inPrimitiveArray();
817 return false;
818 }
819 /// Checks if the structure is an array of unknown size.
820 bool isUnknownSizeArray() const {
821 if (isBlockPointer())
822 return getFieldDesc()->isUnknownSizeArray();
823 if (isOpaquePointer())
824 return Opaque.isUnknownSizeArray();
825 return false;
826 }
827 /// Checks if the pointer points to an array.
828 bool isArrayElement() const {
829 if (!isBlockPointer())
830 return false;
831
832 return view().isArrayElement();
833 }
834 /// Pointer points directly to a block.
835 bool isRoot() const {
836 if (isZero())
837 return true;
838 if (isBlockPointer())
839 return view().isRoot();
840 if (isOpaquePointer())
841 return Opaque.isRoot();
842 return true;
843 }
844
845 [[nodiscard]] const BlockPointer &asBlockPointer() const {
846 assert(isBlockPointer());
847 return BS;
848 }
849 [[nodiscard]] const IntPointer &asIntPointer() const {
850 assert(isIntegralPointer());
851 return Int;
852 }
853 [[nodiscard]] const FunctionPointer &asFunctionPointer() const {
854 assert(isFunctionPointer());
855 return Fn;
856 }
857 [[nodiscard]] const TypeidPointer &asTypeidPointer() const {
858 assert(isTypeidPointer());
859 return Typeid;
860 }
861 [[nodiscard]] const StringPointer &asStringPointer() const {
862 assert(isStringPointer());
863 return Str;
864 }
865 [[nodiscard]] const OpaquePointer &asOpaquePointer() const {
866 assert(isOpaquePointer());
867 return Opaque;
868 }
869
870 bool isBlockPointer() const { return StorageKind == Storage::Block; }
871 bool isIntegralPointer() const { return StorageKind == Storage::Int; }
872 bool isFunctionPointer() const { return StorageKind == Storage::Fn; }
873 bool isTypeidPointer() const { return StorageKind == Storage::Typeid; }
874 bool isStringPointer() const { return StorageKind == Storage::String; }
875 bool isOpaquePointer() const { return StorageKind == Storage::Opaque; }
876
877 /// Returns the record descriptor of a class.
878 const Record *getRecord() const {
879 if (!isBlockPointer())
880 return nullptr;
881 return view().getRecord();
882 }
883 /// Returns the element record type, if this is a non-primive array.
884 const Record *getElemRecord() const { return view().getElemRecord(); }
885 /// Returns the field information.
886 const FieldDecl *getField() const {
887 if (const Descriptor *FD = getFieldDesc())
888 return FD->asFieldDecl();
889 return nullptr;
890 }
891
892 /// Checks if the storage is extern.
893 bool isExtern() const {
894 if (isBlockPointer())
895 return view().isExtern();
896 return false;
897 }
898 /// Checks if the storage is static.
899 bool isStatic() const {
900 if (!isBlockPointer())
901 return true;
902 assert(BS.Pointee);
903 return BS.Pointee->isGlobal();
904 }
905 /// Checks if the storage is temporary.
906 bool isTemporary() const {
907 if (isBlockPointer()) {
908 assert(BS.Pointee);
909 return BS.Pointee->isTemporary();
910 }
911 return false;
912 }
913 /// Checks if the storage has been dynamically allocated.
914 bool isDynamic() const {
915 if (isBlockPointer()) {
916 assert(BS.Pointee);
917 return BS.Pointee->isDynamic();
918 }
919 return false;
920 }
921 /// Checks if the storage is a static temporary.
922 bool isStaticTemporary() const { return isStatic() && isTemporary(); }
923
924 /// Checks if the field is mutable.
925 bool isMutable() const {
926 if (!isBlockPointer())
927 return false;
928 return view().isMutable();
929 }
930
931 bool isWeak() const {
932 switch (StorageKind) {
933 case Storage::Fn:
934 if (!Fn.Func || !Fn.Func->getDecl())
935 return false;
936 return Fn.Func->getDecl()->isWeak();
937 case Storage::Opaque:
938 if (const VarDecl *BaseDecl = Opaque.getBaseVarDecl())
939 return BaseDecl->isWeak();
940 return false;
941 case Storage::Block:
942 return BS.Pointee->isWeak();
943 default:
944 return false;
945 }
946 llvm_unreachable("Unhandled storage kind");
947 }
948 /// Checks if the object is active.
949 bool isActive() const {
950 if (!isBlockPointer())
951 return true;
952 return view().isActive();
953 }
954 /// Checks if a structure is a base class.
955 bool isBaseClass() const { return view().isBaseClass(); }
956 bool isVirtualBaseClass() const { return view().isVirtualBaseClass(); }
957
958 /// Checks if the pointer points to a dummy value.
959 bool isDummy() const { return isOpaquePointer(); }
960
961 /// Checks if an object or a subfield is mutable.
962 bool isConst() const {
963 if (isIntegralPointer())
964 return true;
965 if (isStringPointer())
966 return true;
967 if (!isBlockPointer())
968 return false;
969 return view().isConst();
970 }
971
972 /// Checks if an object or a subfield is volatile.
973 bool isVolatile() const {
974 if (!isBlockPointer())
975 return false;
976 return view().isVolatile();
977 }
978
979 /// Returns the declaration ID.
980 UnsignedOrNone getDeclID() const {
981 if (isBlockPointer()) {
982 assert(BS.Pointee);
983 return BS.Pointee->getDeclID();
984 }
985 return std::nullopt;
986 }
987
988 /// Returns the byte offset from the start.
989 uint64_t getByteOffset() const {
990 if (isBlockPointer())
991 return isOnePastEnd() ? PtrView::PastEndMark : Offset;
992 return Offset;
993 }
994
995 /// Returns the number of elements.
996 unsigned getNumElems() const {
997 if (isStringPointer())
998 return Str.getLiteral()->getLength() + 1;
999 if (isOpaquePointer()) {
1000 const ArrayType *AT =
1001 Opaque.getSurroundingArray()->getAsArrayTypeUnsafe();
1002 if (const auto *CAT = dyn_cast_if_present<ConstantArrayType>(Val: AT))
1003 return CAT->getZExtSize();
1004 }
1005 if (!isBlockPointer())
1006 return ~0u;
1007 return view().getNumElems();
1008 }
1009
1010 const Block *block() const {
1011 assert(isBlockPointer());
1012 return BS.Pointee;
1013 }
1014
1015 /// If backed by actual data (i.e. a block or string pointer), return
1016 /// an address to that data.
1017 const std::byte *getRawAddress() const {
1018 if (isStringPointer()) {
1019 const StringLiteral *Lit = Str.getLiteral();
1020 return reinterpret_cast<const std::byte *>(
1021 Lit->getBytes().data() + (Offset * Lit->getCharByteWidth()));
1022 }
1023 assert(isBlockPointer());
1024 return BS.Pointee->data() + Offset;
1025 }
1026
1027 /// Returns the index into an array.
1028 int64_t getIndex() const {
1029 if (isStringPointer())
1030 return Offset;
1031 if (isOpaquePointer()) {
1032 if (Opaque.isArrayElement())
1033 return Opaque.Path[Opaque.PathLength - 1].Index;
1034 return 0;
1035 }
1036 if (!isBlockPointer())
1037 return getIntegerRepresentation();
1038
1039 return view().getIndex();
1040 }
1041
1042 /// Checks if the index is one past end.
1043 bool isOnePastEnd() const {
1044 if (isStringPointer())
1045 return Offset == (Str.getLiteral()->getLength() + 1);
1046 if (isOpaquePointer())
1047 return Opaque.isOnePastEndOrElementPastEnd();
1048
1049 if (!isBlockPointer())
1050 return false;
1051
1052 if (!BS.Pointee)
1053 return false;
1054
1055 return view().isOnePastEnd();
1056 }
1057
1058 /// Checks if the pointer points past the end of the object.
1059 bool isPastEnd() const {
1060 if (isIntegralPointer())
1061 return false;
1062 if (isStringPointer())
1063 return Offset >= (Str.getLiteral()->getLength() + 1);
1064
1065 return !isZero() && Offset > BS.Pointee->getSize();
1066 }
1067
1068 /// Checks if the pointer is an out-of-bounds element pointer.
1069 bool isElementPastEnd() const { return Offset == PtrView::PastEndMark; }
1070
1071 /// Checks if the pointer is pointing to a zero-size array.
1072 bool isZeroSizeArray() const {
1073 if (isFunctionPointer())
1074 return false;
1075 if (isOpaquePointer())
1076 return false; // FIXME: Can actually happen I think?
1077 if (const auto *Desc = getFieldDesc())
1078 return Desc->isZeroSizeArray();
1079 return false;
1080 }
1081
1082 /// Checks whether the pointer can be dereferenced to the given PrimType.
1083 bool canDeref(PrimType T) const {
1084 if (isStringPointer()) {
1085 switch (Str.getLiteral()->getCharByteWidth()) {
1086 case 1:
1087 return T == PT_Sint8 || T == PT_Uint8;
1088 case 2:
1089 return T == PT_Sint16 || T == PT_Uint16;
1090 case 4:
1091 return T == PT_Sint32 || T == PT_Uint32;
1092 }
1093
1094 return false;
1095 }
1096
1097 assert(isBlockPointer());
1098 if (const Descriptor *FieldDesc = getFieldDesc()) {
1099 return (FieldDesc->isPrimitive() || FieldDesc->isPrimitiveArray()) &&
1100 FieldDesc->getPrimType() == T;
1101 }
1102 return false;
1103 }
1104
1105 /// Dereferences the pointer, if it's live.
1106 template <typename T> T &deref() const {
1107 assert(isLive() && "Invalid pointer");
1108 assert(isBlockPointer());
1109 assert(BS.Pointee);
1110 assert(isDereferencable());
1111 assert(Offset + sizeof(T) <= BS.Pointee->getSize());
1112 return view().deref<T>();
1113 }
1114
1115 template <typename T> T load() const {
1116 assert(isLive() && "Invalid pointer");
1117 if (isBlockPointer()) {
1118 assert(BS.Pointee);
1119 assert(isDereferencable());
1120 assert(Offset + sizeof(T) <= BS.Pointee->getSize());
1121 return view().deref<T>();
1122 }
1123
1124 if (isStringPointer()) {
1125 const StringLiteral *Lit = Str.getLiteral();
1126
1127 if constexpr (isFixedSizeIntegralType<T>()) {
1128 // The literal does not include the nul byte.
1129 if (Offset >= Lit->getLength())
1130 return T::from('\0');
1131 return T::from(Lit->getCodeUnit(I: Offset));
1132 } else if constexpr (std::is_integral_v<T>) {
1133 if (Offset >= Lit->getLength())
1134 return '\0';
1135 return Lit->getCodeUnit(I: Offset);
1136 }
1137 }
1138
1139 llvm_unreachable("Unexpected pointer type in load()");
1140 }
1141
1142 /// Dereferences the element at index \p I.
1143 /// This is equivalent to atIndex(I).deref<T>().
1144 template <typename T> T &elem(unsigned I) const {
1145 assert(isLive() && "Invalid pointer");
1146 assert(isBlockPointer());
1147 assert(BS.Pointee);
1148 assert(isDereferencable());
1149 assert(getFieldDesc()->isPrimitiveArray());
1150 assert(I < getFieldDesc()->getNumElems());
1151
1152 return view().elem<T>(I);
1153 }
1154
1155 template <typename T> T loadElem(unsigned I) const {
1156 assert(isLive() && "Invalid pointer");
1157 if (isBlockPointer()) {
1158 assert(BS.Pointee);
1159 assert(isDereferencable());
1160 assert(getFieldDesc()->isPrimitiveArray());
1161 assert(I < getFieldDesc()->getNumElems());
1162
1163 return view().elem<T>(I);
1164 }
1165
1166 assert(isStringPointer());
1167 const StringLiteral *Lit = Str.getLiteral();
1168 unsigned Index = Offset + I;
1169 if constexpr (isFixedSizeIntegralType<T>()) {
1170 // The literal does not include the nul byte.
1171 if (Index >= Lit->getLength())
1172 return T::from('\0');
1173 return T::from(Lit->getCodeUnit(I: Index));
1174 } else if constexpr (std::is_integral_v<T>) {
1175 if (Index >= Lit->getLength())
1176 return '\0';
1177 return Lit->getCodeUnit(I: Index);
1178 }
1179 llvm_unreachable("Unexpected pointer type in loadElem()");
1180 }
1181
1182 bool isConstexprUnknown() const {
1183 if (isOpaquePointer())
1184 return Opaque.isConstexprUnknown();
1185 if (isBlockPointer())
1186 return block()->isConstexprUnknown();
1187 return false;
1188 }
1189
1190 /// Whether this block can be read from at all. This is only true for
1191 /// block pointers that point to a valid location inside that block.
1192 bool isDereferencable() const {
1193 if (!isBlockPointer())
1194 return false;
1195 if (isDummy())
1196 return false;
1197 if (isConstexprUnknown())
1198 return false;
1199 if (isPastEnd())
1200 return false;
1201
1202 return true;
1203 }
1204
1205 bool isReadablePointerType() const {
1206 return StorageKind == Storage::Block || StorageKind == Storage::String;
1207 }
1208
1209 /// Initializes a field.
1210 void initialize() const {
1211 if (!isBlockPointer())
1212 return;
1213 view().initialize();
1214 }
1215 /// Initialized the given element of a primitive array.
1216 void initializeElement(unsigned Index) const {
1217 view().initializeElement(Index);
1218 }
1219 /// Initialize all elements of a primitive array at once. This can be
1220 /// used in situations where we *know* we have initialized *all* elements
1221 /// of a primtive array.
1222 void initializeAllElements() const;
1223 /// Checks if an object was initialized.
1224 bool isInitialized() const {
1225 if (!isBlockPointer())
1226 return true;
1227
1228 return view().isInitialized();
1229 }
1230
1231 /// Like isInitialized(), but for primitive arrays.
1232 bool isElementInitialized(unsigned Index) const {
1233 if (!isBlockPointer())
1234 return true;
1235
1236 return view().isElementInitialized(Index);
1237 }
1238 bool allElementsInitialized() const {
1239 assert(getFieldDesc()->isPrimitiveArray());
1240 assert(isArrayRoot());
1241 return view().allElementsInitialized();
1242 }
1243 bool allElementsAlive() const;
1244 bool isElementAlive(unsigned Index) const;
1245
1246 /// Activates a field.
1247 void activate() const {
1248 if (!isBlockPointer())
1249 return;
1250 view().activate();
1251 }
1252 /// Deactivates an entire strurcutre.
1253 void deactivate() const {
1254 // TODO: this only appears in constructors, so nothing to deactivate.
1255 }
1256
1257 Lifetime getLifetime() const {
1258 if (!isBlockPointer())
1259 return Lifetime::Started;
1260 return view().getLifetime();
1261 }
1262
1263 /// Start the lifetime of this pointer. This works for pointer with an
1264 /// InlineDescriptor as well as primitive array elements. Pointers are usually
1265 /// alive by default, unless the underlying object has been allocated with
1266 /// std::allocator. This function is used by std::construct_at.
1267 void startLifetime() const { setLifeState(Lifetime::Started); }
1268 /// Ends the lifetime of the pointer. This works for pointer with an
1269 /// InlineDescriptor as well as primitive array elements. This function is
1270 /// used by std::destroy_at.
1271 void endLifetime() const { setLifeState(Lifetime::Ended); }
1272
1273 void setLifeState(Lifetime L) const {
1274 if (!isBlockPointer())
1275 return;
1276 view().setLifeState(L);
1277 };
1278
1279 /// Strip base casts from this Pointer.
1280 /// The result is either a root pointer or something
1281 /// that isn't a base class anymore.
1282 [[nodiscard]] Pointer stripBaseCasts() const {
1283 return Pointer(view().stripBaseCasts());
1284 }
1285 /// Checks if two pointers are comparable.
1286 static bool hasSameBase(const Pointer &A, const Pointer &B);
1287 /// Checks if two pointers can be subtracted.
1288 static bool elemsOfSameArray(const Pointer &A, const Pointer &B);
1289 /// Checks if both given pointers point to the same block.
1290 static bool pointToSameBlock(const Pointer &A, const Pointer &B);
1291
1292 static std::optional<std::pair<PtrView, PtrView>>
1293 computeSplitPoint(const Pointer &A, const Pointer &B);
1294
1295 /// Whether this points to a block that's been created for a "literal lvalue",
1296 /// i.e. a non-MaterializeTemporaryExpr Expr.
1297 bool pointsToLiteral() const;
1298 /// Whether this points to a block created for an AddrLabelExpr.
1299 bool pointsToLabel() const;
1300 /// Returns the AddrLabelExpr the Pointer points to, if any.
1301 const AddrLabelExpr *getPointedToLabel() const {
1302 return dyn_cast_if_present<AddrLabelExpr>(Val: getRootExpr());
1303 }
1304
1305 /// Prints the pointer.
1306 void print(llvm::raw_ostream &OS) const;
1307
1308 /// Compute an integer that can be used to compare this pointer to
1309 /// another one. This is usually NOT the same as the pointer offset
1310 /// regarding the AST record layout.
1311 std::optional<size_t>
1312 computeOffsetForComparison(const ASTContext &ASTCtx) const;
1313 /// Compute the pointer offset as given by the ASTRecordLayout.
1314 /// Returns the result in bytes.
1315 std::optional<size_t> computeLayoutOffset(const ASTContext &ASTCtx) const;
1316
1317private:
1318 friend class Block;
1319 friend class DeadBlock;
1320 friend class MemberPointer;
1321 friend class InterpState;
1322 friend class DynamicAllocator;
1323 friend class Program;
1324
1325 /// Returns the embedded descriptor preceding a field.
1326 InlineDescriptor *getInlineDesc() const {
1327 assert(isBlockPointer());
1328 assert(BS.Base <= BS.Pointee->getSize());
1329 assert(BS.Base != 0);
1330 return getDescriptor(Offset: BS.Base);
1331 }
1332
1333 /// Returns a descriptor at a given offset.
1334 InlineDescriptor *getDescriptor(unsigned Offset) const {
1335 assert(Offset != 0 && "Not a nested pointer");
1336 assert(isBlockPointer());
1337 assert(!isZero());
1338 return view().getDescriptor(Offset);
1339 }
1340
1341 /// Returns a reference to the InitMapPtr which stores the initialization map.
1342 InitMapPtr &getInitMap() const {
1343 assert(isBlockPointer());
1344 assert(!isZero());
1345 return view().getInitMap();
1346 }
1347
1348 /// Offset into the storage.
1349 uint64_t Offset = 0;
1350
1351 Storage StorageKind = Storage::Int;
1352 union {
1353 IntPointer Int;
1354 BlockPointer BS;
1355 FunctionPointer Fn;
1356 TypeidPointer Typeid;
1357 StringPointer Str;
1358 OpaquePointer Opaque;
1359 };
1360};
1361
1362inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Pointer &P) {
1363 P.print(OS);
1364 OS << ' ';
1365 if (P.isZero())
1366 return OS;
1367
1368 if (const Descriptor *D = P.getFieldDesc())
1369 D->dump(OS);
1370 if (P.isArrayElement()) {
1371 if (P.isOnePastEnd())
1372 OS << " one-past-the-end";
1373 else {
1374 OS << ' ';
1375 std::string Indices;
1376 llvm::raw_string_ostream SS(Indices);
1377 Pointer K = P;
1378 while (K.isArrayElement()) {
1379 SS << ']' << K.expand().getIndex() << '[';
1380 K = K.expand().getArray();
1381 }
1382 std::reverse(first: Indices.begin(), last: Indices.end());
1383 OS << Indices;
1384 }
1385 } else if (P.isBlockPointer() && P.isArrayRoot())
1386 OS << " arrayroot";
1387
1388 if (P.isDummy())
1389 OS << " dummy";
1390 if (!P.isLive())
1391 OS << " dead";
1392 if (P.isBlockPointer() && P.isBaseClass())
1393 OS << " base-class";
1394 if (!P.isInitialized()) {
1395 ColorScope SC(OS, true, {.Color: llvm::raw_ostream::BRIGHT_RED, .Bold: true});
1396 OS << " uninitialized";
1397 }
1398 return OS;
1399}
1400
1401} // namespace interp
1402} // namespace clang
1403
1404#endif
1405