26template <
typename T>
static constexpr bool needsDtor() {
27 return std::is_same_v<T, Pointer> || std::is_same_v<T, MemberPointer>;
33 reinterpret_cast<T *
>(Ptr)->~
T();
44 reinterpret_cast<T *
>(Ptr)[I].~
T();
50 bool IsMutable,
bool IsVolatile,
bool IsActive,
53 const unsigned ElemSize =
56 unsigned ElemOffset = 0;
57 for (
unsigned I = 0; I != NumElems; ++I, ElemOffset += ElemSize) {
58 auto *ElemPtr = Ptr + ElemOffset;
64 Desc->IsInitialized =
true;
66 Desc->IsActive = IsActive;
67 Desc->IsConst = IsConst || D->
IsConst;
68 Desc->IsFieldMutable = IsMutable || D->
IsMutable;
69 Desc->InUnion = InUnion;
70 Desc->IsArrayElement =
true;
71 Desc->IsVolatile = IsVolatile;
74 auto *ElemLoc =
reinterpret_cast<std::byte *
>(Desc + 1);
75 Fn(B, ElemLoc, Desc->IsConst, Desc->IsFieldMutable, IsVolatile, IsActive,
76 Desc->InUnion || SD->isUnion(), D->
ElemDesc);
83 const unsigned ElemSize =
86 unsigned ElemOffset = 0;
89 "a composite array without an elem dtor shouldn't have a dtor itself");
90 for (
unsigned I = 0; I != NumElems; ++I, ElemOffset += ElemSize) {
91 auto *ElemPtr = Ptr + ElemOffset;
93 auto *ElemLoc =
reinterpret_cast<std::byte *
>(Desc + 1);
99 bool IsVolatile,
bool IsActive,
bool IsUnionField,
100 bool InUnion,
const Descriptor *D,
unsigned FieldOffset) {
102 Desc->
Offset = FieldOffset;
104 Desc->IsInitialized = D->
IsArray;
105 Desc->IsBase =
false;
106 Desc->IsActive = IsActive && !IsUnionField;
107 Desc->InUnion = InUnion;
108 Desc->IsConst = IsConst || D->
IsConst;
109 Desc->IsFieldMutable = IsMutable || D->
IsMutable;
110 Desc->IsVolatile = IsVolatile || D->
IsVolatile;
112 Desc->IsConstInMutable = Desc->IsConst && IsMutable;
119 Fn(B, Ptr + FieldOffset, Desc->IsConst, Desc->IsFieldMutable,
120 Desc->IsVolatile, Desc->IsActive, InUnion || D->
isUnion(), D);
124 bool IsVolatile,
bool IsActive,
bool InUnion,
126 bool IsVirtualBase) {
132 Desc->
Offset = FieldOffset;
134 Desc->IsInitialized = D->
IsArray;
136 Desc->IsVirtualBase = IsVirtualBase;
137 Desc->IsActive = IsActive && !InUnion;
138 Desc->IsConst = IsConst || D->
IsConst;
139 Desc->IsFieldMutable = IsMutable || D->
IsMutable;
140 Desc->InUnion = InUnion;
141 Desc->IsVolatile =
false;
144 initBase(B, Ptr + FieldOffset, IsConst, IsMutable, IsVolatile, IsActive,
145 InUnion,
V.Desc,
V.Offset,
false);
147 initField(B, Ptr + FieldOffset, IsConst, IsMutable, IsVolatile, IsActive,
148 InUnion, InUnion, F.Desc, F.Offset);
152 bool IsVolatile,
bool IsActive,
bool InUnion,
155 initBase(B, Ptr, IsConst, IsMutable, IsVolatile, IsActive, InUnion,
V.Desc,
159 bool IsUnionField = D->
isUnion();
160 initField(B, Ptr, IsConst, IsMutable, IsVolatile, IsActive, IsUnionField,
161 InUnion || IsUnionField, F.Desc, F.Offset);
164 initBase(B, Ptr, IsConst, IsMutable, IsVolatile, IsActive, InUnion,
V.Desc,
170 unsigned FieldOffset) {
172 Fn(B, Ptr + FieldOffset, D);
176 unsigned FieldOffset) {
197 for (
const auto &B : R->bases()) {
202 for (
const auto &F : R->fields()) {
207 for (
const auto &
V : R->virtual_bases()) {
223 llvm_unreachable(
"Unhandled PrimType");
230template <
typename T>
static constexpr bool needsCtor() {
232 if constexpr (std::is_same_v<T, Char<true>> ||
233 std::is_same_v<T, Char<false>> ||
234 std::is_same_v<T, Integral<16, true>> ||
235 std::is_same_v<T, Integral<16, false>> ||
236 std::is_same_v<T, Integral<32, true>> ||
237 std::is_same_v<T, Integral<32, false>> ||
238 std::is_same_v<T, Integral<64, true>> ||
239 std::is_same_v<T, Integral<64, false>> ||
240 std::is_same_v<T, IntegralAP<true>> ||
241 std::is_same_v<T, IntegralAP<false>> ||
242 std::is_same_v<T, Floating> || std::is_same_v<T, Boolean>)
251 return ctorArrayTy<T>);
252 llvm_unreachable(
"unknown Expr");
264 llvm_unreachable(
"Unhandled PrimType");
269static void ctorArrayTy(
Block *, std::byte *Ptr,
bool,
bool,
bool,
bool,
bool,
273 if constexpr (needsCtor<T>()) {
276 new (&
reinterpret_cast<T *
>(
Ptr)[I])
T();
281static void ctorTy(
Block *, std::byte *Ptr,
bool,
bool,
bool,
bool,
bool,
283 static_assert(needsCtor<T>());
290 llvm_unreachable(
"unknown Expr");
297 : Source(D), SourceType(SourceTy), ElemSize(
primSize(
Type)), Size(ElemSize),
301 assert(Source &&
"Missing source");
308 : Source(D), SourceType(SourceTy), ElemSize(
primSize(
Type)),
309 Size(ElemSize * NumElems), AllocSize(
align(Size) + sizeof(
InitMapPtr)),
313 assert(Source &&
"Missing source");
320 : Source(D), ElemSize(
primSize(
Type)), Size(UnknownSizeMark),
324 assert(Source &&
"Missing source");
331 : Source(D), SourceType(SourceTy),
333 Size(ElemSize * NumElems),
338 assert(Source &&
"Missing source");
345 Size(UnknownSizeMark), AllocSize(alignof(void *)),
ElemDesc(Elem),
348 assert(Source &&
"Missing source");
354 : Source(D), ElemSize(
std::
max<
size_t>(alignof(void *), R->getFullSize())),
358 assert(Source &&
"Missing source");
365 assert(Source &&
"Missing source");
372 if (
const auto *
T = dyn_cast_if_present<TypeDecl>(
asDecl()))
373 return T->getASTContext().getTypeDeclType(
T);
380 std::nullopt, RD,
false);
382 return T.withConst();
386 if (
const auto *E =
asExpr()) {
388 return E->getType()->getPointeeType();
391 if (
const auto *ME = dyn_cast<CXXMemberCallExpr>(E);
392 ME && ME->getRecordDecl()->getName() ==
"allocator" &&
393 ME->getMethodDecl()->getName() ==
"allocate")
394 return E->getType()->getPointeeType();
401 llvm_unreachable(
"Invalid descriptor type");
410 }
else if (
const auto *TDecl = dyn_cast_if_present<TypeDecl>(
asDecl())) {
411 T = TDecl->getASTContext().getTypeDeclType(TDecl);
415 std::nullopt, RD,
false);
418 }
else if (
const auto *E =
asExpr()) {
427 T = AT->getValueType();
428 if (
T->isPointerOrReferenceType())
429 T =
T->getPointeeType();
431 if (
const auto *AT =
T->getAsArrayTypeUnsafe()) {
435 while (
T->isArrayType())
436 T =
T->getAsArrayTypeUnsafe()->getElementType();
439 return AT->getElementType();
442 return CT->getElementType();
444 return CT->getElementType();
458 if (
const auto *E =
asExpr()) {
460 return MakeArrayType(E->getType()->getPointeeType());
463 if (
const auto *ME = dyn_cast<CXXMemberCallExpr>(E);
464 ME && ME->getRecordDecl()->getName() ==
"allocator" &&
465 ME->getMethodDecl()->getName() ==
"allocate")
466 return MakeArrayType(E->getType()->getPointeeType());
474 if (
auto *D = Source.
asDecl())
476 if (
auto *E = Source.asExpr())
477 return E->getExprLoc();
478 llvm_unreachable(
"Invalid descriptor type");
482 if (
const auto *D = Source.
asDecl())
484 if (
const auto *E = Source.asExpr())
486 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.
Encodes a location in the source.
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_virtual_iter > virtual_bases() const
llvm::iterator_range< const_base_iter > 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
SourceLocation getLocation() 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.