From: Bruno Haible Date: Sat, 23 May 2020 20:13:45 +0000 (+0200) Subject: calloc-gnu: Avoid wrong configure results with GCC's AddressSanitizer. X-Git-Tag: v1.0~4076 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=3d29ad5500aca06b0f56bbe979b09c32017f6c1d;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 3d4c0f8b0d..004f069c3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2020-05-23 Bruno Haible + + 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 isnanf, isnanl, isnan: Don't use nonexistent builtins with clang. diff --git a/m4/calloc.m4 b/m4/calloc.m4 index 3361cba7a6..a93439e8c8 100644 --- a/m4/calloc.m4 +++ b/m4/calloc.m4 @@ -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