diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt index de9819cf5346a..e4ccc68cc7404 100644 --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -567,7 +567,6 @@ set(files __mdspan/mdspan.h __memory/addressof.h __memory/align.h - __memory/aligned_alloc.h __memory/allocate_at_least.h __memory/allocation_guard.h __memory/allocator.h diff --git a/libcxx/include/__config b/libcxx/include/__config index 357f77b7d27d6..3be35423b2bbe 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -670,27 +670,6 @@ typedef __char32_t char32_t; # define _LIBCPP_HAS_ALIGNED_ALLOCATION 1 # endif -// It is not yet possible to use aligned_alloc() on all Apple platforms since -// 10.15 was the first version to ship an implementation of aligned_alloc(). -# if defined(__APPLE__) -# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ - __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \ - (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \ - __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) || \ - (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && \ - __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 60000) || \ - (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 130000) -# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0 -# else -# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1 -# endif -# elif defined(__ANDROID__) && __ANDROID_API__ < 28 -// Android only provides aligned_alloc when targeting API 28 or higher. -# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0 -# else -# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1 -# endif - # if defined(__APPLE__) || defined(__FreeBSD__) # define _LIBCPP_WCTYPE_IS_MASK # endif diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in index 11ab61d959e22..b4cf5cf53eaee 100644 --- a/libcxx/include/module.modulemap.in +++ b/libcxx/include/module.modulemap.in @@ -1634,7 +1634,6 @@ module std [system] { module memory { module addressof { header "__memory/addressof.h" } module align { header "__memory/align.h" } - module aligned_alloc { header "__memory/aligned_alloc.h" } module allocate_at_least { header "__memory/allocate_at_least.h" } module allocation_guard { header "__memory/allocation_guard.h" } module allocator { diff --git a/libcxx/include/__memory/aligned_alloc.h b/libcxx/src/include/aligned_alloc.h similarity index 90% rename from libcxx/include/__memory/aligned_alloc.h rename to libcxx/src/include/aligned_alloc.h index fb36983d9c3dc..24ca26ce04525 100644 --- a/libcxx/include/__memory/aligned_alloc.h +++ b/libcxx/src/include/aligned_alloc.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef _LIBCPP___MEMORY_ALIGNED_ALLOC_H -#define _LIBCPP___MEMORY_ALIGNED_ALLOC_H +#ifndef _LIBCPP_SRC_ALIGNED_ALLOC_H +#define _LIBCPP_SRC_ALIGNED_ALLOC_H #include <__config> #include @@ -29,7 +29,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_aligned_alloc(std::size_t __alignment, std::size_t __size) { # if defined(_LIBCPP_MSVCRT_LIKE) return ::_aligned_malloc(__size, __alignment); -# elif _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_C11_ALIGNED_ALLOC + +// Android only provides aligned_alloc when targeting API 28 or higher. +# elif !defined(__ANDROID__) || __ANDROID_API__ >= 28 // aligned_alloc() requires that __size is a multiple of __alignment, // but for C++ [new.delete.general], only states "if the value of an // alignment argument passed to any of these functions is not a valid @@ -60,4 +62,4 @@ inline _LIBCPP_HIDE_FROM_ABI void __libcpp_aligned_free(void* __ptr) { _LIBCPP_END_NAMESPACE_STD -#endif // _LIBCPP___MEMORY_ALIGNED_ALLOC_H +#endif // _LIBCPP_SRC_ALIGNED_ALLOC_H diff --git a/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp b/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp index 4bb42cb532078..282d49d727c8c 100644 --- a/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp +++ b/libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp @@ -21,6 +21,8 @@ // GCC doesn't support the aligned-allocation flags. // XFAIL: gcc +// ADDITIONAL_COMPILE_FLAGS: -I %{libcxx-dir}/src -Wno-macro-redefined + // RUN: %{build} -faligned-allocation -fsized-deallocation // RUN: %{run} // RUN: %{build} -faligned-allocation -fno-sized-deallocation -DNO_SIZE @@ -36,10 +38,7 @@ #include "test_macros.h" -TEST_DIAGNOSTIC_PUSH -TEST_CLANG_DIAGNOSTIC_IGNORED("-Wprivate-header") -#include <__memory/aligned_alloc.h> -TEST_DIAGNOSTIC_POP +#include "include/aligned_alloc.h" struct alloc_stats { alloc_stats() { reset(); } diff --git a/libcxxabi/src/fallback_malloc.cpp b/libcxxabi/src/fallback_malloc.cpp index 75788fe9be8d9..6a261e6f009fe 100644 --- a/libcxxabi/src/fallback_malloc.cpp +++ b/libcxxabi/src/fallback_malloc.cpp @@ -16,7 +16,7 @@ #endif #endif -#include <__memory/aligned_alloc.h> +#include "include/aligned_alloc.h" // from libc++ #include <__assert> #include // for malloc, calloc, free #include // for memset diff --git a/libcxxabi/src/stdlib_new_delete.cpp b/libcxxabi/src/stdlib_new_delete.cpp index b5ed59958d17e..dbb75b128a2a4 100644 --- a/libcxxabi/src/stdlib_new_delete.cpp +++ b/libcxxabi/src/stdlib_new_delete.cpp @@ -8,8 +8,8 @@ #include "__cxxabi_config.h" #include "abort_message.h" +#include "include/aligned_alloc.h" // from libc++ #include "include/overridable_function.h" // from libc++ -#include <__memory/aligned_alloc.h> #include #include #include