From be73606d8580e2efdf22e08b656c5314b39c8542 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Fri, 18 Aug 2023 18:54:28 +0200
Subject: [PATCH] aligned_alloc: Fix test failure on AIX 7.3 with ibm-clang.

* m4/aligned_alloc.m4 (gl_FUNC_ALIGNED_ALLOC): Use 'volatile', to
disable optimization of ibm-clang -O2.
* doc/posix-functions/aligned_alloc.texi: Update version info.
---
 ChangeLog                              | 7 +++++++
 doc/posix-functions/aligned_alloc.texi | 2 +-
 m4/aligned_alloc.m4                    | 9 +++++----
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 26590c9cc7..4aa72e1c06 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-08-18  Bruno Haible  <bruno@clisp.org>
+
+	aligned_alloc: Fix test failure on AIX 7.3 with ibm-clang.
+	* m4/aligned_alloc.m4 (gl_FUNC_ALIGNED_ALLOC): Use 'volatile', to
+	disable optimization of ibm-clang -O2.
+	* doc/posix-functions/aligned_alloc.texi: Update version info.
+
 2023-08-18  Bruno Haible  <bruno@clisp.org>
 
 	sys_socket: Fix compilation errors in C++ mode on AIX 7.3 with gcc.
diff --git a/doc/posix-functions/aligned_alloc.texi b/doc/posix-functions/aligned_alloc.texi
index 7180cf3c12..557f11c6d4 100644
--- a/doc/posix-functions/aligned_alloc.texi
+++ b/doc/posix-functions/aligned_alloc.texi
@@ -11,7 +11,7 @@ Portability problems fixed by Gnulib:
 @item
 This function fails if the alignment argument is smaller than
 @code{sizeof (void *)} on some platforms:
-macOS 11.1, AIX 7.2.
+macOS 11.1, AIX 7.3.1.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/m4/aligned_alloc.m4 b/m4/aligned_alloc.m4
index 8b4c10102e..f546c6ae80 100644
--- a/m4/aligned_alloc.m4
+++ b/m4/aligned_alloc.m4
@@ -1,4 +1,4 @@
-# aligned_alloc.m4 serial 5
+# aligned_alloc.m4 serial 6
 dnl Copyright (C) 2020-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -14,15 +14,16 @@ AC_DEFUN([gl_FUNC_ALIGNED_ALLOC],
 
   gl_CHECK_FUNCS_ANDROID([aligned_alloc], [[#include <stdlib.h>]])
   if test $ac_cv_func_aligned_alloc = yes; then
-    dnl On macOS 11.1 and AIX 7.2, aligned_alloc returns NULL when the alignment
-    dnl argument is smaller than sizeof (void *).
+    dnl On macOS 11.1 and AIX 7.3.1, aligned_alloc returns NULL when the
+    dnl alignment argument is smaller than sizeof (void *).
     AC_CACHE_CHECK([whether aligned_alloc works for small alignments],
       [gl_cv_func_aligned_alloc_works],
       [AC_RUN_IFELSE(
          [AC_LANG_PROGRAM(
             [[#include <stdlib.h>
             ]],
-            [[return aligned_alloc (2, 18) == NULL;
+            [[void *volatile p = aligned_alloc (2, 18);
+              return p == NULL;
             ]])
          ],
          [gl_cv_func_aligned_alloc_works=yes],
-- 
2.39.5