[libcxx-commits] [libcxx] 5201b96 - [libc++] Re-apply the workaround for timespec_get not always being available in Apple SDKs
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Sep 2 09:21:30 PDT 2020
Author: Louis Dionne
Date: 2020-09-02T12:20:32-04:00
New Revision: 5201b962e8956b75dffd2167e278b8627981c90b
URL: https://github.com/llvm/llvm-project/commit/5201b962e8956b75dffd2167e278b8627981c90b
DIFF: https://github.com/llvm/llvm-project/commit/5201b962e8956b75dffd2167e278b8627981c90b.diff
LOG: [libc++] Re-apply the workaround for timespec_get not always being available in Apple SDKs
This commit re-applies 99f3b231cb21, which was reverted in 814242572731
because it broke the modules build. The modules failure was a circular
dependency between the Darwin module and __config. Specifically, the
issue was that if <__config> includes a system header, the std_config
module depends on the Darwin module. However, the Darwin module already
depends on the std_config header because some of its headers include
libc++ headers like <ctype.h> (they mean to include the C <ctype.h>,
but libc++ headers are first in the header search path).
This is fixed by moving the workaround to <ctime> only.
https://llvm.org/PR47208
rdar://68157284
Added:
libcxx/test/libcxx/language.support/timespec_get.xopen.compile.pass.cpp
Modified:
libcxx/include/ctime
Removed:
################################################################################
diff --git a/libcxx/include/ctime b/libcxx/include/ctime
index f9f2f1659d0e..3aa619daa358 100644
--- a/libcxx/include/ctime
+++ b/libcxx/include/ctime
@@ -52,6 +52,18 @@ int timespec_get( struct timespec *ts, int base); // C++17
#pragma GCC system_header
#endif
+// FIXME:
+// 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. Note that
+// we're detecting this here instead of in <__config> because we can't include
+// system headers from <__config>, since it leads to circular module dependencies.
+// This is also meant to be a very temporary workaround until the SDKs are fixed.
+#include <sys/cdefs.h>
+#if defined(__APPLE__) && defined(_LIBCPP_HAS_TIMESPEC_GET) && (__DARWIN_C_LEVEL < __DARWIN_C_FULL)
+# define _LIBCPP_HAS_TIMESPEC_GET_NOT_ACTUALLY_PROVIDED
+#endif
+
_LIBCPP_BEGIN_NAMESPACE_STD
using ::clock_t;
@@ -72,7 +84,7 @@ using ::gmtime;
using ::localtime;
#endif
using ::strftime;
-#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET)
+#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET) && !defined(_LIBCPP_HAS_TIMESPEC_GET_NOT_ACTUALLY_PROVIDED)
using ::timespec_get;
#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