immutable: Add tests.
[gnulib.git] / m4 / aligned_alloc.m4
blobd547c8eb2dd5b25b09c9c68fe833642f41ee4a58
1 # aligned_alloc.m4 serial 2
2 dnl Copyright (C) 2020-2021 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_ALIGNED_ALLOC],
9   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
10   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12   dnl Persuade glibc and OpenBSD <stdlib.h> to declare aligned_alloc().
13   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15   AC_CHECK_FUNCS_ONCE([aligned_alloc])
16   if test $ac_cv_func_aligned_alloc = yes; then
17     dnl On AIX 7.2, aligned_alloc returns NULL when the alignment argument is
18     dnl smaller than sizeof (void *).
19     AC_CACHE_CHECK([whether aligned_alloc works for small alignments],
20       [gl_cv_func_aligned_alloc_works],
21       [AC_RUN_IFELSE(
22          [AC_LANG_PROGRAM(
23             [[#include <stdlib.h>
24             ]],
25             [[return aligned_alloc (2, 18) == NULL;
26             ]])
27          ],
28          [gl_cv_func_aligned_alloc_works=yes],
29          [gl_cv_func_aligned_alloc_works=no],
30          [case "$host_os" in
31                   # Guess no on AIX.
32             aix*) gl_cv_func_aligned_alloc_works="guessing no" ;;
33                   # If we don't know, obey --enable-cross-guesses.
34             *)    gl_cv_func_aligned_alloc_works="$gl_cross_guess_normal" ;;
35           esac
36          ])
37       ])
38     case "$gl_cv_func_aligned_alloc_works" in
39       *yes) ;;
40       *) REPLACE_ALIGNED_ALLOC=1 ;;
41     esac
42   else
43     dnl The system does not have aligned_alloc.
44     HAVE_ALIGNED_ALLOC=0
45   fi