Skip to content

Commit 3dcdb4c

Browse files
authored
[libc++][NFC] Move __memory/aligned_alloc.h into src/ (#166172)
This header is only ever used inside `src/`, so we might as well move it there. As a drive-by this also removes some dead code.
1 parent 89206de commit 3dcdb4c

File tree

7 files changed

+11
-33
lines changed

7 files changed

+11
-33
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,6 @@ set(files
569569
__mdspan/mdspan.h
570570
__memory/addressof.h
571571
__memory/align.h
572-
__memory/aligned_alloc.h
573572
__memory/allocate_at_least.h
574573
__memory/allocation_guard.h
575574
__memory/allocator.h

libcxx/include/__config

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -495,27 +495,6 @@ typedef __char32_t char32_t;
495495
# define _LIBCPP_HAS_ALIGNED_ALLOCATION 1
496496
# endif
497497

498-
// It is not yet possible to use aligned_alloc() on all Apple platforms since
499-
// 10.15 was the first version to ship an implementation of aligned_alloc().
500-
# if defined(__APPLE__)
501-
# if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
502-
__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500) || \
503-
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
504-
__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 130000) || \
505-
(defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && \
506-
__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 60000) || \
507-
(defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 130000)
508-
# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0
509-
# else
510-
# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1
511-
# endif
512-
# elif defined(__ANDROID__) && __ANDROID_API__ < 28
513-
// Android only provides aligned_alloc when targeting API 28 or higher.
514-
# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 0
515-
# else
516-
# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1
517-
# endif
518-
519498
# if defined(__APPLE__) || defined(__FreeBSD__)
520499
# define _LIBCPP_WCTYPE_IS_MASK
521500
# endif

libcxx/include/module.modulemap.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,6 @@ module std [system] {
16281628
module memory {
16291629
module addressof { header "__memory/addressof.h" }
16301630
module align { header "__memory/align.h" }
1631-
module aligned_alloc { header "__memory/aligned_alloc.h" }
16321631
module allocate_at_least { header "__memory/allocate_at_least.h" }
16331632
module allocation_guard { header "__memory/allocation_guard.h" }
16341633
module allocator {

libcxx/include/__memory/aligned_alloc.h renamed to libcxx/src/include/aligned_alloc.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef _LIBCPP___MEMORY_ALIGNED_ALLOC_H
10-
#define _LIBCPP___MEMORY_ALIGNED_ALLOC_H
9+
#ifndef _LIBCPP_SRC_ALIGNED_ALLOC_H
10+
#define _LIBCPP_SRC_ALIGNED_ALLOC_H
1111

1212
#include <__config>
1313
#include <cstdlib>
@@ -29,7 +29,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2929
inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_aligned_alloc(std::size_t __alignment, std::size_t __size) {
3030
# if defined(_LIBCPP_MSVCRT_LIKE)
3131
return ::_aligned_malloc(__size, __alignment);
32-
# elif _LIBCPP_STD_VER >= 17 && _LIBCPP_HAS_C11_ALIGNED_ALLOC
32+
33+
// Android only provides aligned_alloc when targeting API 28 or higher.
34+
# elif !defined(__ANDROID__) || __ANDROID_API__ >= 28
3335
// aligned_alloc() requires that __size is a multiple of __alignment,
3436
// but for C++ [new.delete.general], only states "if the value of an
3537
// 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) {
6062

6163
_LIBCPP_END_NAMESPACE_STD
6264

63-
#endif // _LIBCPP___MEMORY_ALIGNED_ALLOC_H
65+
#endif // _LIBCPP_SRC_ALIGNED_ALLOC_H

libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
// GCC doesn't support the aligned-allocation flags.
2222
// XFAIL: gcc
2323

24+
// ADDITIONAL_COMPILE_FLAGS: -I %{libcxx-dir}/src -Wno-macro-redefined
25+
2426
// RUN: %{build} -faligned-allocation -fsized-deallocation
2527
// RUN: %{run}
2628
// RUN: %{build} -faligned-allocation -fno-sized-deallocation -DNO_SIZE
@@ -36,10 +38,7 @@
3638

3739
#include "test_macros.h"
3840

39-
TEST_DIAGNOSTIC_PUSH
40-
TEST_CLANG_DIAGNOSTIC_IGNORED("-Wprivate-header")
41-
#include <__memory/aligned_alloc.h>
42-
TEST_DIAGNOSTIC_POP
41+
#include "include/aligned_alloc.h"
4342

4443
struct alloc_stats {
4544
alloc_stats() { reset(); }

libcxxabi/src/fallback_malloc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#endif
1717
#endif
1818

19-
#include <__memory/aligned_alloc.h>
19+
#include "include/aligned_alloc.h" // from libc++
2020
#include <__assert>
2121
#include <stdlib.h> // for malloc, calloc, free
2222
#include <string.h> // for memset

libcxxabi/src/stdlib_new_delete.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include "__cxxabi_config.h"
1010
#include "abort_message.h"
11+
#include "include/aligned_alloc.h" // from libc++
1112
#include "include/overridable_function.h" // from libc++
12-
#include <__memory/aligned_alloc.h>
1313
#include <cstddef>
1414
#include <cstdlib>
1515
#include <new>

0 commit comments

Comments
 (0)