On older systems without posix_memalign, libcxx now fails to compile with: new.cpp:73:14: error: no member named 'posix_memalign' in the global namespace while (::posix_memalign(&p, static_cast<size_t>(alignment), size) != 0) ~~^ 1 error generated. This regressed in 9acbffa370bd03e4e0ed742110e4c780b99c28ac with: commit 9acbffa370bd03e4e0ed742110e4c780b99c28ac Author: Eric Fiselier <eric@efcs.ca> Date: Fri Oct 14 06:46:30 2016 +0000 Implement P0035R4 -- Add C++17 aligned allocation functions Summary: This patch implements the library side of P0035R4. The implementation is thanks to @rsmith. In addition to the C++17 implementation, the library implementation can be explicitly turned on using `-faligned-allocation` in all dialects. Reviewers: mclow.lists, rsmith Subscribers: rsmith, cfe-commits Differential Revision: https://reviews.llvm.org/D25591 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@284206 91177308-0d34-0410-b5e6-96231b3b80d8 Can we test for the existence of posix_memalign
Can we test for the existence of posix_memalign and disable support for C++17 aligned allocation functions if it doesn't exist? I'm not suggesting we implement that internally to libcxx, but that would obviously be an option as well.
On Windows, posix_memalign wouldn't be available, but _aligned_malloc would.
@Jeremy Can you be more specific about the platform causing issues? Is it just an older OS X version? If so do you know how to detect the availability of posix_memalign or Apple's libc version on that platform? > On Windows, posix_memalign wouldn't be available, but _aligned_malloc would. Ack. I'll make that change right away.
Windows fix made in r290448.
posix_memalign was added in Snow Leopard, and we've (MacPorts) got some users still on Leopard that we try to support. Yes, that's a bit far back. Something like this should do it in CMakeLists.txt: CHECK_SYMBOL_EXISTS(posix_memalign "stdlib.h" HAVE_POSIX_MEMALIGN) CHECK_SYMBOL_EXISTS(_aligned_malloc "malloc.h" HAVE_ALIGNED_MALLOC) Then something like this in new.cpp: #if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_ALIGNED_MALLOC) #define SUPPORT_ALIGNED_ALLOCATION 1 #else #define SUPPORT_ALIGNED_ALLOCATION 0 #endif
Using CMake to detect it doesn't work. We need to be able to detect it inside <new> so we know if we can offer the aligned new/delete overloads.
Oh, well you could do something like this in <new>: #if defined(__APPLE__) # include <Availability.h> # if __MAC_OS_X_VERSION_MIN_REQUIRED < 1060 # define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION # endif #endif
Awesome thanks! Can you point to the OS X documentation that specifies the min required version for posix_memalign? I can't seem to find it anywhere.
It's declared in stdlib.h as: int posix_memalign(void **, size_t, size_t) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_0); And I've also verified as such through nm.
Fix up for review in D28931. I'll backport it to Clang 4.0 as well. https://reviews.llvm.org/D28931
Fixed in r292564 and merged into the 4.0 release branch.
Patch LGTM. Thanks.