[compiler-rt] 3ead26e - [scudo] Fix implicitly narrow casting (NFC)
Chia-hung Duan via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 14 20:55:17 PDT 2022
Author: Chia-hung Duan
Date: 2022-10-15T03:54:53Z
New Revision: 3ead26e65bab612e6aead979646b40c6c15d9ba6
URL: https://github.com/llvm/llvm-project/commit/3ead26e65bab612e6aead979646b40c6c15d9ba6
DIFF: https://github.com/llvm/llvm-project/commit/3ead26e65bab612e6aead979646b40c6c15d9ba6.diff
LOG: [scudo] Fix implicitly narrow casting (NFC)
u16 may be promoted to int by arithmetic type conversion. Do an explicit
cast to avoid certain compiler's warning. This fixes the problem
introduced by 0fb2aeef5310eaba2915b30810464a744a80da15
Differential Revision: https://reviews.llvm.org/D135985
Added:
Modified:
compiler-rt/lib/scudo/standalone/local_cache.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/local_cache.h b/compiler-rt/lib/scudo/standalone/local_cache.h
index dfdea00529c7d..b36ec8fab981d 100644
--- a/compiler-rt/lib/scudo/standalone/local_cache.h
+++ b/compiler-rt/lib/scudo/standalone/local_cache.h
@@ -151,7 +151,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 = 2 * TransferBatch::getMaxCached(Size);
+ P->MaxCount = static_cast<u16>(2 * TransferBatch::getMaxCached(Size));
if (I != BatchClassId) {
P->ClassSize = Size;
} else {
@@ -187,8 +187,9 @@ template <class SizeClassAllocator> struct SizeClassAllocatorLocalCache {
if (UNLIKELY(!B))
reportOutOfMemory(SizeClassAllocator::getSizeByClassId(BatchClassId));
B->setFromArray(&C->Chunks[0], Count);
- C->Count -= Count;
- for (uptr I = 0; I < C->Count; I++)
+ // u16 will be promoted to int by arithmetic type conversion.
+ C->Count = static_cast<u16>(C->Count - Count);
+ for (u16 I = 0; I < C->Count; I++)
C->Chunks[I] = C->Chunks[I + Count];
Allocator->pushBatch(ClassId, B);
}
More information about the llvm-commits
mailing list