From b040bc83342fd066fc2de96b18e9ee60f474ffa9 Mon Sep 17 00:00:00 2001
From: "Kirill A. Korinsky" <kirill@korins.ky>
Date: Thu, 28 Sep 2023 09:32:08 +0200
Subject: [PATCH] [libcxx] use malloc/free only on macOS before 10.6

---
 libcxx/include/__memory/aligned_alloc.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libcxx/include/__memory/aligned_alloc.h b/libcxx/include/__memory/aligned_alloc.h
index 786963c72dfc..9094dc87deef 100644
--- a/libcxx/include/__memory/aligned_alloc.h
+++ b/libcxx/include/__memory/aligned_alloc.h
@@ -31,6 +31,9 @@ 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 defined(__APPLE__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1060
+    // macOS before 10.6 hasn't got alligned malloc, fallback to just malloc
+    return ::malloc(__size);
 #  elif _LIBCPP_STD_VER >= 17 && !defined(_LIBCPP_HAS_NO_C11_ALIGNED_ALLOC)
     // aligned_alloc() requires that __size is a multiple of __alignment,
     // but for C++ [new.delete.general], only states "if the value of an
-- 
2.42.0

