Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 29 additions & 51 deletions clang/lib/AST/ByteCode/Descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ static void dtorTy(Block *, std::byte *Ptr, const Descriptor *) {
reinterpret_cast<T *>(Ptr)->~T();
}

template <typename T>
static void moveTy(Block *, std::byte *Src, std::byte *Dst,
const Descriptor *) {
auto *SrcPtr = reinterpret_cast<T *>(Src);
auto *DstPtr = reinterpret_cast<T *>(Dst);
new (DstPtr) T(std::move(*SrcPtr));
}

template <typename T>
static void ctorArrayTy(Block *, std::byte *Ptr, bool, bool, bool, bool, bool,
const Descriptor *D) {
Expand Down Expand Up @@ -85,28 +77,6 @@ static void dtorArrayTy(Block *, std::byte *Ptr, const Descriptor *D) {
}
}

template <typename T>
static void moveArrayTy(Block *, std::byte *Src, std::byte *Dst,
const Descriptor *D) {
InitMapPtr &SrcIMP = *reinterpret_cast<InitMapPtr *>(Src);
if (SrcIMP) {
// We only ever invoke the moveFunc when moving block contents to a
// DeadBlock. DeadBlocks don't need InitMaps, so we destroy them here.
SrcIMP = std::nullopt;
}
Src += sizeof(InitMapPtr);
Dst += sizeof(InitMapPtr);
if constexpr (!needsCtor<T>()) {
std::memcpy(Dst, Src, D->getNumElems() * D->getElemSize());
} else {
for (unsigned I = 0, NE = D->getNumElems(); I < NE; ++I) {
auto *SrcPtr = &reinterpret_cast<T *>(Src)[I];
auto *DstPtr = &reinterpret_cast<T *>(Dst)[I];
new (DstPtr) T(std::move(*SrcPtr));
}
}
}

static void ctorArrayDesc(Block *B, std::byte *Ptr, bool IsConst,
bool IsMutable, bool IsVolatile, bool IsActive,
bool InUnion, const Descriptor *D) {
Expand Down Expand Up @@ -144,12 +114,14 @@ static void dtorArrayDesc(Block *B, std::byte *Ptr, const Descriptor *D) {
D->ElemDesc->getAllocSize() + sizeof(InlineDescriptor);

unsigned ElemOffset = 0;
for (unsigned I = 0; I < NumElems; ++I, ElemOffset += ElemSize) {
auto Dtor = D->ElemDesc->DtorFn;
assert(Dtor &&
"a composite array without an elem dtor shouldn't have a dtor itself");
for (unsigned I = 0; I != NumElems; ++I, ElemOffset += ElemSize) {
auto *ElemPtr = Ptr + ElemOffset;
auto *Desc = reinterpret_cast<InlineDescriptor *>(ElemPtr);
auto *ElemLoc = reinterpret_cast<std::byte *>(Desc + 1);
if (auto Fn = D->ElemDesc->DtorFn)
Fn(B, ElemLoc, D->ElemDesc);
Dtor(B, ElemLoc, D->ElemDesc);
}
}

Expand Down Expand Up @@ -265,34 +237,40 @@ static bool needsRecordDtor(const Record *R) {
return false;
}

static BlockCtorFn getCtorPrim(PrimType Type) {
// Floating types are special. They are primitives, but need their
// constructor called.
if (Type == PT_Float)
static BlockCtorFn getCtorPrim(PrimType T) {
switch (T) {
case PT_Float:
return ctorTy<PrimConv<PT_Float>::T>;
if (Type == PT_IntAP)
case PT_IntAP:
return ctorTy<PrimConv<PT_IntAP>::T>;
if (Type == PT_IntAPS)
case PT_IntAPS:
return ctorTy<PrimConv<PT_IntAPS>::T>;
if (Type == PT_MemberPtr)
case PT_Ptr:
return ctorTy<PrimConv<PT_Ptr>::T>;
case PT_MemberPtr:
return ctorTy<PrimConv<PT_MemberPtr>::T>;

COMPOSITE_TYPE_SWITCH(Type, return ctorTy<T>, return nullptr);
default:
return nullptr;
}
llvm_unreachable("Unhandled PrimType");
}

static BlockDtorFn getDtorPrim(PrimType Type) {
// Floating types are special. They are primitives, but need their
// destructor called, since they might allocate memory.
if (Type == PT_Float)
static BlockDtorFn getDtorPrim(PrimType T) {
switch (T) {
case PT_Float:
return dtorTy<PrimConv<PT_Float>::T>;
if (Type == PT_IntAP)
case PT_IntAP:
return dtorTy<PrimConv<PT_IntAP>::T>;
if (Type == PT_IntAPS)
case PT_IntAPS:
return dtorTy<PrimConv<PT_IntAPS>::T>;
if (Type == PT_MemberPtr)
case PT_Ptr:
return dtorTy<PrimConv<PT_Ptr>::T>;
case PT_MemberPtr:
return dtorTy<PrimConv<PT_MemberPtr>::T>;

COMPOSITE_TYPE_SWITCH(Type, return dtorTy<T>, return nullptr);
default:
return nullptr;
}
llvm_unreachable("Unhandled PrimType");
}

static BlockCtorFn getCtorArrayPrim(PrimType Type) {
Expand Down
10 changes: 0 additions & 10 deletions clang/lib/AST/ByteCode/PrimType.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,4 @@ static inline bool aligned(const void *P) {
} \
} while (0)

#define COMPOSITE_TYPE_SWITCH(Expr, B, D) \
do { \
switch (Expr) { \
TYPE_SWITCH_CASE(PT_Ptr, B) \
default: { \
D; \
break; \
} \
} \
} while (0)
#endif