Skip to content

Commit 115d36d

Browse files
tbaederrcjdb
authored andcommitted
[clang][bytecode][NFC] Get rid of const_casts in Move fns (llvm#105698)
1 parent bafb190 commit 115d36d

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

clang/lib/AST/ByteCode/Descriptor.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ static void dtorTy(Block *, std::byte *Ptr, const Descriptor *) {
3131
}
3232

3333
template <typename T>
34-
static void moveTy(Block *, const std::byte *Src, std::byte *Dst,
34+
static void moveTy(Block *, std::byte *Src, std::byte *Dst,
3535
const Descriptor *) {
36-
// FIXME: Get rid of the const_cast.
37-
auto *SrcPtr = reinterpret_cast<T *>(const_cast<std::byte *>(Src));
36+
auto *SrcPtr = reinterpret_cast<T *>(Src);
3837
auto *DstPtr = reinterpret_cast<T *>(Dst);
3938
new (DstPtr) T(std::move(*SrcPtr));
4039
}
@@ -63,11 +62,9 @@ static void dtorArrayTy(Block *, std::byte *Ptr, const Descriptor *D) {
6362
}
6463

6564
template <typename T>
66-
static void moveArrayTy(Block *, const std::byte *Src, std::byte *Dst,
65+
static void moveArrayTy(Block *, std::byte *Src, std::byte *Dst,
6766
const Descriptor *D) {
68-
// FIXME: Get rid of the const_cast.
69-
InitMapPtr &SrcIMP =
70-
*reinterpret_cast<InitMapPtr *>(const_cast<std::byte *>(Src));
67+
InitMapPtr &SrcIMP = *reinterpret_cast<InitMapPtr *>(Src);
7168
if (SrcIMP) {
7269
// We only ever invoke the moveFunc when moving block contents to a
7370
// DeadBlock. DeadBlocks don't need InitMaps, so we destroy them here.
@@ -76,7 +73,7 @@ static void moveArrayTy(Block *, const std::byte *Src, std::byte *Dst,
7673
Src += sizeof(InitMapPtr);
7774
Dst += sizeof(InitMapPtr);
7875
for (unsigned I = 0, NE = D->getNumElems(); I < NE; ++I) {
79-
auto *SrcPtr = &reinterpret_cast<T *>(const_cast<std::byte *>(Src))[I];
76+
auto *SrcPtr = &reinterpret_cast<T *>(Src)[I];
8077
auto *DstPtr = &reinterpret_cast<T *>(Dst)[I];
8178
new (DstPtr) T(std::move(*SrcPtr));
8279
}
@@ -126,19 +123,19 @@ static void dtorArrayDesc(Block *B, std::byte *Ptr, const Descriptor *D) {
126123
}
127124
}
128125

129-
static void moveArrayDesc(Block *B, const std::byte *Src, std::byte *Dst,
126+
static void moveArrayDesc(Block *B, std::byte *Src, std::byte *Dst,
130127
const Descriptor *D) {
131128
const unsigned NumElems = D->getNumElems();
132129
const unsigned ElemSize =
133130
D->ElemDesc->getAllocSize() + sizeof(InlineDescriptor);
134131

135132
unsigned ElemOffset = 0;
136133
for (unsigned I = 0; I < NumElems; ++I, ElemOffset += ElemSize) {
137-
const auto *SrcPtr = Src + ElemOffset;
134+
auto *SrcPtr = Src + ElemOffset;
138135
auto *DstPtr = Dst + ElemOffset;
139136

140-
const auto *SrcDesc = reinterpret_cast<const InlineDescriptor *>(SrcPtr);
141-
const auto *SrcElemLoc = reinterpret_cast<const std::byte *>(SrcDesc + 1);
137+
auto *SrcDesc = reinterpret_cast<InlineDescriptor *>(SrcPtr);
138+
auto *SrcElemLoc = reinterpret_cast<std::byte *>(SrcDesc + 1);
142139
auto *DstDesc = reinterpret_cast<InlineDescriptor *>(DstPtr);
143140
auto *DstElemLoc = reinterpret_cast<std::byte *>(DstDesc + 1);
144141

@@ -233,7 +230,7 @@ static void dtorRecord(Block *B, std::byte *Ptr, const Descriptor *D) {
233230
destroyBase(B, Ptr, F.Desc, F.Offset);
234231
}
235232

236-
static void moveRecord(Block *B, const std::byte *Src, std::byte *Dst,
233+
static void moveRecord(Block *B, std::byte *Src, std::byte *Dst,
237234
const Descriptor *D) {
238235
assert(D);
239236
assert(D->ElemRecord);

clang/lib/AST/ByteCode/Descriptor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ using BlockDtorFn = void (*)(Block *Storage, std::byte *FieldPtr,
4444
/// blocks are persisted: the move function copies all inline descriptors and
4545
/// non-trivial fields, as existing pointers might need to reference those
4646
/// descriptors. Data is not copied since it cannot be legally read.
47-
using BlockMoveFn = void (*)(Block *Storage, const std::byte *SrcFieldPtr,
47+
using BlockMoveFn = void (*)(Block *Storage, std::byte *SrcFieldPtr,
4848
std::byte *DstFieldPtr,
4949
const Descriptor *FieldDesc);
5050

0 commit comments

Comments
 (0)