Paul Eggert wrote: > Thanks, I committed that in Autoconf. Thanks. I'm committing this in Gnulib:
2026-10-19 Bruno Haible <[email protected]> Fix AC_CHECK_FUNC results with optimizing MSVC in a simpler way. * m4/00gnulib.m4 (gl_COMPILER_PREPARE_CHECK_FUNC): Remove macro. (_AC_CHECK_FUNC_BODY): Remove override. (AC_LANG_FUNC_LINK_TRY(C)): New override, from autoconf master. * m4/zzgnulib.m4 (AC_PROG_CC): Don't invoke gl_COMPILER_PREPARE_CHECK_FUNC. diff --git a/m4/00gnulib.m4 b/m4/00gnulib.m4 index c922273a70..d8ebc3b56a 100644 --- a/m4/00gnulib.m4 +++ b/m4/00gnulib.m4 @@ -1,5 +1,5 @@ # 00gnulib.m4 -# serial 10 +# serial 11 dnl Copyright (C) 2009-2026 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -80,67 +80,76 @@ m4_define([_AC_CHECK_DECL_BODY] m4_defn([_AC_CHECK_DECL_BODY])[ ac_compile="$ac_saved_ac_compile" ]) -# The following definitions arrange to use a compiler option -Oi- in -# AC_CHECK_FUNC, when the compiler is MSVC with optimization enabled. -# Without it, this compiler implicitly declares "known" library functions, -# which would cause the AC_CHECK_FUNC test to fail. -# The list of such library functions is documented at -# <https://learn.microsoft.com/en-us/cpp/intrinsics/intrinsics-available-on-all-architectures>. -# It's not possible to AC_REQUIRE the extra tests from AC_CHECK_FUNC, -# because AC_CHECK_FUNC, like other Autoconf built-ins, is not supposed -# to AC_REQUIRE anything: some configure.ac files have their first -# AC_CHECK_FUNC executed conditionally. Therefore append the extra tests -# to AC_PROG_CC. -AC_DEFUN([gl_COMPILER_PREPARE_CHECK_FUNC], -[ -dnl AC_REQUIRE([AC_PROG_CC]) - AC_CACHE_CHECK([for compiler option needed when checking for functions], - [gl_cv_compiler_check_func_option], - [dnl Use _AC_COMPILE_IFELSE instead of AC_COMPILE_IFELSE, to avoid a - dnl warning "AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS". - _AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([[ - #ifdef __cplusplus - extern "C" - #endif - char memcpy (void); - ]],[[ - return memcpy (); - ]])], - [gl_cv_compiler_check_func_option=none], - [dnl Test whether the compiler supports the option '-Oi-'. - saved_ac_compile="$ac_compile" - ac_compile="$ac_compile -Oi-" - _AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([[ - #ifdef __cplusplus - extern "C" - #endif - char memcpy (void); - ]],[[ - return memcpy (); - ]])], - [gl_cv_compiler_check_func_option='-Oi-'], - [gl_cv_compiler_check_func_option=none]) - ac_compile="$saved_ac_compile" - ]) - ]) - if test "x$gl_cv_compiler_check_func_option" != xnone; then - ac_link_for_check_func="$ac_link $gl_cv_compiler_check_func_option" - else - ac_link_for_check_func="$ac_link" - fi -]) -dnl Redefine _AC_CHECK_FUNC_BODY so that it references ac_link_for_check_func -dnl instead of ac_link. If, for whatever reason, the override of AC_PROG_CC -dnl in zzgnulib.m4 is inactive, use the original ac_link. -m4_define([_AC_CHECK_FUNC_BODY], -[ ac_saved_ac_link="$ac_link" - if test -n "$ac_link_for_check_func"; then - ac_link="$ac_link_for_check_func" - fi] -m4_defn([_AC_CHECK_FUNC_BODY])[ ac_link="$ac_saved_ac_link" -]) +# This implementation is taken from GNU Autoconf lib/autoconf/c.m4 +# commit cba29368f2d37483990c317617b6c762b0a43c39 dated 2026-10-19 21:14:13. +# This implementation will be obsolete once we can assume Autoconf 2.74 +# or later is installed everywhere a Gnulib program might be developed. + +m4_version_prereq([2.74], [], [ + +# AC_LANG_FUNC_LINK_TRY(C)(FUNCTION) +# ---------------------------------- +# Don't include <ctype.h> because on OSF/1 3.0 it includes +# <sys/types.h> which includes <sys/select.h> which contains a +# prototype for select. Similarly for bzero. +# +# This test used to merely assign f=$1 in main(), but that was +# optimized away by HP unbundled cc A.05.36 for ia64 under +O3, +# presumably on the basis that there's no need to do that store if the +# program is about to exit. Conversely, the AIX linker optimizes an +# unused external declaration that initializes f=$1. So this test +# program has both an external initialization of f, and a use of f in +# main that affects the exit status. +# +m4_define([AC_LANG_FUNC_LINK_TRY(C)], +[AC_LANG_PROGRAM( +[/* Define $1 to an innocuous variant, in case <limits.h> declares $1. + For example, HP-UX 11i <limits.h> declares gettimeofday. */ +#define $1 innocuous_$1 + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $1 (void); below. */ +#include <limits.h> +#undef $1 + +/* Tell Clang to allow disagreement with declaration of builtin $1. */ +#if defined __clang__ && 4 <= __clang_major__ +# pragma clang diagnostic ignored "-Wincompatible-library-redeclaration" +#endif + +#ifdef _MSC_VER + +/* Tell MSVC to link the function without checking its type. */ +# ifdef _M_IX86 /* x86 */ +# pragma comment (linker, "/include:_$1") +# else /* x86_64, arm, arm64 */ +# pragma comment (linker, "/include:$1") +# endif + +#else + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +# ifdef __cplusplus +extern "C" +# endif +char $1 (void); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +# if defined __stub_$1 || defined __stub___$1 +choke me +# endif + +#endif +], [ +#ifndef _MSC_VER +return $1 (); +#endif +])]) + +])# m4_version_prereq # gl_00GNULIB # ----------- diff --git a/m4/zzgnulib.m4 b/m4/zzgnulib.m4 index edce69192c..5608ba68ff 100644 --- a/m4/zzgnulib.m4 +++ b/m4/zzgnulib.m4 @@ -1,5 +1,5 @@ # zzgnulib.m4 -# serial 2 +# serial 3 dnl Copyright (C) 2020-2026 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -10,13 +10,12 @@ dnl package- or gnulib-provided .m4 files - at least for those packages dnl that redefine AC_PROG_CC. -dnl Redefine AC_PROG_CC so that it ends with invocations of gl_COMPILER_CLANG, -dnl gl_COMPILER_PREPARE_CHECK_DECL, and gl_COMPILER_PREPARE_CHECK_FUNC. +dnl Redefine AC_PROG_CC so that it ends with invocations of gl_COMPILER_CLANG +dnl and gl_COMPILER_PREPARE_CHECK_DECL. m4_define([AC_PROG_CC], m4_defn([AC_PROG_CC])[ gl_COMPILER_CLANG gl_COMPILER_PREPARE_CHECK_DECL -gl_COMPILER_PREPARE_CHECK_FUNC ]) # gl_ZZGNULIB
