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 @@ -85,9 +85,7 @@ stack_depot.h stats.h string_utils.h - # TODO(chiahungduan): Temporarily disable the timer because of the print - # of u64 has incorrect placeholder. - # timing.h + timing.h tsd_exclusive.h tsd_shared.h tsd.h @@ -110,9 +108,7 @@ report.cpp rss_limit_checker.cpp string_utils.cpp - # TODO(chiahungduan): Temporarily disable the timer because of the print - # of u64 has incorrect placeholder. - # timing.cpp + timing.cpp ) # Enable the necessary instruction set for scudo_crc32.cpp, if available. 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 @@ -195,6 +195,28 @@ appendChar(&Buffer, BufferEnd, static_cast(va_arg(Args, int))); break; } + // In Scudo, `s64`/`u64` are supposed to use `lld` and `llu` respectively. + // However, `-Wformat` doesn't know we have a different parser for those + // placeholders and it keeps complaining the type mismatch on 64-bit + // platform which uses `ld`/`lu` for `s64`/`u64`. Therefore, in order to + // silence the warning, we turn to use `PRId64`/`PRIu64` for printing + // `s64`/`u64` and handle the `ld`/`lu` here. + case 'l': { + ++Cur; + RAW_CHECK(*Cur == 'd' || *Cur == 'u'); + + if (*Cur == 'd') { + DVal = va_arg(Args, s64); + Res += + appendSignedDecimal(&Buffer, BufferEnd, DVal, Width, PadWithZero); + } else { + UVal = va_arg(Args, u64); + Res += appendUnsigned(&Buffer, BufferEnd, UVal, 10, Width, PadWithZero, + false); + } + + break; + } case '%': { RAW_CHECK_MSG(!HaveFlags, PrintfFormatsHelp); Res += appendChar(&Buffer, BufferEnd, '%'); 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 @@ -105,9 +105,7 @@ size_class_map_test.cpp stats_test.cpp strings_test.cpp - # TODO(chiahungduan): Temporarily disable the timer test because of the print - # of u64 has incorrect placeholder. - # timing_test.cpp + timing_test.cpp tsd_test.cpp vector_test.cpp scudo_unit_test_main.cpp diff --git a/compiler-rt/lib/scudo/standalone/timing.h b/compiler-rt/lib/scudo/standalone/timing.h --- a/compiler-rt/lib/scudo/standalone/timing.h +++ b/compiler-rt/lib/scudo/standalone/timing.h @@ -14,6 +14,7 @@ #include "string_utils.h" #include "thread_annotations.h" +#include #include namespace scudo { @@ -178,11 +179,11 @@ Occurrence == 0 ? 0 : ((AccumulatedTime % Occurrence) * 10) / Occurrence; - Str.append("%14lu.%lu(ns) %-11s", Integral, Fraction, " "); + Str.append("%14" PRId64 ".%" PRId64 "(ns) %-11s", Integral, Fraction, " "); for (u32 I = 0; I < ExtraIndent; ++I) Str.append("%s", " "); - Str.append("%s (%lu)\n", Timers[HandleId].Name, Occurrence); + Str.append("%s (%" PRId64 ")\n", Timers[HandleId].Name, Occurrence); for (u32 I = 0; I < NumAllocatedTimers; ++I) if (Timers[I].Nesting == HandleId)