diff --git a/clang/lib/AST/ByteCode/Descriptor.cpp b/clang/lib/AST/ByteCode/Descriptor.cpp index 68536d4e2d777..647de56b28013 100644 --- a/clang/lib/AST/ByteCode/Descriptor.cpp +++ b/clang/lib/AST/ByteCode/Descriptor.cpp @@ -49,14 +49,6 @@ static void dtorTy(Block *, std::byte *Ptr, const Descriptor *) { reinterpret_cast(Ptr)->~T(); } -template -static void moveTy(Block *, std::byte *Src, std::byte *Dst, - const Descriptor *) { - auto *SrcPtr = reinterpret_cast(Src); - auto *DstPtr = reinterpret_cast(Dst); - new (DstPtr) T(std::move(*SrcPtr)); -} - template static void ctorArrayTy(Block *, std::byte *Ptr, bool, bool, bool, bool, bool, const Descriptor *D) { @@ -85,28 +77,6 @@ static void dtorArrayTy(Block *, std::byte *Ptr, const Descriptor *D) { } } -template -static void moveArrayTy(Block *, std::byte *Src, std::byte *Dst, - const Descriptor *D) { - InitMapPtr &SrcIMP = *reinterpret_cast(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()) { - std::memcpy(Dst, Src, D->getNumElems() * D->getElemSize()); - } else { - for (unsigned I = 0, NE = D->getNumElems(); I < NE; ++I) { - auto *SrcPtr = &reinterpret_cast(Src)[I]; - auto *DstPtr = &reinterpret_cast(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) { @@ -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(ElemPtr); auto *ElemLoc = reinterpret_cast(Desc + 1); - if (auto Fn = D->ElemDesc->DtorFn) - Fn(B, ElemLoc, D->ElemDesc); + Dtor(B, ElemLoc, D->ElemDesc); } } @@ -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::T>; - if (Type == PT_IntAP) + case PT_IntAP: return ctorTy::T>; - if (Type == PT_IntAPS) + case PT_IntAPS: return ctorTy::T>; - if (Type == PT_MemberPtr) + case PT_Ptr: + return ctorTy::T>; + case PT_MemberPtr: return ctorTy::T>; - - COMPOSITE_TYPE_SWITCH(Type, return ctorTy, 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::T>; - if (Type == PT_IntAP) + case PT_IntAP: return dtorTy::T>; - if (Type == PT_IntAPS) + case PT_IntAPS: return dtorTy::T>; - if (Type == PT_MemberPtr) + case PT_Ptr: + return dtorTy::T>; + case PT_MemberPtr: return dtorTy::T>; - - COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr); + default: + return nullptr; + } + llvm_unreachable("Unhandled PrimType"); } static BlockCtorFn getCtorArrayPrim(PrimType Type) { diff --git a/clang/lib/AST/ByteCode/PrimType.h b/clang/lib/AST/ByteCode/PrimType.h index 6e3a49cadcbf1..54fd39ac6fcc8 100644 --- a/clang/lib/AST/ByteCode/PrimType.h +++ b/clang/lib/AST/ByteCode/PrimType.h @@ -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