[clang][Interp][NFC] Take a const Descriptor* in dtor,move,ctorFns
authorTimm Bäder <tbaeder@redhat.com>
Mon, 6 Mar 2023 13:57:19 +0000 (14:57 +0100)
committerTimm Bäder <tbaeder@redhat.com>
Thu, 9 Mar 2023 15:08:59 +0000 (16:08 +0100)
We are not mutating the descriptors here.

clang/lib/AST/Interp/Descriptor.cpp
clang/lib/AST/Interp/Descriptor.h

index e9fe159..212311c 100644 (file)
@@ -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;
index 57cb572..5b86ffb 100644 (file)
@@ -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.
 ///