[compiler-rt] a2cee05 - [scudo] Make report pointers const. (#144624)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 18 09:12:57 PDT 2025
Author: Christopher Ferris
Date: 2025-06-18T09:12:53-07:00
New Revision: a2cee05449636c8e0d630b2ccdc71f2d422227a9
URL: https://github.com/llvm/llvm-project/commit/a2cee05449636c8e0d630b2ccdc71f2d422227a9
DIFF: https://github.com/llvm/llvm-project/commit/a2cee05449636c8e0d630b2ccdc71f2d422227a9.diff
LOG: [scudo] Make report pointers const. (#144624)
Mark as many of the reportXX functions that take pointers const. This
avoid the need to use const_cast when calling these functions on an
already const pointer.
Fix reportHeaderCorruption calls where an argument was passed into an
append call that didn't use them.
Added:
Modified:
compiler-rt/lib/scudo/standalone/chunk.h
compiler-rt/lib/scudo/standalone/combined.h
compiler-rt/lib/scudo/standalone/report.cpp
compiler-rt/lib/scudo/standalone/report.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/chunk.h b/compiler-rt/lib/scudo/standalone/chunk.h
index a1b8e723d4cb5..9da2dc57e71a1 100644
--- a/compiler-rt/lib/scudo/standalone/chunk.h
+++ b/compiler-rt/lib/scudo/standalone/chunk.h
@@ -125,7 +125,7 @@ inline void loadHeader(u32 Cookie, const void *Ptr,
*NewUnpackedHeader = bit_cast<UnpackedHeader>(NewPackedHeader);
if (UNLIKELY(NewUnpackedHeader->Checksum !=
computeHeaderChecksum(Cookie, Ptr, NewUnpackedHeader)))
- reportHeaderCorruption(NewUnpackedHeader, const_cast<void *>(Ptr));
+ reportHeaderCorruption(NewUnpackedHeader, Ptr);
}
inline bool isValid(u32 Cookie, const void *Ptr,
diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index 43655642843cb..87acdec2a3bac 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -775,7 +775,7 @@ class Allocator {
// Getting the alloc size of a chunk only makes sense if it's allocated.
if (UNLIKELY(Header.State != Chunk::State::Allocated))
- reportInvalidChunkState(AllocatorAction::Sizing, const_cast<void *>(Ptr));
+ reportInvalidChunkState(AllocatorAction::Sizing, Ptr);
return getSize(Ptr, &Header);
}
diff --git a/compiler-rt/lib/scudo/standalone/report.cpp b/compiler-rt/lib/scudo/standalone/report.cpp
index 14a4066d37200..b97a74b078c2f 100644
--- a/compiler-rt/lib/scudo/standalone/report.cpp
+++ b/compiler-rt/lib/scudo/standalone/report.cpp
@@ -66,17 +66,16 @@ void NORETURN reportInvalidFlag(const char *FlagType, const char *Value) {
// The checksum of a chunk header is invalid. This could be caused by an
// {over,under}write of the header, a pointer that is not an actual chunk.
-void NORETURN reportHeaderCorruption(void *Header, void *Ptr) {
+void NORETURN reportHeaderCorruption(void *Header, const void *Ptr) {
ScopedErrorReport Report;
Report.append("corrupted chunk header at address %p", Ptr);
if (*static_cast<Chunk::PackedHeader *>(Header) == 0U) {
// Header all zero, which could indicate that this might be a pointer that
// has been double freed but the memory has been released to the kernel.
Report.append(": chunk header is zero and might indicate memory corruption "
- "or a double free\n",
- Ptr);
+ "or a double free\n");
} else {
- Report.append(": most likely due to memory corruption\n", Ptr);
+ Report.append(": most likely due to memory corruption\n");
}
}
@@ -131,13 +130,13 @@ static const char *stringifyAction(AllocatorAction Action) {
// The chunk is not in a state congruent with the operation we want to perform.
// This is usually the case with a double-free, a realloc of a freed pointer.
-void NORETURN reportInvalidChunkState(AllocatorAction Action, void *Ptr) {
+void NORETURN reportInvalidChunkState(AllocatorAction Action, const void *Ptr) {
ScopedErrorReport Report;
Report.append("invalid chunk state when %s address %p\n",
stringifyAction(Action), Ptr);
}
-void NORETURN reportMisalignedPointer(AllocatorAction Action, void *Ptr) {
+void NORETURN reportMisalignedPointer(AllocatorAction Action, const void *Ptr) {
ScopedErrorReport Report;
Report.append("misaligned pointer when %s address %p\n",
stringifyAction(Action), Ptr);
@@ -145,7 +144,7 @@ void NORETURN reportMisalignedPointer(AllocatorAction Action, void *Ptr) {
// The deallocation function used is at odds with the one used to allocate the
// chunk (eg: new[]/delete or malloc/delete, and so on).
-void NORETURN reportDeallocTypeMismatch(AllocatorAction Action, void *Ptr,
+void NORETURN reportDeallocTypeMismatch(AllocatorAction Action, const void *Ptr,
u8 TypeA, u8 TypeB) {
ScopedErrorReport Report;
Report.append("allocation type mismatch when %s address %p (%d vs %d)\n",
@@ -154,7 +153,7 @@ void NORETURN reportDeallocTypeMismatch(AllocatorAction Action, void *Ptr,
// The size specified to the delete operator does not match the one that was
// passed to new when allocating the chunk.
-void NORETURN reportDeleteSizeMismatch(void *Ptr, uptr Size,
+void NORETURN reportDeleteSizeMismatch(const void *Ptr, uptr Size,
uptr ExpectedSize) {
ScopedErrorReport Report;
Report.append(
diff --git a/compiler-rt/lib/scudo/standalone/report.h b/compiler-rt/lib/scudo/standalone/report.h
index c0214b51560e9..c397dd3fc9c65 100644
--- a/compiler-rt/lib/scudo/standalone/report.h
+++ b/compiler-rt/lib/scudo/standalone/report.h
@@ -24,7 +24,7 @@ void NORETURN reportRawError(const char *Message);
void NORETURN reportInvalidFlag(const char *FlagType, const char *Value);
// Chunk header related errors.
-void NORETURN reportHeaderCorruption(void *Header, void *Ptr);
+void NORETURN reportHeaderCorruption(void *Header, const void *Ptr);
// Sanity checks related error.
void NORETURN reportSanityCheckError(const char *Field);
@@ -41,11 +41,12 @@ enum class AllocatorAction : u8 {
Reallocating,
Sizing,
};
-void NORETURN reportInvalidChunkState(AllocatorAction Action, void *Ptr);
-void NORETURN reportMisalignedPointer(AllocatorAction Action, void *Ptr);
-void NORETURN reportDeallocTypeMismatch(AllocatorAction Action, void *Ptr,
+void NORETURN reportInvalidChunkState(AllocatorAction Action, const void *Ptr);
+void NORETURN reportMisalignedPointer(AllocatorAction Action, const void *Ptr);
+void NORETURN reportDeallocTypeMismatch(AllocatorAction Action, const void *Ptr,
u8 TypeA, u8 TypeB);
-void NORETURN reportDeleteSizeMismatch(void *Ptr, uptr Size, uptr ExpectedSize);
+void NORETURN reportDeleteSizeMismatch(const void *Ptr, uptr Size,
+ uptr ExpectedSize);
// C wrappers errors.
void NORETURN reportAlignmentNotPowerOfTwo(uptr Alignment);
More information about the llvm-commits
mailing list