]> Savannah Git Hosting - gnulib.git/commitdiff
calloc-gnu: Avoid wrong configure results with GCC's AddressSanitizer.
authorBruno Haible <bruno@clisp.org>
Sat, 23 May 2020 20:13:45 +0000 (22:13 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 23 May 2020 20:13:45 +0000 (22:13 +0200)
* m4/calloc.m4 (_AC_FUNC_CALLOC_IF): Split the AC_RUN_IFELSE into two
AC_RUN_IFELSE invocations.

ChangeLog
m4/calloc.m4

index 3d4c0f8b0d96700fb620d8dd953b3127e72318d4..004f069c3dd1b3aa75160774f9cd8d6ef396b9d3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-05-23  Bruno Haible  <bruno@clisp.org>
+
+       calloc-gnu: Avoid wrong configure results with GCC's AddressSanitizer.
+       * m4/calloc.m4 (_AC_FUNC_CALLOC_IF): Split the AC_RUN_IFELSE into two
+       AC_RUN_IFELSE invocations.
+
 2020-05-23  Bruno Haible  <bruno@clisp.org>
 
        isnanf, isnanl, isnan: Don't use nonexistent builtins with clang.
index 3361cba7a6086d3a53f1adbd61351ecd0a430619..a93439e8c8f4391084b54cd43c39fe96b2ab9c07 100644 (file)
@@ -1,4 +1,4 @@
-# calloc.m4 serial 21
+# calloc.m4 serial 22
 
 # Copyright (C) 2004-2020 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -21,33 +21,48 @@ AC_DEFUN([_AC_FUNC_CALLOC_IF],
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
   AC_CACHE_CHECK([for GNU libc compatible calloc],
     [ac_cv_func_calloc_0_nonnull],
-    [AC_RUN_IFELSE(
-       [AC_LANG_PROGRAM(
-          [AC_INCLUDES_DEFAULT],
-          [[int result = 0;
-            char * volatile p = calloc (0, 0);
-            if (!p)
-              result |= 1;
-            free (p);
-            p = calloc ((size_t) -1 / 8 + 1, 8);
-            if (p)
-              result |= 2;
-            free (p);
-            return result;
-          ]])],
-       [ac_cv_func_calloc_0_nonnull=yes],
-       [ac_cv_func_calloc_0_nonnull=no],
-       [case "$host_os" in
-                         # Guess yes on glibc systems.
-          *-gnu* | gnu*) ac_cv_func_calloc_0_nonnull="guessing yes" ;;
-                         # Guess yes on musl systems.
-          *-musl*)       ac_cv_func_calloc_0_nonnull="guessing yes" ;;
-                         # Guess yes on native Windows.
-          mingw*)        ac_cv_func_calloc_0_nonnull="guessing yes" ;;
-                         # If we don't know, obey --enable-cross-guesses.
-          *)             ac_cv_func_calloc_0_nonnull="$gl_cross_guess_normal" ;;
-        esac
-       ])])
+    [if test $cross_compiling != yes; then
+       ac_cv_func_calloc_0_nonnull=yes
+       AC_RUN_IFELSE(
+         [AC_LANG_PROGRAM(
+            [AC_INCLUDES_DEFAULT],
+            [[int result = 0;
+              char * volatile p = calloc (0, 0);
+              if (!p)
+                result |= 1;
+              free (p);
+              return result;
+            ]])],
+         [],
+         [ac_cv_func_calloc_0_nonnull=no])
+       AC_RUN_IFELSE(
+         [AC_LANG_PROGRAM(
+            [AC_INCLUDES_DEFAULT],
+            [[int result = 0;
+              char * volatile p = calloc ((size_t) -1 / 8 + 1, 8);
+              if (!p)
+                result |= 2;
+              free (p);
+              return result;
+            ]])],
+         dnl The exit code of this program is 0 if calloc() succeeded (which
+         dnl it shouldn't), 2 if calloc() failed, or 1 if some leak sanitizer
+         dnl terminated the program as a result of the calloc() call.
+         [ac_cv_func_calloc_0_nonnull=no],
+         [])
+     else
+       case "$host_os" in
+                        # Guess yes on glibc systems.
+         *-gnu* | gnu*) ac_cv_func_calloc_0_nonnull="guessing yes" ;;
+                        # Guess yes on musl systems.
+         *-musl*)       ac_cv_func_calloc_0_nonnull="guessing yes" ;;
+                        # Guess yes on native Windows.
+         mingw*)        ac_cv_func_calloc_0_nonnull="guessing yes" ;;
+                        # If we don't know, obey --enable-cross-guesses.
+         *)             ac_cv_func_calloc_0_nonnull="$gl_cross_guess_normal" ;;
+       esac
+     fi
+    ])
   case "$ac_cv_func_calloc_0_nonnull" in
     *yes)
       $1