27template <
typename T>
static constexpr bool needsDtor() {
28 return std::is_same_v<T, Pointer> || std::is_same_v<T, MemberPointer>;
34 reinterpret_cast<T *
>(Ptr)->~
T();
45 reinterpret_cast<T *
>(Ptr)[I].~
T();
51 bool IsMutable,
bool IsVolatile,
bool IsActive,
54 const unsigned ElemSize =
57 unsigned ElemOffset = 0;
58 for (
unsigned I = 0; I != NumElems; ++I, ElemOffset += ElemSize) {
59 auto *ElemPtr = Ptr + ElemOffset;
65 Desc->IsInitialized =
true;
67 Desc->IsActive = IsActive;
68 Desc->IsConst = IsConst || D->
IsConst;
69 Desc->IsFieldMutable = IsMutable || D->
IsMutable;
70 Desc->InUnion = InUnion;
71 Desc->IsArrayElement =
true;
72 Desc->IsVolatile = IsVolatile;
75 auto *ElemLoc =
reinterpret_cast<std::byte *
>(Desc + 1);
76 Fn(B, ElemLoc, Desc->IsConst, Desc->IsFieldMutable, IsVolatile, IsActive,
77 Desc->InUnion || SD->isUnion(), D->
ElemDesc);
84 const unsigned ElemSize =
87 unsigned ElemOffset = 0;
90 "a composite array without an elem dtor shouldn't have a dtor itself");
91 for (
unsigned I = 0; I != NumElems; ++I, ElemOffset += ElemSize) {
92 auto *ElemPtr = Ptr + ElemOffset;
94 auto *ElemLoc =
reinterpret_cast<std::byte *
>(Desc + 1);
100 bool IsVolatile,
bool IsActive,
bool IsUnionField,
101 bool InUnion,
const Descriptor *D,
unsigned FieldOffset) {
103 Desc->
Offset = FieldOffset;
105 Desc->IsInitialized = D->
IsArray;
106 Desc->IsBase =
false;
107 Desc->IsActive = IsActive && !IsUnionField;
108 Desc->InUnion = InUnion;
109 Desc->IsConst = IsConst || D->
IsConst;
110 Desc->IsFieldMutable = IsMutable || D->
IsMutable;
111 Desc->IsVolatile = IsVolatile || D->
IsVolatile;
113 Desc->IsConstInMutable = Desc->IsConst && IsMutable;
120 Fn(B, Ptr + FieldOffset, Desc->IsConst, Desc->IsFieldMutable,
121 Desc->IsVolatile, Desc->IsActive, InUnion || D->
isUnion(), D);
125 bool IsVolatile,
bool IsActive,
bool InUnion,
127 bool IsVirtualBase) {
133 Desc->
Offset = FieldOffset;
135 Desc->IsInitialized = D->
IsArray;
137 Desc->IsVirtualBase = IsVirtualBase;
138 Desc->IsActive = IsActive && !InUnion;
139 Desc->IsConst = IsConst || D->
IsConst;
140 Desc->IsFieldMutable = IsMutable || D->
IsMutable;
141 Desc->InUnion = InUnion;
142 Desc->IsVolatile =
false;
145 initBase(B, Ptr + FieldOffset, IsConst, IsMutable, IsVolatile, IsActive,
146 InUnion,
V.Desc,
V.Offset,
false);
148 initField(B, Ptr + FieldOffset, IsConst, IsMutable, IsVolatile, IsActive,
149 InUnion, InUnion, F.Desc, F.Offset);
153 bool IsVolatile,
bool IsActive,
bool InUnion,
156 initBase(B, Ptr, IsConst, IsMutable, IsVolatile, IsActive, InUnion,
V.Desc,
160 bool IsUnionField = D->
isUnion();
161 initField(B, Ptr, IsConst, IsMutable, IsVolatile, IsActive, IsUnionField,
162 InUnion || IsUnionField, F.Desc, F.Offset);
165 initBase(B, Ptr, IsConst, IsMutable, IsVolatile, IsActive, InUnion,
V.Desc,
171 unsigned FieldOffset) {
173 Fn(B, Ptr + FieldOffset, D);
177 unsigned FieldOffset) {
198 for (
const auto &B : R->bases()) {
203 for (
const auto &F : R->fields()) {
208 for (
const auto &
V : R->virtual_bases()) {
224 llvm_unreachable(
"Unhandled PrimType");
231template <
typename T>
static constexpr bool needsCtor() {
233 if constexpr (std::is_same_v<T, Char<true>> ||
234 std::is_same_v<T, Char<false>> ||
235 std::is_same_v<T, Integral<16, true>> ||
236 std::is_same_v<T, Integral<16, false>> ||
237 std::is_same_v<T, Integral<32, true>> ||
238 std::is_same_v<T, Integral<32, false>> ||
239 std::is_same_v<T, Integral<64, true>> ||
240 std::is_same_v<T, Integral<64, false>> ||
241 std::is_same_v<T, IntegralAP<true>> ||
242 std::is_same_v<T, IntegralAP<false>> ||
243 std::is_same_v<T, Floating> || std::is_same_v<T, Boolean>)
252 return ctorArrayTy<T>);
253 llvm_unreachable(
"unknown Expr");
265 llvm_unreachable(
"Unhandled PrimType");
270static void ctorArrayTy(
Block *, std::byte *Ptr,
bool,
bool,
bool,
bool,
bool,
274 if constexpr (needsCtor<T>()) {
277 new (&
reinterpret_cast<T *
>(
Ptr)[I])
T();
282static void ctorTy(
Block *, std::byte *Ptr,
bool,
bool,
bool,
bool,
bool,
284 static_assert(needsCtor<T>());
291 llvm_unreachable(
"unknown Expr");
298 : Source(D), SourceType(SourceTy), ElemSize(
primSize(
Type)), Size(ElemSize),
302 assert(Source &&
"Missing source");
309 : Source(D), SourceType(SourceTy), ElemSize(
primSize(
Type)),
310 Size(ElemSize * NumElems), AllocSize(
align(Size) + sizeof(
InitMapPtr)),
314 assert(Source &&
"Missing source");
321 : Source(D), ElemSize(
primSize(
Type)), Size(UnknownSizeMark),
325 assert(Source &&
"Missing source");
332 : Source(D), SourceType(SourceTy),
334 Size(ElemSize * NumElems),
339 assert(Source &&
"Missing source");
346 Size(UnknownSizeMark), AllocSize(alignof(void *)),
ElemDesc(Elem),
349 assert(Source &&
"Missing source");
355 : Source(D), ElemSize(
std::
max<
size_t>(alignof(void *), R->getFullSize())),
359 assert(Source &&
"Missing source");
366 assert(Source &&
"Missing source");
373 if (
const auto *
T = dyn_cast_if_present<TypeDecl>(
asDecl()))
374 return T->getASTContext().getTypeDeclType(
T);
381 std::nullopt, RD,
false);
383 return T.withConst();
387 if (
const auto *E =
asExpr()) {
389 return E->getType()->getPointeeType();
392 if (
const auto *ME = dyn_cast<CXXMemberCallExpr>(E);
393 ME && ME->getRecordDecl()->getName() ==
"allocator" &&
394 ME->getMethodDecl()->getName() ==
"allocate")
395 return E->getType()->getPointeeType();
402 llvm_unreachable(
"Invalid descriptor type");
411 }
else if (
const auto *TDecl = dyn_cast_if_present<TypeDecl>(
asDecl())) {
412 T = TDecl->getASTContext().getTypeDeclType(TDecl);
416 std::nullopt, RD,
false);
419 }
else if (
const auto *E =
asExpr()) {
428 T = AT->getValueType();
429 if (
T->isPointerOrReferenceType())
430 T =
T->getPointeeType();
432 if (
const auto *AT =
T->getAsArrayTypeUnsafe()) {
436 while (
T->isArrayType())
437 T =
T->getAsArrayTypeUnsafe()->getElementType();
440 return AT->getElementType();
443 return CT->getElementType();
445 return CT->getElementType();
459 if (
const auto *E =
asExpr()) {
461 return MakeArrayType(E->getType()->getPointeeType());
464 if (
const auto *ME = dyn_cast<CXXMemberCallExpr>(E);
465 ME && ME->getRecordDecl()->getName() ==
"allocator" &&
466 ME->getMethodDecl()->getName() ==
"allocate")
467 return MakeArrayType(E->getType()->getPointeeType());
475 if (
const auto *D = Source.
asDecl())
477 if (
const auto *E = Source.asExpr())
479 llvm_unreachable(
"Invalid descriptor type");
static void ctorRecord(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable, bool IsVolatile, bool IsActive, bool InUnion, const Descriptor *D)
static void dtorTy(Block *, std::byte *Ptr, const Descriptor *)
static void destroyField(Block *B, std::byte *Ptr, const Descriptor *D, unsigned FieldOffset)
static void initField(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable, bool IsVolatile, bool IsActive, bool IsUnionField, bool InUnion, const Descriptor *D, unsigned FieldOffset)
static void dtorArrayTy(Block *, std::byte *Ptr, const Descriptor *D)
static constexpr bool needsDtor()
static void ctorArrayDesc(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable, bool IsVolatile, bool IsActive, bool InUnion, const Descriptor *D)
static void destroyBase(Block *B, std::byte *Ptr, const Descriptor *D, unsigned FieldOffset)
static void dtorArrayDesc(Block *B, std::byte *Ptr, const Descriptor *D)
static bool needsRecordDtor(const Record *R)
Whether a record needs its descriptor dtor function called.
static BlockDtorFn getDtorArrayPrim(PrimType Type)
static BlockDtorFn getDtorPrim(PrimType T)
static void dtorRecord(Block *B, std::byte *Ptr, const Descriptor *D)
static void initBase(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable, bool IsVolatile, bool IsActive, bool InUnion, const Descriptor *D, unsigned FieldOffset, bool IsVirtualBase)
Defines the clang::Expr interface and subclasses for C++ expressions.
#define FIXED_SIZE_INT_TYPE_SWITCH(Expr, B)
#define TYPE_SWITCH(Expr, B)
__DEVICE__ int max(int __a, int __b)
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
QualType getTagType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TagDecl *TD, bool OwnsTag) const
Complex values, per C99 6.2.5p11.
ASTContext & getASTContext() const LLVM_READONLY
A (possibly-)qualified type.
Represents a struct/union/class.
The base class of the type hierarchy.
Represents a GCC generic vector type.
A memory block, either on the stack or in the heap.
Structure/Class descriptor.
bool isUnion() const
Checks if the record is a union.
llvm::iterator_range< const_base_iter > bases() const
llvm::iterator_range< const_base_iter > virtual_bases() const
llvm::iterator_range< const_field_iter > fields() const
Describes the statement/declaration an opcode was generated from.
void(*)(Block *Storage, std::byte *FieldPtr, const Descriptor *FieldDesc) BlockDtorFn
Invoked when a block is destroyed.
bool NE(InterpState &S, CodePtr OpPC)
constexpr size_t align(size_t Size)
Aligns a size to the pointer alignment.
constexpr bool isIntegerOrBoolType(PrimType T)
PrimType
Enumeration of the primitive types of the VM.
size_t primSize(PrimType Type)
Returns the size of a primitive type in bytes.
void(*)(Block *Storage, std::byte *FieldPtr, bool IsConst, bool IsMutable, bool IsVolatile, bool IsActive, bool InUnion, const Descriptor *FieldDesc) BlockCtorFn
Invoked whenever a block is created.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
const FunctionProtoType * T
@ None
No keyword precedes the qualified type name.
Token to denote structures of unknown size.
Describes a memory block created by an allocation site.
const bool IsConst
Flag indicating if the block is mutable.
unsigned getAllocSize() const
Returns the allocated size, including metadata.
unsigned getNumElems() const
Returns the number of elements stored in the block.
bool isPrimitive() const
Checks if the descriptor is of a primitive.
QualType getElemQualType() const
bool hasTrivialDtor() const
Whether variables of this descriptor need their destructor called or not.
const OptPrimType PrimT
The primitive type this descriptor was created for, or the primitive element type in case this is a p...
const ValueDecl * asValueDecl() const
const BlockCtorFn CtorFn
Storage management methods.
static constexpr unsigned MaxArrayElemBytes
Maximum number of bytes to be used for array elements.
const Decl * asDecl() const
const Descriptor *const ElemDesc
Descriptor of the array element.
SourceInfo getLoc() const
const bool IsMutable
Flag indicating if a field is mutable.
QualType getDataType(const ASTContext &Ctx) const
const bool IsArray
Flag indicating if the block is an array.
unsigned getElemDataSize() const
Returns the element data size, i.e.
bool isPrimitiveArray() const
Checks if the descriptor is of an array of primitives.
Descriptor(DeclOrExpr D, const Type *SourceTy, PrimType Type, bool IsConst, bool IsTemporary, bool IsMutable, bool IsVolatile)
Allocates a descriptor for a primitive.
PrimType getPrimType() const
bool isRecord() const
Checks if the descriptor is of a record.
const bool IsTemporary
Flag indicating if the block is a temporary.
const Record *const ElemRecord
Pointer to the record, if block contains records.
bool isUnion() const
Checks if the descriptor is of a union.
const Expr * asExpr() const
bool isArray() const
Checks if the descriptor is of an array.
A pointer-sized struct we use to allocate into data storage.
void deleteInitMap()
Delete the InitMap if one exists.
Inline descriptor embedded in structures and arrays.
unsigned Offset
Offset inside the structure/array.