[compiler-rt] 5fe6f3e - Revert "[scudo] Fix implicitly narrow casting (NFC)"
Kamau Bridgeman via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 14 13:12:25 PDT 2022
Author: Kamau Bridgeman
Date: 2022-10-14T15:11:34-05:00
New Revision: 5fe6f3e0bc05964308ea6287a41851541a5034ee
URL: https://github.com/llvm/llvm-project/commit/5fe6f3e0bc05964308ea6287a41851541a5034ee
DIFF: https://github.com/llvm/llvm-project/commit/5fe6f3e0bc05964308ea6287a41851541a5034ee.diff
LOG: Revert "[scudo] Fix implicitly narrow casting (NFC)"
This reverts commit fd7c7ad4fe0138314b922ea0db1691d5a679cc75.
Added:
Modified:
compiler-rt/lib/scudo/standalone/local_cache.h
compiler-rt/lib/scudo/standalone/primary32.h
compiler-rt/lib/scudo/standalone/primary64.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/local_cache.h b/compiler-rt/lib/scudo/standalone/local_cache.h
index 6e84158659ae9..6e5b09fdb709e 100644
--- a/compiler-rt/lib/scudo/standalone/local_cache.h
+++ b/compiler-rt/lib/scudo/standalone/local_cache.h
@@ -31,8 +31,7 @@ template <class SizeClassAllocator> struct SizeClassAllocatorLocalCache {
void appendFromArray(CompactPtrT *Array, u16 N) {
DCHECK_LE(N, MaxNumCached - Count);
memcpy(Batch + Count, Array, sizeof(Batch[0]) * N);
- // u16 will be promoted to int by arithmetic type conversion.
- Count = static_cast<u16>(Count + N);
+ Count += N;
}
void clear() { Count = 0; }
void add(CompactPtrT P) {
@@ -190,7 +189,7 @@ template <class SizeClassAllocator> struct SizeClassAllocatorLocalCache {
for (uptr I = 0; I < NumClasses; I++) {
PerClass *P = &PerClassArray[I];
const uptr Size = SizeClassAllocator::getSizeByClassId(I);
- P->MaxCount = static_cast<u16>(2 * TransferBatch::getMaxCached(Size));
+ P->MaxCount = 2 * TransferBatch::getMaxCached(Size);
if (I != BatchClassId) {
P->ClassSize = Size;
} else {
@@ -222,8 +221,7 @@ template <class SizeClassAllocator> struct SizeClassAllocatorLocalCache {
NOINLINE void drain(PerClass *C, uptr ClassId) {
const u16 Count = Min(static_cast<u16>(C->MaxCount / 2), C->Count);
Allocator->pushBlocks(this, ClassId, &C->Chunks[0], Count);
- // u16 will be promoted to int by arithmetic type conversion.
- C->Count = static_cast<u16>(C->Count - Count);
+ C->Count -= Count;
for (u16 I = 0; I < C->Count; I++)
C->Chunks[I] = C->Chunks[I + Count];
}
diff --git a/compiler-rt/lib/scudo/standalone/primary32.h b/compiler-rt/lib/scudo/standalone/primary32.h
index c30f22f3fe990..fb6cb53392358 100644
--- a/compiler-rt/lib/scudo/standalone/primary32.h
+++ b/compiler-rt/lib/scudo/standalone/primary32.h
@@ -436,8 +436,7 @@ template <typename Config> class SizeClassAllocator32 {
for (u32 I = 0; I < Size;) {
DCHECK_GE(BG->MaxCachedPerBatch, CurBatch->getCount());
- u16 UnusedSlots =
- static_cast<u16>(BG->MaxCachedPerBatch - CurBatch->getCount());
+ u16 UnusedSlots = BG->MaxCachedPerBatch - CurBatch->getCount();
if (UnusedSlots == 0) {
CurBatch = C->createBatch(ClassId, reinterpret_cast<void *>(
decompactPtr(ClassId, Array[I])));
@@ -445,7 +444,6 @@ template <typename Config> class SizeClassAllocator32 {
Batches.push_front(CurBatch);
UnusedSlots = BG->MaxCachedPerBatch;
}
- // `UnusedSlots` is u16 so the result will be also fit in u16.
u16 AppendSize = static_cast<u16>(Min<u32>(UnusedSlots, Size - I));
CurBatch->appendFromArray(&Array[I], AppendSize);
I += AppendSize;
diff --git a/compiler-rt/lib/scudo/standalone/primary64.h b/compiler-rt/lib/scudo/standalone/primary64.h
index 29d498f309a47..2b6e71c8584ab 100644
--- a/compiler-rt/lib/scudo/standalone/primary64.h
+++ b/compiler-rt/lib/scudo/standalone/primary64.h
@@ -442,8 +442,7 @@ template <typename Config> class SizeClassAllocator64 {
for (u32 I = 0; I < Size;) {
DCHECK_GE(BG->MaxCachedPerBatch, CurBatch->getCount());
- u16 UnusedSlots =
- static_cast<u16>(BG->MaxCachedPerBatch - CurBatch->getCount());
+ u16 UnusedSlots = BG->MaxCachedPerBatch - CurBatch->getCount();
if (UnusedSlots == 0) {
CurBatch = C->createBatch(ClassId, reinterpret_cast<void *>(
decompactPtr(ClassId, Array[I])));
More information about the llvm-commits
mailing list