#endif
#if ((ALIGNMENT) <= MALLOC_ALIGNMENT) || HAVE_POSIX_MEMALIGN || HAVE_ALIGNED_ALLOC || HAVE_MEMALIGN
+# if defined aligned_free || __GNUC__ >= 11
+ /* The caller wants an inline function, not a macro,
+ or we can use GCC's -Wmismatched-dealloc warning. */
+static inline void
+aligned_free (void *q)
+{
+ free (q);
+}
+# else
+# define aligned_free free
+# endif
+
# if (ALIGNMENT) <= MALLOC_ALIGNMENT
/* Simply use malloc. */
-# ifdef aligned_malloc
- /* The caller wants an inline function, not a macro. */
-static inline void *
+# if defined aligned_malloc || __GNUC__ >= 11
+ /* The caller wants an inline function, not a macro,
+ or GCC's -Wmismatched-dealloc warning might be in effect. */
+static inline
+/*_GL_ATTRIBUTE_DEALLOC (aligned_free, 1)*/
+void *
aligned_malloc (size_t size)
{
return malloc (size);
/* Use posix_memalign.
This is OK since ALIGNMENT > MALLOC_ALIGNMENT >= sizeof (void *). */
-static inline void *
+static inline
+/*_GL_ATTRIBUTE_DEALLOC (aligned_free, 1)*/
+void *
aligned_malloc (size_t size)
{
void *p;
# elif HAVE_ALIGNED_ALLOC
/* Use aligned_alloc. */
-static inline void *
+static inline
+/*_GL_ATTRIBUTE_DEALLOC (aligned_free, 1)*/
+void *
aligned_malloc (size_t size)
{
/* Round up SIZE to the next multiple of ALIGNMENT,
# elif HAVE_MEMALIGN /* HP-UX, IRIX, Solaris <= 10 */
/* Use memalign. */
-static inline void *
+static inline
+/*_GL_ATTRIBUTE_DEALLOC (aligned_free, 1)*/
+void *
aligned_malloc (size_t size)
{
return memalign ((ALIGNMENT), size);
# endif
-# ifdef aligned_free
- /* The caller wants an inline function, not a macro. */
+#else
+/* Use malloc and waste a bit of memory. */
+
static inline void
aligned_free (void *q)
{
- free (q);
+ if (q != NULL)
+ {
+ if ((uintptr_t) q & ((ALIGNMENT) - 1))
+ /* Argument not aligned as expected. */
+ abort ();
+ else
+ {
+ void *p = ((void **) q)[-1];
+ if (!((uintptr_t) p <= (uintptr_t) q
+ && (uintptr_t) q - (uintptr_t) p >= MALLOC_ALIGNMENT
+ && (uintptr_t) q - (uintptr_t) p <= (ALIGNMENT)))
+ abort ();
+ free (p);
+ }
+ }
}
-# else
-# define aligned_free free
-# endif
-
-#else
-/* Use malloc and waste a bit of memory. */
-static inline void *
+static inline
+/*_GL_ATTRIBUTE_DEALLOC (aligned_free, 1)*/
+void *
aligned_malloc (size_t size)
{
size += (ALIGNMENT);
return NULL;
}
-static inline void
-aligned_free (void *q)
-{
- if (q != NULL)
- {
- if ((uintptr_t) q & ((ALIGNMENT) - 1))
- /* Argument not aligned as expected. */
- abort ();
- else
- {
- void *p = ((void **) q)[-1];
- if (!((uintptr_t) p <= (uintptr_t) q
- && (uintptr_t) q - (uintptr_t) p >= MALLOC_ALIGNMENT
- && (uintptr_t) q - (uintptr_t) p <= (ALIGNMENT)))
- abort ();
- free (p);
- }
- }
-}
-
#endif