[libcxx-commits] [PATCH] D93456: [libcxx] Avoid overflows in the windows __libcpp_steady_clock_now()
Martin Storsjö via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jan 12 14:00:00 PST 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG02f1d28ed6b8: [libcxx] Avoid overflows in the windows __libcpp_steady_clock_now() (authored by mstorsjo).
Changed prior to commit:
https://reviews.llvm.org/D93456?vs=312472&id=316232#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93456/new/
https://reviews.llvm.org/D93456
Files:
libcxx/src/chrono.cpp
libcxx/test/std/utilities/time/time.clock/time.clock.steady/now.pass.cpp
Index: libcxx/test/std/utilities/time/time.clock/time.clock.steady/now.pass.cpp
===================================================================
--- libcxx/test/std/utilities/time/time.clock/time.clock.steady/now.pass.cpp
+++ libcxx/test/std/utilities/time/time.clock/time.clock.steady/now.pass.cpp
@@ -25,6 +25,8 @@
C::time_point t1 = C::now();
C::time_point t2 = C::now();
assert(t2 >= t1);
+ // make sure t2 didn't wrap around
+ assert(t2 > std::chrono::time_point<C>());
return 0;
}
Index: libcxx/src/chrono.cpp
===================================================================
--- libcxx/src/chrono.cpp
+++ libcxx/src/chrono.cpp
@@ -153,7 +153,10 @@
LARGE_INTEGER counter;
(void) QueryPerformanceCounter(&counter);
- return steady_clock::time_point(steady_clock::duration(counter.QuadPart * nano::den / freq.QuadPart));
+ auto seconds = counter.QuadPart / freq.QuadPart;
+ auto fractions = counter.QuadPart % freq.QuadPart;
+ auto dur = seconds * nano::den + fractions * nano::den / freq.QuadPart;
+ return steady_clock::time_point(steady_clock::duration(dur));
}
#elif defined(CLOCK_MONOTONIC)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93456.316232.patch
Type: text/x-patch
Size: 1149 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210112/409ba1c7/attachment-0001.bin>
More information about the libcxx-commits
mailing list