diff --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/CMakeLists.txt --- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/CMakeLists.txt @@ -10,9 +10,6 @@ -g -nostdinc++) -# Too many existing bugs, needs cleanup. -append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format SCUDO_CFLAGS) - # Remove -stdlib= which is unused when passing -nostdinc++. string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) diff --git a/compiler-rt/lib/scudo/standalone/common.cpp b/compiler-rt/lib/scudo/standalone/common.cpp --- a/compiler-rt/lib/scudo/standalone/common.cpp +++ b/compiler-rt/lib/scudo/standalone/common.cpp @@ -27,7 +27,7 @@ if (SizeIfOOM) { formatString( Error, sizeof(Error), - "Scudo ERROR: internal map failure (NO MEMORY) requesting %zuKB\n", + "Scudo ERROR: internal map failure (NO MEMORY) requesting %luKB\n", SizeIfOOM >> 10); } outputRaw(Error); diff --git a/compiler-rt/lib/scudo/standalone/primary32.h b/compiler-rt/lib/scudo/standalone/primary32.h --- a/compiler-rt/lib/scudo/standalone/primary32.h +++ b/compiler-rt/lib/scudo/standalone/primary32.h @@ -193,8 +193,8 @@ PoppedBlocks += Sci->Stats.PoppedBlocks; PushedBlocks += Sci->Stats.PushedBlocks; } - Str->append("Stats: SizeClassAllocator32: %zuM mapped in %zu allocations; " - "remains %zu\n", + Str->append("Stats: SizeClassAllocator32: %luM mapped in %lu allocations; " + "remains %lu\n", TotalMapped >> 20, PoppedBlocks, PoppedBlocks - PushedBlocks); for (uptr I = 0; I < NumClasses; I++) getStats(Str, I, 0); @@ -415,8 +415,8 @@ return; const uptr InUse = Sci->Stats.PoppedBlocks - Sci->Stats.PushedBlocks; const uptr AvailableChunks = Sci->AllocatedUser / getSizeByClassId(ClassId); - Str->append(" %02zu (%6zu): mapped: %6zuK popped: %7zu pushed: %7zu " - "inuse: %6zu avail: %6zu rss: %6zuK releases: %6zu\n", + Str->append(" %02lu (%6lu): mapped: %6luK popped: %7lu pushed: %7lu " + "inuse: %6lu avail: %6lu rss: %6luK releases: %6lu\n", ClassId, getSizeByClassId(ClassId), Sci->AllocatedUser >> 10, Sci->Stats.PoppedBlocks, Sci->Stats.PushedBlocks, InUse, AvailableChunks, Rss >> 10, Sci->ReleaseInfo.RangesReleased); diff --git a/compiler-rt/lib/scudo/standalone/primary64.h b/compiler-rt/lib/scudo/standalone/primary64.h --- a/compiler-rt/lib/scudo/standalone/primary64.h +++ b/compiler-rt/lib/scudo/standalone/primary64.h @@ -164,9 +164,9 @@ PoppedBlocks += Region->Stats.PoppedBlocks; PushedBlocks += Region->Stats.PushedBlocks; } - Str->append("Stats: SizeClassAllocator64: %zuM mapped (%zuM rss) in %zu " - "allocations; remains %zu\n", - TotalMapped >> 20, 0, PoppedBlocks, + Str->append("Stats: SizeClassAllocator64: %luM mapped (%uM rss) in %lu " + "allocations; remains %lu\n", + TotalMapped >> 20, 0U, PoppedBlocks, PoppedBlocks - PushedBlocks); for (uptr I = 0; I < NumClasses; I++) @@ -348,7 +348,7 @@ ScopedString Str; getStats(&Str); Str.append( - "Scudo OOM: The process has exhausted %zuM for size class %zu.\n", + "Scudo OOM: The process has exhausted %luM for size class %lu.\n", RegionSize >> 20, Size); Str.output(); } @@ -413,9 +413,9 @@ return; const uptr InUse = Region->Stats.PoppedBlocks - Region->Stats.PushedBlocks; const uptr TotalChunks = Region->AllocatedUser / getSizeByClassId(ClassId); - Str->append("%s %02zu (%6zu): mapped: %6zuK popped: %7zu pushed: %7zu " - "inuse: %6zu total: %6zu rss: %6zuK releases: %6zu last " - "released: %6zuK region: 0x%zx (0x%zx)\n", + Str->append("%s %02lu (%6lu): mapped: %6luK popped: %7lu pushed: %7lu " + "inuse: %6lu total: %6lu rss: %6luK releases: %6lu last " + "released: %6luK region: 0x%lx (0x%lx)\n", Region->Exhausted ? "F" : " ", ClassId, getSizeByClassId(ClassId), Region->MappedUser >> 10, Region->Stats.PoppedBlocks, Region->Stats.PushedBlocks, InUse, diff --git a/compiler-rt/lib/scudo/standalone/quarantine.h b/compiler-rt/lib/scudo/standalone/quarantine.h --- a/compiler-rt/lib/scudo/standalone/quarantine.h +++ b/compiler-rt/lib/scudo/standalone/quarantine.h @@ -149,8 +149,8 @@ ? 0 : TotalOverheadBytes * 100 / TotalQuarantinedBytes; Str->append( - "Stats: Quarantine: batches: %zu; bytes: %zu (user: %zu); chunks: %zu " - "(capacity: %zu); %zu%% chunks used; %zu%% memory overhead\n", + "Stats: Quarantine: batches: %lu; bytes: %lu (user: %lu); chunks: %lu " + "(capacity: %lu); %lu%% chunks used; %lu%% memory overhead\n", BatchCount, TotalBytes, TotalQuarantinedBytes, TotalQuarantineChunks, QuarantineChunksCapacity, ChunksUsagePercent, MemoryOverheadPercent); } @@ -218,7 +218,7 @@ void getStats(ScopedString *Str) const { // It assumes that the world is stopped, just as the allocator's printStats. Cache.getStats(Str); - Str->append("Quarantine limits: global: %zuK; thread local: %zuK\n", + Str->append("Quarantine limits: global: %luK; thread local: %luK\n", getMaxSize() >> 10, getCacheSize() >> 10); } diff --git a/compiler-rt/lib/scudo/standalone/report.cpp b/compiler-rt/lib/scudo/standalone/report.cpp --- a/compiler-rt/lib/scudo/standalone/report.cpp +++ b/compiler-rt/lib/scudo/standalone/report.cpp @@ -86,8 +86,8 @@ // integer overflows, or unexpected corner cases. void NORETURN reportAlignmentTooBig(uptr Alignment, uptr MaxAlignment) { ScopedErrorReport Report; - Report.append("invalid allocation alignment: %zu exceeds maximum supported " - "alignment of %zu\n", + Report.append("invalid allocation alignment: %lu exceeds maximum supported " + "alignment of %lu\n", Alignment, MaxAlignment); } @@ -95,14 +95,14 @@ void NORETURN reportAllocationSizeTooBig(uptr UserSize, uptr TotalSize, uptr MaxSize) { ScopedErrorReport Report; - Report.append("requested allocation size %zu (%zu after adjustments) exceeds " - "maximum supported size of %zu\n", + Report.append("requested allocation size %lu (%lu after adjustments) exceeds " + "maximum supported size of %lu\n", UserSize, TotalSize, MaxSize); } void NORETURN reportOutOfMemory(uptr RequestedSize) { ScopedErrorReport Report; - Report.append("out of memory trying to allocate %zu bytes\n", RequestedSize); + Report.append("out of memory trying to allocate %lu bytes\n", RequestedSize); } static const char *stringifyAction(AllocatorAction Action) { @@ -148,20 +148,20 @@ uptr ExpectedSize) { ScopedErrorReport Report; Report.append( - "invalid sized delete when deallocating address %p (%zu vs %zu)\n", Ptr, + "invalid sized delete when deallocating address %p (%lu vs %lu)\n", Ptr, Size, ExpectedSize); } void NORETURN reportAlignmentNotPowerOfTwo(uptr Alignment) { ScopedErrorReport Report; Report.append( - "invalid allocation alignment: %zu, alignment must be a power of two\n", + "invalid allocation alignment: %lu, alignment must be a power of two\n", Alignment); } void NORETURN reportCallocOverflow(uptr Count, uptr Size) { ScopedErrorReport Report; - Report.append("calloc parameters overflow: count * size (%zu * %zu) cannot " + Report.append("calloc parameters overflow: count * size (%lu * %lu) cannot " "be represented with type size_t\n", Count, Size); } @@ -169,22 +169,22 @@ void NORETURN reportInvalidPosixMemalignAlignment(uptr Alignment) { ScopedErrorReport Report; Report.append( - "invalid alignment requested in posix_memalign: %zu, alignment must be a " + "invalid alignment requested in posix_memalign: %lu, alignment must be a " "power of two and a multiple of sizeof(void *) == %zu\n", Alignment, sizeof(void *)); } void NORETURN reportPvallocOverflow(uptr Size) { ScopedErrorReport Report; - Report.append("pvalloc parameters overflow: size %zu rounded up to system " - "page size %zu cannot be represented in type size_t\n", + Report.append("pvalloc parameters overflow: size %lu rounded up to system " + "page size %lu cannot be represented in type size_t\n", Size, getPageSizeCached()); } void NORETURN reportInvalidAlignedAllocAlignment(uptr Alignment, uptr Size) { ScopedErrorReport Report; - Report.append("invalid alignment requested in aligned_alloc: %zu, alignment " - "must be a power of two and the requested size %zu must be a " + Report.append("invalid alignment requested in aligned_alloc: %lu, alignment " + "must be a power of two and the requested size %lu must be a " "multiple of alignment\n", Alignment, Size); } diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h --- a/compiler-rt/lib/scudo/standalone/secondary.h +++ b/compiler-rt/lib/scudo/standalone/secondary.h @@ -602,12 +602,11 @@ template void MapAllocator::getStats(ScopedString *Str) const { - Str->append( - "Stats: MapAllocator: allocated %zu times (%zuK), freed %zu times " - "(%zuK), remains %zu (%zuK) max %zuM\n", - NumberOfAllocs, AllocatedBytes >> 10, NumberOfFrees, FreedBytes >> 10, - NumberOfAllocs - NumberOfFrees, (AllocatedBytes - FreedBytes) >> 10, - LargestSize >> 20); + Str->append("Stats: MapAllocator: allocated %u times (%luK), freed %u times " + "(%luK), remains %u (%luK) max %luM\n", + NumberOfAllocs, AllocatedBytes >> 10, NumberOfFrees, + FreedBytes >> 10, NumberOfAllocs - NumberOfFrees, + (AllocatedBytes - FreedBytes) >> 10, LargestSize >> 20); } } // namespace scudo diff --git a/compiler-rt/lib/scudo/standalone/size_class_map.h b/compiler-rt/lib/scudo/standalone/size_class_map.h --- a/compiler-rt/lib/scudo/standalone/size_class_map.h +++ b/compiler-rt/lib/scudo/standalone/size_class_map.h @@ -335,13 +335,13 @@ const uptr L = S ? getMostSignificantSetBitIndex(S) : 0; const uptr Cached = SCMap::getMaxCachedHint(S) * S; Buffer.append( - "C%02zu => S: %zu diff: +%zu %02zu%% L %zu Cached: %zu %zu; id %zu\n", - I, S, D, P, L, SCMap::getMaxCachedHint(S), Cached, + "C%02lu => S: %lu diff: +%lu %02lu%% L %lu Cached: %u %lu; id %lu\n", I, + S, D, P, L, SCMap::getMaxCachedHint(S), Cached, SCMap::getClassIdBySize(S)); TotalCached += Cached; PrevS = S; } - Buffer.append("Total Cached: %zu\n", TotalCached); + Buffer.append("Total Cached: %lu\n", TotalCached); Buffer.output(); } diff --git a/compiler-rt/lib/scudo/standalone/string_utils.cpp b/compiler-rt/lib/scudo/standalone/string_utils.cpp --- a/compiler-rt/lib/scudo/standalone/string_utils.cpp +++ b/compiler-rt/lib/scudo/standalone/string_utils.cpp @@ -118,7 +118,7 @@ static int formatString(char *Buffer, uptr BufferLength, const char *Format, va_list Args) { static const char *PrintfFormatsHelp = - "Supported formatString formats: %([0-9]*)?(z|ll)?{d,u,x,X}; %p; " + "Supported formatString formats: %([0-9]*)?(z|l|ll)?{d,u,x,X}; %p; " "%[-]([0-9]*)?(\\.\\*)?s; %c\n"; RAW_CHECK(Format); RAW_CHECK(BufferLength > 0); @@ -149,28 +149,30 @@ } const bool HaveZ = (*Cur == 'z'); Cur += HaveZ; - const bool HaveLL = !HaveZ && (Cur[0] == 'l' && Cur[1] == 'l'); + const bool HaveL = !HaveZ && (Cur[0] == 'l' && Cur[1] != 'l'); + Cur += HaveL; + const bool HaveLL = !HaveZ && !HaveL && (Cur[0] == 'l' && Cur[1] == 'l'); Cur += HaveLL * 2; s64 DVal; u64 UVal; - const bool HaveLength = HaveZ || HaveLL; + const bool HaveLength = HaveZ || HaveL || HaveLL; const bool HaveFlags = HaveWidth || HaveLength; // At the moment only %s supports precision and left-justification. CHECK(!((Precision >= 0 || LeftJustified) && *Cur != 's')); switch (*Cur) { case 'd': { - DVal = HaveLL ? va_arg(Args, s64) - : HaveZ ? va_arg(Args, sptr) - : va_arg(Args, int); + DVal = HaveLL ? va_arg(Args, s64) + : (HaveZ || HaveL) ? va_arg(Args, sptr) + : va_arg(Args, int); Res += appendSignedDecimal(&Buffer, BufferEnd, DVal, Width, PadWithZero); break; } case 'u': case 'x': case 'X': { - UVal = HaveLL ? va_arg(Args, u64) - : HaveZ ? va_arg(Args, uptr) - : va_arg(Args, unsigned); + UVal = HaveLL ? va_arg(Args, u64) + : (HaveZ || HaveL) ? va_arg(Args, uptr) + : va_arg(Args, unsigned); const bool Upper = (*Cur == 'X'); Res += appendUnsigned(&Buffer, BufferEnd, UVal, (*Cur == 'u') ? 10 : 16, Width, PadWithZero, Upper); diff --git a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt --- a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt @@ -17,9 +17,6 @@ # TODO(kostyak): find a way to make -fsized-deallocation work -Wno-mismatched-new-delete) -# Too many existing bugs, needs cleanup. -append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format SCUDO_UNITTEST_CFLAGS) - if(COMPILER_RT_DEBUG) list(APPEND SCUDO_UNITTEST_CFLAGS -DSCUDO_DEBUG=1) endif() diff --git a/compiler-rt/lib/scudo/standalone/tests/strings_test.cpp b/compiler-rt/lib/scudo/standalone/tests/strings_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/strings_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/strings_test.cpp @@ -20,7 +20,7 @@ TEST(ScudoStringsTest, Basic) { scudo::ScopedString Str; - Str.append("a%db%zdc%ue%zuf%xh%zxq%pe%sr", static_cast(-1), + Str.append("a%db%ldc%ue%luf%xh%lxq%pe%sr", static_cast(-1), static_cast(-2), static_cast(-4), static_cast(5), static_cast(10), static_cast(11), reinterpret_cast(0x123),