From 812a9061338dad80a3e9725db95f67590bc54dcd Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Fri, 26 Feb 2021 14:32:01 -0800 Subject: [PATCH] [sanitizers][NFC] Change typesto avoid warnings Warning was enabled by D94640 --- .../sanitizer_allocator_primary64.h | 12 ++++----- .../tests/sanitizer_allocator_test.cpp | 25 ++++++++++--------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h index 26e70df77218..26753b6c8aeb 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary64.h @@ -371,8 +371,7 @@ class SizeClassAllocator64 { } ~PackedCounterArray() { if (buffer) { - memory_mapper->UnmapPackedCounterArrayBuffer( - reinterpret_cast(buffer), buffer_size); + memory_mapper->UnmapPackedCounterArrayBuffer(buffer, buffer_size); } } @@ -803,17 +802,16 @@ class SizeClassAllocator64 { return released_bytes; } - uptr MapPackedCounterArrayBuffer(uptr buffer_size) { + void *MapPackedCounterArrayBuffer(uptr buffer_size) { // TODO(alekseyshl): The idea to explore is to check if we have enough // space between num_freed_chunks*sizeof(CompactPtrT) and // mapped_free_array to fit buffer_size bytes and use that space instead // of mapping a temporary one. - return reinterpret_cast( - MmapOrDieOnFatalError(buffer_size, "ReleaseToOSPageCounters")); + return MmapOrDieOnFatalError(buffer_size, "ReleaseToOSPageCounters"); } - void UnmapPackedCounterArrayBuffer(uptr buffer, uptr buffer_size) { - UnmapOrDie(reinterpret_cast(buffer), buffer_size); + void UnmapPackedCounterArrayBuffer(void *buffer, uptr buffer_size) { + UnmapOrDie(buffer, buffer_size); } // Releases [from, to) range of pages back to OS. diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp index 26593c0c2f49..590e477678ea 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cpp @@ -1081,11 +1081,11 @@ class NoMemoryMapper { NoMemoryMapper() : last_request_buffer_size(0) {} - uptr MapPackedCounterArrayBuffer(uptr buffer_size) { + void *MapPackedCounterArrayBuffer(uptr buffer_size) { last_request_buffer_size = buffer_size; - return 0; + return nullptr; } - void UnmapPackedCounterArrayBuffer(uptr buffer, uptr buffer_size) {} + void UnmapPackedCounterArrayBuffer(void *buffer, uptr buffer_size) {} }; class RedZoneMemoryMapper { @@ -1100,14 +1100,15 @@ class RedZoneMemoryMapper { UnmapOrDie(buffer, 3 * GetPageSize()); } - uptr MapPackedCounterArrayBuffer(uptr buffer_size) { + void *MapPackedCounterArrayBuffer(uptr buffer_size) { const auto page_size = GetPageSize(); CHECK_EQ(buffer_size, page_size); - memset(reinterpret_cast(reinterpret_cast(buffer) + page_size), - 0, page_size); - return reinterpret_cast(buffer) + page_size; + void *p = + reinterpret_cast(reinterpret_cast(buffer) + page_size); + memset(p, 0, page_size); + return p; } - void UnmapPackedCounterArrayBuffer(uptr buffer, uptr buffer_size) {} + void UnmapPackedCounterArrayBuffer(void *buffer, uptr buffer_size) {} private: void *buffer; @@ -1227,12 +1228,12 @@ class ReleasedPagesTrackingMemoryMapper { public: std::set reported_pages; - uptr MapPackedCounterArrayBuffer(uptr buffer_size) { + void *MapPackedCounterArrayBuffer(uptr buffer_size) { reported_pages.clear(); - return reinterpret_cast(calloc(1, buffer_size)); + return calloc(1, buffer_size); } - void UnmapPackedCounterArrayBuffer(uptr buffer, uptr buffer_size) { - free(reinterpret_cast(buffer)); + void UnmapPackedCounterArrayBuffer(void *buffer, uptr buffer_size) { + free(buffer); } void ReleasePageRangeToOS(u32 from, u32 to) {