<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - std::steady_clock::now() frequently overflows on Windows"
   href="https://bugs.llvm.org/show_bug.cgi?id=43703">43703</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>std::steady_clock::now() frequently overflows on Windows
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>stevebe@microsoft.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>std::steady_clock::now() multiplies the result from QueryPerformanceCounter()
by nano::den (10^9), which frequently overflows, producing a negative int64_t
value.  libc++ should perform this calculation more carefully to avoid
overflow.

Current implementation:

  return time_point(duration(counter.QuadPart * nano::den / freq.QuadPart));

Proposed fixed implementation:

  const auto first_part = 
    (counter.QuadPart / freq.QuadPart) * nano::den;

  const auto second_part = 
    (counter.QuadPart % freq.QuadPart) * nano::den / freq.QuadPart;

  return time_point(duration(first_part + second_part));</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>