Author: Timm Bäder Date: 2023-03-09T16:08:59+01:00 New Revision: 0041f081962c60a96d45d9a3a964c2d00216c16d
URL: https://github.com/llvm/llvm-project/commit/0041f081962c60a96d45d9a3a964c2d00216c16d DIFF: https://github.com/llvm/llvm-project/commit/0041f081962c60a96d45d9a3a964c2d00216c16d.diff LOG: [clang][Interp][NFC] Take a const Descriptor* in dtor,move,ctorFns We are not mutating the descriptors here. Added: Modified: clang/lib/AST/Interp/Descriptor.cpp clang/lib/AST/Interp/Descriptor.h Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/Descriptor.cpp b/clang/lib/AST/Interp/Descriptor.cpp index e9fe159eccd4b..212311cfa2ae6 100644 --- a/clang/lib/AST/Interp/Descriptor.cpp +++ b/clang/lib/AST/Interp/Descriptor.cpp @@ -17,30 +17,32 @@ using namespace clang; using namespace clang::interp; template <typename T> -static void ctorTy(Block *, char *Ptr, bool, bool, bool, Descriptor *) { +static void ctorTy(Block *, char *Ptr, bool, bool, bool, const Descriptor *) { new (Ptr) T(); } -template <typename T> static void dtorTy(Block *, char *Ptr, Descriptor *) { +template <typename T> +static void dtorTy(Block *, char *Ptr, const Descriptor *) { reinterpret_cast<T *>(Ptr)->~T(); } template <typename T> -static void moveTy(Block *, char *Src, char *Dst, Descriptor *) { +static void moveTy(Block *, char *Src, char *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 *, char *Ptr, bool, bool, bool, Descriptor *D) { +static void ctorArrayTy(Block *, char *Ptr, bool, bool, bool, + const Descriptor *D) { for (unsigned I = 0, NE = D->getNumElems(); I < NE; ++I) { new (&reinterpret_cast<T *>(Ptr)[I]) T(); } } template <typename T> -static void dtorArrayTy(Block *, char *Ptr, Descriptor *D) { +static void dtorArrayTy(Block *, char *Ptr, const Descriptor *D) { InitMap *IM = *reinterpret_cast<InitMap **>(Ptr); if (IM != (InitMap *)-1) free(IM); @@ -52,7 +54,7 @@ static void dtorArrayTy(Block *, char *Ptr, Descriptor *D) { } template <typename T> -static void moveArrayTy(Block *, char *Src, char *Dst, Descriptor *D) { +static void moveArrayTy(Block *, char *Src, char *Dst, const Descriptor *D) { for (unsigned I = 0, NE = D->getNumElems(); I < NE; ++I) { auto *SrcPtr = &reinterpret_cast<T *>(Src)[I]; auto *DstPtr = &reinterpret_cast<T *>(Dst)[I]; @@ -61,7 +63,7 @@ static void moveArrayTy(Block *, char *Src, char *Dst, Descriptor *D) { } static void ctorArrayDesc(Block *B, char *Ptr, bool IsConst, bool IsMutable, - bool IsActive, Descriptor *D) { + bool IsActive, const Descriptor *D) { const unsigned NumElems = D->getNumElems(); const unsigned ElemSize = D->ElemDesc->getAllocSize() + sizeof(InlineDescriptor); @@ -86,7 +88,7 @@ static void ctorArrayDesc(Block *B, char *Ptr, bool IsConst, bool IsMutable, } } -static void dtorArrayDesc(Block *B, char *Ptr, Descriptor *D) { +static void dtorArrayDesc(Block *B, char *Ptr, const Descriptor *D) { const unsigned NumElems = D->getNumElems(); const unsigned ElemSize = D->ElemDesc->getAllocSize() + sizeof(InlineDescriptor); @@ -101,7 +103,7 @@ static void dtorArrayDesc(Block *B, char *Ptr, Descriptor *D) { } } -static void moveArrayDesc(Block *B, char *Src, char *Dst, Descriptor *D) { +static void moveArrayDesc(Block *B, char *Src, char *Dst, const Descriptor *D) { const unsigned NumElems = D->getNumElems(); const unsigned ElemSize = D->ElemDesc->getAllocSize() + sizeof(InlineDescriptor); @@ -123,7 +125,7 @@ static void moveArrayDesc(Block *B, char *Src, char *Dst, Descriptor *D) { } static void ctorRecord(Block *B, char *Ptr, bool IsConst, bool IsMutable, - bool IsActive, Descriptor *D) { + bool IsActive, const Descriptor *D) { const bool IsUnion = D->ElemRecord->isUnion(); auto CtorSub = [=](unsigned SubOff, Descriptor *F, bool IsBase) { auto *Desc = reinterpret_cast<InlineDescriptor *>(Ptr + SubOff) - 1; @@ -146,7 +148,7 @@ static void ctorRecord(Block *B, char *Ptr, bool IsConst, bool IsMutable, CtorSub(V.Offset, V.Desc, /*isBase=*/true); } -static void dtorRecord(Block *B, char *Ptr, Descriptor *D) { +static void dtorRecord(Block *B, char *Ptr, const Descriptor *D) { auto DtorSub = [=](unsigned SubOff, Descriptor *F) { if (auto Fn = F->DtorFn) Fn(B, Ptr + SubOff, F); @@ -159,7 +161,7 @@ static void dtorRecord(Block *B, char *Ptr, Descriptor *D) { DtorSub(F.Offset, F.Desc); } -static void moveRecord(Block *B, char *Src, char *Dst, Descriptor *D) { +static void moveRecord(Block *B, char *Src, char *Dst, const Descriptor *D) { for (const auto &F : D->ElemRecord->fields()) { auto FieldOff = F.Offset; auto FieldDesc = F.Desc; diff --git a/clang/lib/AST/Interp/Descriptor.h b/clang/lib/AST/Interp/Descriptor.h index 57cb5728c9ba8..5b86ffb7957a0 100644 --- a/clang/lib/AST/Interp/Descriptor.h +++ b/clang/lib/AST/Interp/Descriptor.h @@ -30,19 +30,19 @@ using DeclTy = llvm::PointerUnion<const Decl *, const Expr *>; /// all the fields which contain non-trivial types. using BlockCtorFn = void (*)(Block *Storage, char *FieldPtr, bool IsConst, bool IsMutable, bool IsActive, - Descriptor *FieldDesc); + const Descriptor *FieldDesc); /// Invoked when a block is destroyed. Invokes the destructors of all /// non-trivial nested fields of arrays and records. using BlockDtorFn = void (*)(Block *Storage, char *FieldPtr, - Descriptor *FieldDesc); + const Descriptor *FieldDesc); /// Invoked when a block with pointers referencing it goes out of scope. Such /// blocks are persisted: the move function copies all inline descriptors and /// non-trivial fields, as existing pointers might need to reference those /// descriptors. Data is not copied since it cannot be legally read. using BlockMoveFn = void (*)(Block *Storage, char *SrcFieldPtr, - char *DstFieldPtr, Descriptor *FieldDesc); + char *DstFieldPtr, const Descriptor *FieldDesc); /// Inline descriptor embedded in structures and arrays. /// _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits