clang 20.0.0git
Descriptor.cpp
Go to the documentation of this file.
1//===--- Descriptor.cpp - 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#include "Descriptor.h"
10#include "Boolean.h"
11#include "Floating.h"
12#include "FunctionPointer.h"
13#include "IntegralAP.h"
14#include "MemberPointer.h"
15#include "Pointer.h"
16#include "PrimType.h"
17#include "Record.h"
18
19using namespace clang;
20using namespace clang::interp;
21
22template <typename T>
23static void ctorTy(Block *, std::byte *Ptr, bool, bool, bool, bool,
24 const Descriptor *) {
25 new (Ptr) T();
26}
27
28template <typename T>
29static void dtorTy(Block *, std::byte *Ptr, const Descriptor *) {
30 reinterpret_cast<T *>(Ptr)->~T();
31}
32
33template <typename T>
34static void moveTy(Block *, std::byte *Src, std::byte *Dst,
35 const Descriptor *) {
36 auto *SrcPtr = reinterpret_cast<T *>(Src);
37 auto *DstPtr = reinterpret_cast<T *>(Dst);
38 new (DstPtr) T(std::move(*SrcPtr));
39}
40
41template <typename T>
42static void ctorArrayTy(Block *, std::byte *Ptr, bool, bool, bool, bool,
43 const Descriptor *D) {
44 new (Ptr) InitMapPtr(std::nullopt);
45
46 Ptr += sizeof(InitMapPtr);
47 for (unsigned I = 0, NE = D->getNumElems(); I < NE; ++I) {
48 new (&reinterpret_cast<T *>(Ptr)[I]) T();
49 }
50}
51
52template <typename T>
53static void dtorArrayTy(Block *, std::byte *Ptr, const Descriptor *D) {
54 InitMapPtr &IMP = *reinterpret_cast<InitMapPtr *>(Ptr);
55
56 if (IMP)
57 IMP = std::nullopt;
58 Ptr += sizeof(InitMapPtr);
59 for (unsigned I = 0, NE = D->getNumElems(); I < NE; ++I) {
60 reinterpret_cast<T *>(Ptr)[I].~T();
61 }
62}
63
64template <typename T>
65static void moveArrayTy(Block *, std::byte *Src, std::byte *Dst,
66 const Descriptor *D) {
67 InitMapPtr &SrcIMP = *reinterpret_cast<InitMapPtr *>(Src);
68 if (SrcIMP) {
69 // We only ever invoke the moveFunc when moving block contents to a
70 // DeadBlock. DeadBlocks don't need InitMaps, so we destroy them here.
71 SrcIMP = std::nullopt;
72 }
73 Src += sizeof(InitMapPtr);
74 Dst += sizeof(InitMapPtr);
75 for (unsigned I = 0, NE = D->getNumElems(); I < NE; ++I) {
76 auto *SrcPtr = &reinterpret_cast<T *>(Src)[I];
77 auto *DstPtr = &reinterpret_cast<T *>(Dst)[I];
78 new (DstPtr) T(std::move(*SrcPtr));
79 }
80}
81
82static void ctorArrayDesc(Block *B, std::byte *Ptr, bool IsConst,
83 bool IsMutable, bool IsActive, bool InUnion,
84 const Descriptor *D) {
85 const unsigned NumElems = D->getNumElems();
86 const unsigned ElemSize =
87 D->ElemDesc->getAllocSize() + sizeof(InlineDescriptor);
88
89 unsigned ElemOffset = 0;
90 for (unsigned I = 0; I < NumElems; ++I, ElemOffset += ElemSize) {
91 auto *ElemPtr = Ptr + ElemOffset;
92 auto *Desc = reinterpret_cast<InlineDescriptor *>(ElemPtr);
93 auto *ElemLoc = reinterpret_cast<std::byte *>(Desc + 1);
94 auto *SD = D->ElemDesc;
95
96 Desc->Offset = ElemOffset + sizeof(InlineDescriptor);
97 Desc->Desc = SD;
98 Desc->IsInitialized = true;
99 Desc->IsBase = false;
100 Desc->IsActive = IsActive;
101 Desc->IsConst = IsConst || D->IsConst;
102 Desc->IsFieldMutable = IsMutable || D->IsMutable;
103 Desc->InUnion = InUnion;
104
105 if (auto Fn = D->ElemDesc->CtorFn)
106 Fn(B, ElemLoc, Desc->IsConst, Desc->IsFieldMutable, IsActive,
107 Desc->InUnion || SD->isUnion(), D->ElemDesc);
108 }
109}
110
111static void dtorArrayDesc(Block *B, std::byte *Ptr, const Descriptor *D) {
112 const unsigned NumElems = D->getNumElems();
113 const unsigned ElemSize =
114 D->ElemDesc->getAllocSize() + sizeof(InlineDescriptor);
115
116 unsigned ElemOffset = 0;
117 for (unsigned I = 0; I < NumElems; ++I, ElemOffset += ElemSize) {
118 auto *ElemPtr = Ptr + ElemOffset;
119 auto *Desc = reinterpret_cast<InlineDescriptor *>(ElemPtr);
120 auto *ElemLoc = reinterpret_cast<std::byte *>(Desc + 1);
121 if (auto Fn = D->ElemDesc->DtorFn)
122 Fn(B, ElemLoc, D->ElemDesc);
123 }
124}
125
126static void moveArrayDesc(Block *B, std::byte *Src, std::byte *Dst,
127 const Descriptor *D) {
128 const unsigned NumElems = D->getNumElems();
129 const unsigned ElemSize =
130 D->ElemDesc->getAllocSize() + sizeof(InlineDescriptor);
131
132 unsigned ElemOffset = 0;
133 for (unsigned I = 0; I < NumElems; ++I, ElemOffset += ElemSize) {
134 auto *SrcPtr = Src + ElemOffset;
135 auto *DstPtr = Dst + ElemOffset;
136
137 auto *SrcDesc = reinterpret_cast<InlineDescriptor *>(SrcPtr);
138 auto *SrcElemLoc = reinterpret_cast<std::byte *>(SrcDesc + 1);
139 auto *DstDesc = reinterpret_cast<InlineDescriptor *>(DstPtr);
140 auto *DstElemLoc = reinterpret_cast<std::byte *>(DstDesc + 1);
141
142 *DstDesc = *SrcDesc;
143 if (auto Fn = D->ElemDesc->MoveFn)
144 Fn(B, SrcElemLoc, DstElemLoc, D->ElemDesc);
145 }
146}
147
148static void initField(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable,
149 bool IsActive, bool IsUnionField, bool InUnion,
150 const Descriptor *D, unsigned FieldOffset) {
151 auto *Desc = reinterpret_cast<InlineDescriptor *>(Ptr + FieldOffset) - 1;
152 Desc->Offset = FieldOffset;
153 Desc->Desc = D;
154 Desc->IsInitialized = D->IsArray;
155 Desc->IsBase = false;
156 Desc->IsActive = IsActive && !IsUnionField;
157 Desc->InUnion = InUnion;
158 Desc->IsConst = IsConst || D->IsConst;
159 Desc->IsFieldMutable = IsMutable || D->IsMutable;
160
161 if (auto Fn = D->CtorFn)
162 Fn(B, Ptr + FieldOffset, Desc->IsConst, Desc->IsFieldMutable,
163 Desc->IsActive, InUnion || D->isUnion(), D);
164}
165
166static void initBase(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable,
167 bool IsActive, bool InUnion, const Descriptor *D,
168 unsigned FieldOffset, bool IsVirtualBase) {
169 assert(D);
170 assert(D->ElemRecord);
171 assert(!D->ElemRecord->isUnion()); // Unions cannot be base classes.
172
173 auto *Desc = reinterpret_cast<InlineDescriptor *>(Ptr + FieldOffset) - 1;
174 Desc->Offset = FieldOffset;
175 Desc->Desc = D;
176 Desc->IsInitialized = D->IsArray;
177 Desc->IsBase = true;
178 Desc->IsVirtualBase = IsVirtualBase;
179 Desc->IsActive = IsActive && !InUnion;
180 Desc->IsConst = IsConst || D->IsConst;
181 Desc->IsFieldMutable = IsMutable || D->IsMutable;
182 Desc->InUnion = InUnion;
183
184 for (const auto &V : D->ElemRecord->bases())
185 initBase(B, Ptr + FieldOffset, IsConst, IsMutable, IsActive, InUnion,
186 V.Desc, V.Offset, false);
187 for (const auto &F : D->ElemRecord->fields())
188 initField(B, Ptr + FieldOffset, IsConst, IsMutable, IsActive, InUnion,
189 InUnion, F.Desc, F.Offset);
190}
191
192static void ctorRecord(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable,
193 bool IsActive, bool InUnion, const Descriptor *D) {
194 for (const auto &V : D->ElemRecord->bases())
195 initBase(B, Ptr, IsConst, IsMutable, IsActive, InUnion, V.Desc, V.Offset,
196 false);
197 for (const auto &F : D->ElemRecord->fields()) {
198 bool IsUnionField = D->isUnion();
199 initField(B, Ptr, IsConst, IsMutable, IsActive, IsUnionField,
200 InUnion || IsUnionField, F.Desc, F.Offset);
201 }
202 for (const auto &V : D->ElemRecord->virtual_bases())
203 initBase(B, Ptr, IsConst, IsMutable, IsActive, InUnion, V.Desc, V.Offset,
204 true);
205}
206
207static void destroyField(Block *B, std::byte *Ptr, const Descriptor *D,
208 unsigned FieldOffset) {
209 if (auto Fn = D->DtorFn)
210 Fn(B, Ptr + FieldOffset, D);
211}
212
213static void destroyBase(Block *B, std::byte *Ptr, const Descriptor *D,
214 unsigned FieldOffset) {
215 assert(D);
216 assert(D->ElemRecord);
217
218 for (const auto &V : D->ElemRecord->bases())
219 destroyBase(B, Ptr + FieldOffset, V.Desc, V.Offset);
220 for (const auto &F : D->ElemRecord->fields())
221 destroyField(B, Ptr + FieldOffset, F.Desc, F.Offset);
222}
223
224static void dtorRecord(Block *B, std::byte *Ptr, const Descriptor *D) {
225 for (const auto &F : D->ElemRecord->bases())
226 destroyBase(B, Ptr, F.Desc, F.Offset);
227 for (const auto &F : D->ElemRecord->fields())
228 destroyField(B, Ptr, F.Desc, F.Offset);
229 for (const auto &F : D->ElemRecord->virtual_bases())
230 destroyBase(B, Ptr, F.Desc, F.Offset);
231}
232
233static void moveRecord(Block *B, std::byte *Src, std::byte *Dst,
234 const Descriptor *D) {
235 assert(D);
236 assert(D->ElemRecord);
237
238 // FIXME: There might be cases where we need to move over the (v)bases as
239 // well.
240 for (const auto &F : D->ElemRecord->fields()) {
241 auto FieldOffset = F.Offset;
242 const auto *SrcDesc =
243 reinterpret_cast<const InlineDescriptor *>(Src + FieldOffset) - 1;
244 auto *DestDesc =
245 reinterpret_cast<InlineDescriptor *>(Dst + FieldOffset) - 1;
246 std::memcpy(DestDesc, SrcDesc, sizeof(InlineDescriptor));
247
248 if (auto Fn = F.Desc->MoveFn)
249 Fn(B, Src + FieldOffset, Dst + FieldOffset, F.Desc);
250 }
251}
252
254 // Floating types are special. They are primitives, but need their
255 // constructor called.
256 if (Type == PT_Float)
257 return ctorTy<PrimConv<PT_Float>::T>;
258 if (Type == PT_IntAP)
259 return ctorTy<PrimConv<PT_IntAP>::T>;
260 if (Type == PT_IntAPS)
261 return ctorTy<PrimConv<PT_IntAPS>::T>;
262 if (Type == PT_MemberPtr)
263 return ctorTy<PrimConv<PT_MemberPtr>::T>;
264
265 COMPOSITE_TYPE_SWITCH(Type, return ctorTy<T>, return nullptr);
266}
267
269 // Floating types are special. They are primitives, but need their
270 // destructor called, since they might allocate memory.
271 if (Type == PT_Float)
272 return dtorTy<PrimConv<PT_Float>::T>;
273 if (Type == PT_IntAP)
274 return dtorTy<PrimConv<PT_IntAP>::T>;
275 if (Type == PT_IntAPS)
276 return dtorTy<PrimConv<PT_IntAPS>::T>;
277 if (Type == PT_MemberPtr)
278 return dtorTy<PrimConv<PT_MemberPtr>::T>;
279
280 COMPOSITE_TYPE_SWITCH(Type, return dtorTy<T>, return nullptr);
281}
282
284 if (Type == PT_Float)
285 return moveTy<PrimConv<PT_Float>::T>;
286 if (Type == PT_IntAP)
287 return moveTy<PrimConv<PT_IntAP>::T>;
288 if (Type == PT_IntAPS)
289 return moveTy<PrimConv<PT_IntAPS>::T>;
290 if (Type == PT_MemberPtr)
291 return moveTy<PrimConv<PT_MemberPtr>::T>;
292 COMPOSITE_TYPE_SWITCH(Type, return moveTy<T>, return nullptr);
293}
294
296 TYPE_SWITCH(Type, return ctorArrayTy<T>);
297 llvm_unreachable("unknown Expr");
298}
299
301 TYPE_SWITCH(Type, return dtorArrayTy<T>);
302 llvm_unreachable("unknown Expr");
303}
304
306 TYPE_SWITCH(Type, return moveArrayTy<T>);
307 llvm_unreachable("unknown Expr");
308}
309
310/// Primitives.
312 bool IsConst, bool IsTemporary, bool IsMutable)
313 : Source(D), ElemSize(primSize(Type)), Size(ElemSize),
314 MDSize(MD.value_or(0)), AllocSize(align(Size + MDSize)), PrimT(Type),
315 IsConst(IsConst), IsMutable(IsMutable), IsTemporary(IsTemporary),
316 CtorFn(getCtorPrim(Type)), DtorFn(getDtorPrim(Type)),
317 MoveFn(getMovePrim(Type)) {
318 assert(AllocSize >= Size);
319 assert(Source && "Missing source");
320}
321
322/// Primitive arrays.
324 size_t NumElems, bool IsConst, bool IsTemporary,
325 bool IsMutable)
326 : Source(D), ElemSize(primSize(Type)), Size(ElemSize * NumElems),
327 MDSize(MD.value_or(0)),
328 AllocSize(align(MDSize) + align(Size) + sizeof(InitMapPtr)), PrimT(Type),
329 IsConst(IsConst), IsMutable(IsMutable), IsTemporary(IsTemporary),
330 IsArray(true), CtorFn(getCtorArrayPrim(Type)),
331 DtorFn(getDtorArrayPrim(Type)), MoveFn(getMoveArrayPrim(Type)) {
332 assert(Source && "Missing source");
333 assert(NumElems <= (MaxArrayElemBytes / ElemSize));
334}
335
336/// Primitive unknown-size arrays.
338 bool IsTemporary, UnknownSize)
339 : Source(D), ElemSize(primSize(Type)), Size(UnknownSizeMark),
340 MDSize(MD.value_or(0)),
341 AllocSize(MDSize + sizeof(InitMapPtr) + alignof(void *)), IsConst(true),
342 IsMutable(false), IsTemporary(IsTemporary), IsArray(true),
343 CtorFn(getCtorArrayPrim(Type)), DtorFn(getDtorArrayPrim(Type)),
344 MoveFn(getMoveArrayPrim(Type)) {
345 assert(Source && "Missing source");
346}
347
348/// Arrays of composite elements.
350 unsigned NumElems, bool IsConst, bool IsTemporary,
351 bool IsMutable)
352 : Source(D), ElemSize(Elem->getAllocSize() + sizeof(InlineDescriptor)),
353 Size(ElemSize * NumElems), MDSize(MD.value_or(0)),
354 AllocSize(std::max<size_t>(alignof(void *), Size) + MDSize),
355 ElemDesc(Elem), IsConst(IsConst), IsMutable(IsMutable),
356 IsTemporary(IsTemporary), IsArray(true), CtorFn(ctorArrayDesc),
357 DtorFn(dtorArrayDesc), MoveFn(moveArrayDesc) {
358 assert(Source && "Missing source");
359}
360
361/// Unknown-size arrays of composite elements.
363 bool IsTemporary, UnknownSize)
364 : Source(D), ElemSize(Elem->getAllocSize() + sizeof(InlineDescriptor)),
365 Size(UnknownSizeMark), MDSize(MD.value_or(0)),
366 AllocSize(MDSize + alignof(void *)), ElemDesc(Elem), IsConst(true),
367 IsMutable(false), IsTemporary(IsTemporary), IsArray(true),
368 CtorFn(ctorArrayDesc), DtorFn(dtorArrayDesc), MoveFn(moveArrayDesc) {
369 assert(Source && "Missing source");
370}
371
372/// Composite records.
374 bool IsConst, bool IsTemporary, bool IsMutable)
375 : Source(D), ElemSize(std::max<size_t>(alignof(void *), R->getFullSize())),
376 Size(ElemSize), MDSize(MD.value_or(0)), AllocSize(Size + MDSize),
377 ElemRecord(R), IsConst(IsConst), IsMutable(IsMutable),
378 IsTemporary(IsTemporary), CtorFn(ctorRecord), DtorFn(dtorRecord),
379 MoveFn(moveRecord) {
380 assert(Source && "Missing source");
381}
382
383/// Dummy.
385 : Source(D), ElemSize(1), Size(1), MDSize(0), AllocSize(MDSize),
386 ElemRecord(nullptr), IsConst(true), IsMutable(false), IsTemporary(false),
387 IsDummy(true) {
388 assert(Source && "Missing source");
389}
390
392 if (const auto *E = asExpr())
393 return E->getType();
394 if (const auto *D = asValueDecl())
395 return D->getType();
396 if (const auto *T = dyn_cast<TypeDecl>(asDecl()))
397 return QualType(T->getTypeForDecl(), 0);
398 llvm_unreachable("Invalid descriptor type");
399}
400
402 assert(isArray());
403 QualType T = getType();
404 if (const auto *AT = T->getAsArrayTypeUnsafe())
405 return AT->getElementType();
406 if (const auto *CT = T->getAs<ComplexType>())
407 return CT->getElementType();
408 if (const auto *CT = T->getAs<VectorType>())
409 return CT->getElementType();
410 llvm_unreachable("Array that's not an array/complex/vector type?");
411}
412
414 if (auto *D = Source.dyn_cast<const Decl *>())
415 return D->getLocation();
416 if (auto *E = Source.dyn_cast<const Expr *>())
417 return E->getExprLoc();
418 llvm_unreachable("Invalid descriptor type");
419}
420
421bool Descriptor::isUnion() const { return isRecord() && ElemRecord->isUnion(); }
422
424 : UninitFields(N), Data(std::make_unique<T[]>(numFields(N))) {
425 std::fill_n(data(), numFields(N), 0);
426}
427
428bool InitMap::initializeElement(unsigned I) {
429 unsigned Bucket = I / PER_FIELD;
430 T Mask = T(1) << (I % PER_FIELD);
431 if (!(data()[Bucket] & Mask)) {
432 data()[Bucket] |= Mask;
433 UninitFields -= 1;
434 }
435 return UninitFields == 0;
436}
437
438bool InitMap::isElementInitialized(unsigned I) const {
439 unsigned Bucket = I / PER_FIELD;
440 return data()[Bucket] & (T(1) << (I % PER_FIELD));
441}
#define V(N, I)
Definition: ASTContext.h:3341
const Decl * D
Expr * E
static void moveArrayTy(Block *, std::byte *Src, std::byte *Dst, const Descriptor *D)
Definition: Descriptor.cpp:65
static void dtorTy(Block *, std::byte *Ptr, const Descriptor *)
Definition: Descriptor.cpp:29
static BlockCtorFn getCtorArrayPrim(PrimType Type)
Definition: Descriptor.cpp:295
static void initField(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable, bool IsActive, bool IsUnionField, bool InUnion, const Descriptor *D, unsigned FieldOffset)
Definition: Descriptor.cpp:148
static void initBase(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable, bool IsActive, bool InUnion, const Descriptor *D, unsigned FieldOffset, bool IsVirtualBase)
Definition: Descriptor.cpp:166
static BlockMoveFn getMoveArrayPrim(PrimType Type)
Definition: Descriptor.cpp:305
static void destroyField(Block *B, std::byte *Ptr, const Descriptor *D, unsigned FieldOffset)
Definition: Descriptor.cpp:207
static void dtorArrayTy(Block *, std::byte *Ptr, const Descriptor *D)
Definition: Descriptor.cpp:53
static BlockMoveFn getMovePrim(PrimType Type)
Definition: Descriptor.cpp:283
static void moveRecord(Block *B, std::byte *Src, std::byte *Dst, const Descriptor *D)
Definition: Descriptor.cpp:233
static void moveTy(Block *, std::byte *Src, std::byte *Dst, const Descriptor *)
Definition: Descriptor.cpp:34
static void ctorArrayTy(Block *, std::byte *Ptr, bool, bool, bool, bool, const Descriptor *D)
Definition: Descriptor.cpp:42
static void destroyBase(Block *B, std::byte *Ptr, const Descriptor *D, unsigned FieldOffset)
Definition: Descriptor.cpp:213
static void dtorArrayDesc(Block *B, std::byte *Ptr, const Descriptor *D)
Definition: Descriptor.cpp:111
static void ctorTy(Block *, std::byte *Ptr, bool, bool, bool, bool, const Descriptor *)
Definition: Descriptor.cpp:23
static BlockDtorFn getDtorPrim(PrimType Type)
Definition: Descriptor.cpp:268
static BlockCtorFn getCtorPrim(PrimType Type)
Definition: Descriptor.cpp:253
static BlockDtorFn getDtorArrayPrim(PrimType Type)
Definition: Descriptor.cpp:300
static void moveArrayDesc(Block *B, std::byte *Src, std::byte *Dst, const Descriptor *D)
Definition: Descriptor.cpp:126
static void dtorRecord(Block *B, std::byte *Ptr, const Descriptor *D)
Definition: Descriptor.cpp:224
static void ctorArrayDesc(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable, bool IsActive, bool InUnion, const Descriptor *D)
Definition: Descriptor.cpp:82
static void ctorRecord(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable, bool IsActive, bool InUnion, const Descriptor *D)
Definition: Descriptor.cpp:192
#define COMPOSITE_TYPE_SWITCH(Expr, B, D)
Definition: PrimType.h:206
#define TYPE_SWITCH(Expr, B)
Definition: PrimType.h:148
__DEVICE__ int max(int __a, int __b)
__SIZE_TYPE__ size_t
Complex values, per C99 6.2.5p11.
Definition: Type.h:3139
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
SourceLocation getLocation() const
Definition: DeclBase.h:446
This represents one expression.
Definition: Expr.h:110
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:277
QualType getType() const
Definition: Expr.h:142
A (possibly-)qualified type.
Definition: Type.h:941
Encodes a location in the source.
The base class of the type hierarchy.
Definition: Type.h:1829
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition: Type.h:8598
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8545
Represents a GCC generic vector type.
Definition: Type.h:4026
A memory block, either on the stack or in the heap.
Definition: InterpBlock.h:49
Structure/Class descriptor.
Definition: Record.h:25
bool isUnion() const
Checks if the record is a union.
Definition: Record.h:56
std::optional< std::pair< bool, std::shared_ptr< InitMap > > > InitMapPtr
Definition: Descriptor.h:29
void(*)(Block *Storage, std::byte *FieldPtr, bool IsConst, bool IsMutable, bool IsActive, bool InUnion, const Descriptor *FieldDesc) BlockCtorFn
Invoked whenever a block is created.
Definition: Descriptor.h:36
bool NE(InterpState &S, CodePtr OpPC)
Definition: Interp.h:1090
void(*)(Block *Storage, std::byte *FieldPtr, const Descriptor *FieldDesc) BlockDtorFn
Invoked when a block is destroyed.
Definition: Descriptor.h:41
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
Definition: PrimType.h:126
PrimType
Enumeration of the primitive types of the VM.
Definition: PrimType.h:33
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
Definition: PrimType.cpp:23
void(*)(Block *Storage, std::byte *SrcFieldPtr, std::byte *DstFieldPtr, const Descriptor *FieldDesc) BlockMoveFn
Invoked when a block with pointers referencing it goes out of scope.
Definition: Descriptor.h:49
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
Definition: Descriptor.h:28
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
#define true
Definition: stdbool.h:25
#define false
Definition: stdbool.h:26
Token to denote structures of unknown size.
Definition: Descriptor.h:129
Describes a memory block created by an allocation site.
Definition: Descriptor.h:111
QualType getElemQualType() const
Definition: Descriptor.cpp:401
const ValueDecl * asValueDecl() const
Definition: Descriptor.h:202
static constexpr unsigned MaxArrayElemBytes
Maximum number of bytes to be used for array elements.
Definition: Descriptor.h:136
QualType getType() const
Definition: Descriptor.cpp:391
const Decl * asDecl() const
Definition: Descriptor.h:198
SourceLocation getLocation() const
Definition: Descriptor.cpp:413
std::optional< unsigned > MetadataSize
Definition: Descriptor.h:131
Descriptor(const DeclTy &D, PrimType Type, MetadataSize MD, bool IsConst, bool IsTemporary, bool IsMutable)
Allocates a descriptor for a primitive.
Definition: Descriptor.cpp:311
bool isRecord() const
Checks if the descriptor is of a record.
Definition: Descriptor.h:256
const Record *const ElemRecord
Pointer to the record, if block contains records.
Definition: Descriptor.h:141
bool isUnion() const
Checks if the descriptor is of a union.
Definition: Descriptor.cpp:421
const Expr * asExpr() const
Definition: Descriptor.h:199
bool isArray() const
Checks if the descriptor is of an array.
Definition: Descriptor.h:254
InitMap(unsigned N)
Initializes the map with no fields set.
Definition: Descriptor.cpp:423
Inline descriptor embedded in structures and arrays.
Definition: Descriptor.h:69
unsigned Offset
Offset inside the structure/array.
Definition: Descriptor.h:71