[llvm-bugs] [Bug 43703] New: std::steady_clock::now() frequently overflows on Windows
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Oct 17 10:20:01 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=43703
Bug ID: 43703
Summary: std::steady_clock::now() frequently overflows on
Windows
Product: libc++
Version: unspecified
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: stevebe at microsoft.com
CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
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));
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191017/8f8745bf/attachment.html>
More information about the llvm-bugs
mailing list