[libcxx-commits] [libcxx] 19fd903 - Fix _LIBCPP_HAS_ definitions for Android.
Dan Albert via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Nov 18 12:22:16 PST 2019
Author: Dan Albert
Date: 2019-11-18T12:19:58-08:00
New Revision: 19fd9039ca242f408493b5c662f9d908eab8555e
URL: https://github.com/llvm/llvm-project/commit/19fd9039ca242f408493b5c662f9d908eab8555e
DIFF: https://github.com/llvm/llvm-project/commit/19fd9039ca242f408493b5c662f9d908eab8555e.diff
LOG: Fix _LIBCPP_HAS_ definitions for Android.
Summary:
Android added quick_exit()/at_quick_exit() in API level 21,
aligned_alloc() in API level 28, and timespec_get() in API level 29,
but has the other C11 features at all API levels (since they're basically
just coming from clang directly).
_LIBCPP_HAS_QUICK_EXIT and _LIBCPP_HAS_TIMESPEC_GET already existed,
so we can reuse them. (And use _LIBCPP_HAS_TIMESPEC_GET in a few more
places where _LIBCPP_HAS_C11_FEATURES has been used as a proxy. This
isn't correct for Android.)
_LIBCPP_HAS_ALIGNED_ALLOC is added, to cover aligned_alloc() (obviously).
Add a missing std:: before aligned_alloc in a cstdlib test, and remove a
couple of !defined(_WIN32)s now that we're explicitly testing
TEST_HAS_ALIGNED_ALLOC rather than TEST_HAS_C11_FEATURES.
Reviewers: danalbert, EricWF, mclow.lists
Reviewed By: danalbert
Subscribers: srhines, christof, libcxx-commits
Tags: #libc
Differential Revision: https://reviews.llvm.org/D69929
Added:
Modified:
libcxx/include/__config
libcxx/include/cstdlib
libcxx/include/ctime
libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp
libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
libcxx/test/std/language.support/support.runtime/ctime.pass.cpp
libcxx/test/std/utilities/time/date.time/ctime.pass.cpp
libcxx/test/support/test_macros.h
Removed:
################################################################################
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 47b40c49cf79..67d2fd7a3e1b 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -340,9 +340,22 @@
#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L
# if defined(__FreeBSD__)
+# define _LIBCPP_HAS_ALIGNED_ALLOC
# define _LIBCPP_HAS_QUICK_EXIT
# define _LIBCPP_HAS_C11_FEATURES
+# elif defined(__BIONIC__)
+# define _LIBCPP_HAS_C11_FEATURES
+# if __ANDROID_API__ >= 21
+# define _LIBCPP_HAS_QUICK_EXIT
+# endif
+# if __ANDROID_API__ >= 28
+# define _LIBCPP_HAS_ALIGNED_ALLOC
+# endif
+# if __ANDROID_API__ >= 29
+# define _LIBCPP_HAS_TIMESPEC_GET
+# endif
# elif defined(__Fuchsia__) || defined(__wasi__)
+# define _LIBCPP_HAS_ALIGNED_ALLOC
# define _LIBCPP_HAS_QUICK_EXIT
# define _LIBCPP_HAS_TIMESPEC_GET
# define _LIBCPP_HAS_C11_FEATURES
@@ -352,10 +365,12 @@
# define _LIBCPP_HAS_QUICK_EXIT
# endif
# if _LIBCPP_GLIBC_PREREQ(2, 17)
+# define _LIBCPP_HAS_ALIGNED_ALLOC
# define _LIBCPP_HAS_C11_FEATURES
# define _LIBCPP_HAS_TIMESPEC_GET
# endif
# else // defined(_LIBCPP_HAS_MUSL_LIBC)
+# define _LIBCPP_HAS_ALIGNED_ALLOC
# define _LIBCPP_HAS_QUICK_EXIT
# define _LIBCPP_HAS_TIMESPEC_GET
# define _LIBCPP_HAS_C11_FEATURES
diff --git a/libcxx/include/cstdlib b/libcxx/include/cstdlib
index 68b3ded3fd51..675a12d9e04b 100644
--- a/libcxx/include/cstdlib
+++ b/libcxx/include/cstdlib
@@ -154,7 +154,7 @@ using ::wcstombs;
using ::at_quick_exit;
using ::quick_exit;
#endif
-#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_C11_FEATURES)
+#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_ALIGNED_ALLOC)
using ::aligned_alloc;
#endif
diff --git a/libcxx/include/ctime b/libcxx/include/ctime
index 71e60b10fe55..f9f2f1659d0e 100644
--- a/libcxx/include/ctime
+++ b/libcxx/include/ctime
@@ -58,7 +58,7 @@ using ::clock_t;
using ::size_t;
using ::time_t;
using ::tm;
-#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_C11_FEATURES)
+#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET)
using ::timespec;
#endif
using ::clock;
diff --git a/libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp b/libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp
index d1fde66da4c2..49f17d63b82d 100644
--- a/libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp
+++ b/libcxx/test/std/depr/depr.c.headers/stdlib_h.pass.cpp
@@ -132,8 +132,7 @@ int main(int, char**)
static_assert((std::is_same<decltype(rand()), int>::value), "");
static_assert((std::is_same<decltype(srand(0)), void>::value), "");
-// Microsoft does not implement aligned_alloc in their C library
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && !defined(_WIN32)
+#if TEST_STD_VER > 14 && defined(TEST_HAS_ALIGNED_ALLOC)
static_assert((std::is_same<decltype(aligned_alloc(0,0)), void*>::value), "");
#endif
diff --git a/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp b/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
index 8e6357304d04..da0e3c01fd16 100644
--- a/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
+++ b/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
@@ -119,9 +119,8 @@ int main(int, char**)
static_assert((std::is_same<decltype(std::rand()), int>::value), "");
static_assert((std::is_same<decltype(std::srand(0)), void>::value), "");
-// Microsoft does not implement aligned_alloc in their C library
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES) && !defined(_WIN32)
- static_assert((std::is_same<decltype(aligned_alloc(0,0)), void*>::value), "");
+#if TEST_STD_VER > 14 && defined(TEST_HAS_ALIGNED_ALLOC)
+ static_assert((std::is_same<decltype(std::aligned_alloc(0,0)), void*>::value), "");
#endif
static_assert((std::is_same<decltype(std::calloc(0,0)), void*>::value), "");
diff --git a/libcxx/test/std/language.support/support.runtime/ctime.pass.cpp b/libcxx/test/std/language.support/support.runtime/ctime.pass.cpp
index a8c2dc7ff567..fb744c5001e9 100644
--- a/libcxx/test/std/language.support/support.runtime/ctime.pass.cpp
+++ b/libcxx/test/std/language.support/support.runtime/ctime.pass.cpp
@@ -20,7 +20,7 @@
#error CLOCKS_PER_SEC not defined
#endif
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)
+#if TEST_STD_VER > 14 && defined(TEST_HAS_TIMESPEC_GET)
#ifndef TIME_UTC
#error TIME_UTC not defined
#endif
@@ -32,7 +32,7 @@ int main(int, char**)
std::size_t s = 0;
std::time_t t = 0;
std::tm tm = {};
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)
+#if TEST_STD_VER > 14 && defined(TEST_HAS_TIMESPEC_GET)
std::timespec tmspec = {};
((void)tmspec); // Prevent unused warning
#endif
diff --git a/libcxx/test/std/utilities/time/date.time/ctime.pass.cpp b/libcxx/test/std/utilities/time/date.time/ctime.pass.cpp
index ac29fd781804..da16c85e7cd5 100644
--- a/libcxx/test/std/utilities/time/date.time/ctime.pass.cpp
+++ b/libcxx/test/std/utilities/time/date.time/ctime.pass.cpp
@@ -19,7 +19,7 @@
#error CLOCKS_PER_SEC not defined
#endif
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)
+#if TEST_STD_VER > 14 && defined(TEST_HAS_TIMESPEC_GET)
#ifndef TIME_UTC
#error TIME_UTC not defined
#endif
@@ -41,7 +41,7 @@ int main(int, char**)
((void)t); // Prevent unused warning
((void)tm); // Prevent unused warning
((void)str); // Prevent unused warning
-#if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)
+#if TEST_STD_VER > 14 && defined(TEST_HAS_TIMESPEC_GET)
std::timespec tmspec = {};
((void)tmspec); // Prevent unused warning
#endif
diff --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h
index df480abbead4..f5fbedb55552 100644
--- a/libcxx/test/support/test_macros.h
+++ b/libcxx/test/support/test_macros.h
@@ -153,8 +153,18 @@
# if defined(__FreeBSD__)
// Specifically, FreeBSD does NOT have timespec_get, even though they have all
// the rest of C11 - this is PR#38495
+# define TEST_HAS_ALIGNED_ALLOC
# define TEST_HAS_C11_FEATURES
+# elif defined(__BIONIC__)
+# define TEST_HAS_C11_FEATURES
+# if __ANDROID_API__ >= 28
+# define TEST_HAS_ALIGNED_ALLOC
+# endif
+# if __ANDROID_API__ >= 29
+# define TEST_HAS_TIMESPEC_GET
+# endif
# elif defined(__Fuchsia__) || defined(__wasi__)
+# define TEST_HAS_ALIGNED_ALLOC
# define TEST_HAS_C11_FEATURES
# define TEST_HAS_TIMESPEC_GET
# elif defined(__linux__)
@@ -164,15 +174,18 @@
// newlib, etc may all support these features but need to be configured.
# if defined(TEST_GLIBC_PREREQ)
# if TEST_GLIBC_PREREQ(2, 17)
+# define TEST_HAS_ALIGNED_ALLOC
# define TEST_HAS_TIMESPEC_GET
# define TEST_HAS_C11_FEATURES
# endif
# elif defined(_LIBCPP_HAS_MUSL_LIBC)
+# define TEST_HAS_ALIGNED_ALLOC
# define TEST_HAS_C11_FEATURES
# define TEST_HAS_TIMESPEC_GET
# endif
# elif defined(_WIN32)
# if defined(_MSC_VER) && !defined(__MINGW32__)
+# define TEST_HAS_ALIGNED_ALLOC
# define TEST_HAS_C11_FEATURES // Using Microsoft's C Runtime library
# define TEST_HAS_TIMESPEC_GET
# endif
More information about the libcxx-commits
mailing list