Skip to content

Commit

Permalink
[clang][Interp][NFC] Make Src parameter for move functions const
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Jun 5, 2023
1 parent c91246b commit e69448b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions clang/lib/AST/Interp/Descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ static void dtorTy(Block *, char *Ptr, const Descriptor *) {
}

template <typename T>
static void moveTy(Block *, char *Src, char *Dst, const Descriptor *) {
auto *SrcPtr = reinterpret_cast<T *>(Src);
static void moveTy(Block *, const char *Src, char *Dst, const Descriptor *) {
const auto *SrcPtr = reinterpret_cast<const T *>(Src);
auto *DstPtr = reinterpret_cast<T *>(Dst);
new (DstPtr) T(std::move(*SrcPtr));
}
Expand All @@ -55,9 +55,10 @@ static void dtorArrayTy(Block *, char *Ptr, const Descriptor *D) {
}

template <typename T>
static void moveArrayTy(Block *, char *Src, char *Dst, const Descriptor *D) {
static void moveArrayTy(Block *, const char *Src, char *Dst,
const Descriptor *D) {
for (unsigned I = 0, NE = D->getNumElems(); I < NE; ++I) {
auto *SrcPtr = &reinterpret_cast<T *>(Src)[I];
const auto *SrcPtr = &reinterpret_cast<const T *>(Src)[I];
auto *DstPtr = &reinterpret_cast<T *>(Dst)[I];
new (DstPtr) T(std::move(*SrcPtr));
}
Expand Down Expand Up @@ -104,18 +105,19 @@ static void dtorArrayDesc(Block *B, char *Ptr, const Descriptor *D) {
}
}

static void moveArrayDesc(Block *B, char *Src, char *Dst, const Descriptor *D) {
static void moveArrayDesc(Block *B, const char *Src, char *Dst,
const Descriptor *D) {
const unsigned NumElems = D->getNumElems();
const unsigned ElemSize =
D->ElemDesc->getAllocSize() + sizeof(InlineDescriptor);

unsigned ElemOffset = 0;
for (unsigned I = 0; I < NumElems; ++I, ElemOffset += ElemSize) {
auto *SrcPtr = Src + ElemOffset;
const auto *SrcPtr = Src + ElemOffset;
auto *DstPtr = Dst + ElemOffset;

auto *SrcDesc = reinterpret_cast<InlineDescriptor *>(SrcPtr);
auto *SrcElemLoc = reinterpret_cast<char *>(SrcDesc + 1);
const auto *SrcDesc = reinterpret_cast<const InlineDescriptor *>(SrcPtr);
const auto *SrcElemLoc = reinterpret_cast<const char *>(SrcDesc + 1);
auto *DstDesc = reinterpret_cast<InlineDescriptor *>(DstPtr);
auto *DstElemLoc = reinterpret_cast<char *>(DstDesc + 1);

Expand Down Expand Up @@ -162,7 +164,8 @@ static void dtorRecord(Block *B, char *Ptr, const Descriptor *D) {
DtorSub(F.Offset, F.Desc);
}

static void moveRecord(Block *B, char *Src, char *Dst, const Descriptor *D) {
static void moveRecord(Block *B, const char *Src, char *Dst,
const Descriptor *D) {
for (const auto &F : D->ElemRecord->fields()) {
auto FieldOff = F.Offset;
auto FieldDesc = F.Desc;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/Interp/Descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ using BlockDtorFn = void (*)(Block *Storage, char *FieldPtr,
/// 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,
using BlockMoveFn = void (*)(Block *Storage, const char *SrcFieldPtr,
char *DstFieldPtr, const Descriptor *FieldDesc);

/// Inline descriptor embedded in structures and arrays.
Expand Down

0 comments on commit e69448b

Please sign in to comment.