[libcxx-commits] [PATCH] D88825: [libc++] Check _LIBCPP_USE_CLOCK_GETTIME before using clock_gettime

Hafiz Abid Qadeer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 5 04:52:13 PDT 2020


abidh created this revision.
abidh added reviewers: libc++, ldionne.
Herald added subscribers: libcxx-commits, dexonsmith.
Herald added a project: libc++.
abidh requested review of this revision.

[libc++] Check _LIBCPP_USE_CLOCK_GETTIME before using clock_gettime

The clock_gettime function is available when _POSIX_TIMERS is defined.
We check for this and set _LIBCPP_USE_CLOCK_GETTIME accordingly since
59b3102739c <https://reviews.llvm.org/rG59b3102739c5988c9fc7ea77888de1bc8ce9c8ab>. But check for _LIBCPP_USE_CLOCK_GETTIME was removed in
babd3aefc91 <https://reviews.llvm.org/rGbabd3aefc9193b44ad0620a2cfd63ebb6ad7e952>. As a result, code is now trying to use clock_gettime even
on platform where it is not available and it is causing build failure with newlib

This patch restores the checks to fix this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88825

Files:
  libcxx/src/chrono.cpp


Index: libcxx/src/chrono.cpp
===================================================================
--- libcxx/src/chrono.cpp
+++ libcxx/src/chrono.cpp
@@ -28,7 +28,7 @@
 #    include <winapifamily.h>
 #  endif
 #else
-#  if !defined(CLOCK_REALTIME)
+#  if !defined(CLOCK_REALTIME) || !defined(_LIBCPP_USE_CLOCK_GETTIME)
 #    include <sys/time.h>        // for gettimeofday and timeval
 #  endif // !defined(CLOCK_REALTIME)
 #endif // defined(_LIBCPP_WIN32API)
@@ -74,7 +74,7 @@
                        static_cast<__int64>(ft.dwLowDateTime)};
   return time_point(duration_cast<duration>(d - nt_to_unix_epoch));
 #else
-#if defined(CLOCK_REALTIME)
+#if defined(CLOCK_REALTIME) && defined(_LIBCPP_USE_CLOCK_GETTIME)
   struct timespec tp;
   if (0 != clock_gettime(CLOCK_REALTIME, &tp))
     __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88825.296155.patch
Type: text/x-patch
Size: 859 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201005/ad4d5f60/attachment.bin>


More information about the libcxx-commits mailing list