[libcxx-commits] [libcxx] ebc01bb - [libc++] Skip logic for detecting C11 features when using_if_exists is supported

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 18 08:53:44 PDT 2021


Author: Louis Dionne
Date: 2021-08-18T11:53:34-04:00
New Revision: ebc01bbc7a6758743e6383af34619ef1423afa15

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

LOG: [libc++] Skip logic for detecting C11 features when using_if_exists is supported

In the future, we'll want to rely exclusively on using_if_exists for this
job, but for now, only rely on it when the compiler supports that attribute.
That removes the possibility for getting the logic wrong.

Differential Revision: https://reviews.llvm.org/D108297

Added: 
    

Modified: 
    libcxx/include/__config
    libcxx/include/ctime

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__config b/libcxx/include/__config
index 0f2a23163414..740106ce8d5a 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -354,6 +354,16 @@
 #  define _LIBCPP_NO_CFI
 #endif
 
+// If the compiler supports using_if_exists, pretend we have those functions and they'll
+// be picked up if the C library provides them.
+//
+// TODO: Once we drop support for Clang 12, we can assume the compiler supports using_if_exists
+//       for platforms that don't have a conforming C11 library, so we can drop this whole thing.
+#if __has_attribute(using_if_exists)
+# define _LIBCPP_HAS_TIMESPEC_GET
+# define _LIBCPP_HAS_QUICK_EXIT
+# define _LIBCPP_HAS_ALIGNED_ALLOC
+#else
 #if (defined(__ISO_C_VISIBLE) && (__ISO_C_VISIBLE >= 2011)) || __cplusplus >= 201103L
 #  if defined(__FreeBSD__)
 #    define _LIBCPP_HAS_ALIGNED_ALLOC
@@ -408,6 +418,7 @@
 #    endif
 #  endif // __APPLE__
 #endif
+#endif // __has_attribute(using_if_exists)
 
 #ifndef _LIBCPP_CXX03_LANG
 # define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)

diff  --git a/libcxx/include/ctime b/libcxx/include/ctime
index 8b2efd7449ca..2a3fdd12e874 100644
--- a/libcxx/include/ctime
+++ b/libcxx/include/ctime
@@ -59,7 +59,7 @@ int timespec_get( struct timespec *ts, int base); // C++17
 // 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.
-#if defined(__APPLE__)
+#if defined(__APPLE__) && !__has_attribute(using_if_exists)
 #   include <sys/cdefs.h>
 #   if defined(_LIBCPP_HAS_TIMESPEC_GET) && (__DARWIN_C_LEVEL < __DARWIN_C_FULL)
 #       define _LIBCPP_HAS_TIMESPEC_GET_NOT_ACTUALLY_PROVIDED


        


More information about the libcxx-commits mailing list