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: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
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._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs