[PATCH] D39597: [Support][Chrono] Use explicit cast of text output of time values.

Simon Dardis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 3 07:19:27 PDT 2017


sdardis created this revision.
Herald added a subscriber: arichardson.

https://reviews.llvm.org/rL316419 exposed a platform specific issue where the type of the values
passed to llvm::format could be different to the format string.

Debian unstable for mips uses long long int for std::chrono:duration,
while x86_64 uses long int.

For mips, this resulted in the value being corrupted when rendered to a
string. Address this by explicitly casting the result of the duration_cast
to the type specified in the format string.


Repository:
  rL LLVM

https://reviews.llvm.org/D39597

Files:
  lib/Support/Chrono.cpp


Index: lib/Support/Chrono.cpp
===================================================================
--- lib/Support/Chrono.cpp
+++ lib/Support/Chrono.cpp
@@ -65,17 +65,17 @@
     if (Style[I] == '%' && Style.size() > I + 1) switch (Style[I + 1]) {
         case 'L':  // Milliseconds, from Ruby.
           FStream << llvm::format(
-              "%.3lu", duration_cast<milliseconds>(Fractional).count());
+              "%.3lu", (long)duration_cast<milliseconds>(Fractional).count());
           ++I;
           continue;
         case 'f':  // Microseconds, from Python.
           FStream << llvm::format(
-              "%.6lu", duration_cast<microseconds>(Fractional).count());
+              "%.6lu", (long)duration_cast<microseconds>(Fractional).count());
           ++I;
           continue;
         case 'N':  // Nanoseconds, from date(1).
           FStream << llvm::format(
-              "%.6lu", duration_cast<nanoseconds>(Fractional).count());
+              "%.6lu", (long)duration_cast<nanoseconds>(Fractional).count());
           ++I;
           continue;
         case '%':  // Consume %%, so %%f parses as (%%)f not %(%f)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39597.121473.patch
Type: text/x-patch
Size: 1141 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171103/c0f6c716/attachment.bin>


More information about the llvm-commits mailing list