[libcxx-commits] [libcxx] 99f3b23 - [libc++] Workaround timespec_get not always being available in Apple SDKs

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 1 12:11:00 PDT 2020


Author: Louis Dionne
Date: 2020-09-01T15:10:50-04:00
New Revision: 99f3b231cb21abc567c93813650cd76cfa614325

URL: https://github.com/llvm/llvm-project/commit/99f3b231cb21abc567c93813650cd76cfa614325
DIFF: https://github.com/llvm/llvm-project/commit/99f3b231cb21abc567c93813650cd76cfa614325.diff

LOG: [libc++] Workaround timespec_get not always being available in Apple SDKs

timespec_get is not available in Apple SDKs when (__DARWIN_C_LEVEL >= __DARWIN_C_FULL)
isn't true, which leads to libc++ trying to import ::timespec_get into
namespace std when it's not available. This issue has been reported to
Apple's libc, but we need a workaround in the meantime.

https://llvm.org/PR47208
rdar://68157284

Added: 
    libcxx/test/libcxx/language.support/timespec_get.xopen.compile.pass.cpp

Modified: 
    libcxx/include/__config

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__config b/libcxx/include/__config
index d7b6a2acaeff..d734c10cd8ed 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -388,7 +388,14 @@
          __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 130000 || \
          __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 60000)
 #      define _LIBCPP_HAS_ALIGNED_ALLOC
-#      define _LIBCPP_HAS_TIMESPEC_GET
+       // TODO: Apple SDKs don't define ::timespec_get unconditionally in C++
+       //       mode. This should be fixed in future SDKs, but for the time
+       //       being we need to avoid trying to use that declaration when
+       //       the SDK doesn't provide it.
+#      include <sys/cdefs.h>
+#      if (__DARWIN_C_LEVEL >= __DARWIN_C_FULL)
+#        define _LIBCPP_HAS_TIMESPEC_GET
+#      endif
 #    endif
 #  endif // __APPLE__
 #endif

diff  --git a/libcxx/test/libcxx/language.support/timespec_get.xopen.compile.pass.cpp b/libcxx/test/libcxx/language.support/timespec_get.xopen.compile.pass.cpp
new file mode 100644
index 000000000000..cf4c5957a418
--- /dev/null
+++ b/libcxx/test/libcxx/language.support/timespec_get.xopen.compile.pass.cpp
@@ -0,0 +1,18 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+// Make sure that <ctime> can be included even when _XOPEN_SOURCE is defined.
+// This used to trigger some bug in Apple SDKs, since timespec_get was not
+// defined in <time.h> but we tried using it from <ctime>.
+// See https://llvm.org/PR47208 for details.
+
+// ADDITIONAL_COMPILE_FLAGS: -D_XOPEN_SOURCE=500
+
+#include <ctime>


        


More information about the libcxx-commits mailing list