|
| 1 | +diff --git a/pocketfft_hdronly.h b/pocketfft_hdronly.h |
| 2 | +index 57db7d7..e831ac0 100644 |
| 3 | +--- a/pocketfft_hdronly.h |
| 4 | ++++ b/pocketfft_hdronly.h |
| 5 | +@@ -162,8 +162,20 @@ template<> struct VLEN<double> { static constexpr size_t val=2; }; |
| 6 | + // std::aligned_alloc is a bit cursed ... it doesn't exist on MacOS < 10.15 |
| 7 | + // and in musl, and other OSes seem to have even more peculiarities. |
| 8 | + // Let's unconditionally work around it for now. |
| 9 | +-# if 0 |
| 10 | +-//#if (__cplusplus >= 201703L) && (!defined(__MINGW32__)) && (!defined(_MSC_VER)) && (__MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_15) |
| 11 | ++#if defined(__APPLE__) || defined(__unix__) |
| 12 | ++// Use posix_memalign on POSIX systems - it is ASAN-compatible. |
| 13 | ++// The portable aligned_alloc below stores metadata at ptr[-1], which conflicts |
| 14 | ++// with ASAN's heap redzone and causes intermittent bus errors. |
| 15 | ++inline void *aligned_alloc(size_t align, size_t size) |
| 16 | ++ { |
| 17 | ++ void *ptr = nullptr; |
| 18 | ++ if (posix_memalign(&ptr, align, size) != 0) |
| 19 | ++ throw std::bad_alloc(); |
| 20 | ++ return ptr; |
| 21 | ++ } |
| 22 | ++inline void aligned_dealloc(void *ptr) |
| 23 | ++ { free(ptr); } |
| 24 | ++#elif (__cplusplus >= 201703L) && (!defined(__MINGW32__)) && (!defined(_MSC_VER)) |
| 25 | + inline void *aligned_alloc(size_t align, size_t size) |
| 26 | + { |
| 27 | + // aligned_alloc() requires that the requested size is a multiple of "align" |
| 28 | +@@ -173,7 +185,7 @@ inline void *aligned_alloc(size_t align, size_t size) |
| 29 | + } |
| 30 | + inline void aligned_dealloc(void *ptr) |
| 31 | + { free(ptr); } |
| 32 | +-#else // portable emulation |
| 33 | ++#else // portable emulation (NOT ASAN-compatible - stores metadata at ptr[-1]) |
| 34 | + inline void *aligned_alloc(size_t align, size_t size) |
| 35 | + { |
| 36 | + align = std::max(align, alignof(max_align_t)); |
0 commit comments