Hi, There is no news that AC_CHECK_FUNC fails to find built-in functions when either AC_LANG_WERROR is used or -Werror is included in CFLAGS:
$ cat configure.ac AC_INIT AC_LANG_WERROR AC_CHECK_FUNC(memset) $ autoconf && ./configure checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking for memset... no $ grep 'warning.*memset' config.log conftest.c:35: warning: conflicting types for built-in function 'memset' For a long time I maintain a patch that remedies this problem. While the patch is probably not quite suitable for inclusion as is, it is known to work. I've updated it for the HEAD and decided to give it a chance to be discussed here. I hope the idea behind this patch could be used for a more acceptable fix. --- lib/autoconf/c.m4 | 19 +++++++++++++++++++ lib/autoconf/functions.m4 | 4 +++- lib/autoconf/lang.m4 | 8 ++++++++ 3 files changed, 30 insertions(+), 1 deletions(-) diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4 index 40fdab4..8536c65 100644 --- a/lib/autoconf/c.m4 +++ b/lib/autoconf/c.m4 @@ -183,6 +183,25 @@ choke me ], [return $1 ();])]) +# AC_LANG_FUNC_LINK_TRY_GCC_BUILTIN(C)(FUNCTION) +# ---------------------------------- +# This will test if function is available as +# gcc3 builtin. +# +m4_define([AC_LANG_FUNC_LINK_TRY_GCC_BUILTIN(C)], +[AC_LANG_PROGRAM( +[#ifndef __GNUC__ +choke me +#else +#undef $1 +/* Declare this function with same prototype as __builtin_$1. + This removes warning about conflicting type with builtin */ +__typeof__(__builtin_$1) $1; + +__typeof__(__builtin_$1) *f = $1; +#endif +], [return f != $1;])]) + # AC_LANG_BOOL_COMPILE_TRY(C)(PROLOGUE, EXPRESSION) # ------------------------------------------------- # Return a program that is valid if EXPRESSION is nonzero. diff --git a/lib/autoconf/functions.m4 b/lib/autoconf/functions.m4 index 24dcf86..8176ee7 100644 --- a/lib/autoconf/functions.m4 +++ b/lib/autoconf/functions.m4 @@ -47,7 +47,9 @@ m4_define([_AC_CHECK_FUNC_BODY], AC_CACHE_CHECK([for $[]2], [$[]3], [AC_LINK_IFELSE([AC_LANG_FUNC_LINK_TRY($[]2)], [AS_VAR_SET([$[]3], [yes])], - [AS_VAR_SET([$[]3], [no])])]) + [AC_LINK_IFELSE([AC_LANG_FUNC_LINK_TRY_GCC_BUILTIN($[]2)], + [AS_VAR_SET([$[]3], [yes])], + [AS_VAR_SET([$[]3], [no])])])]) AS_LINENO_POP ])# _AC_CHECK_FUNC_BODY diff --git a/lib/autoconf/lang.m4 b/lib/autoconf/lang.m4 index 98ccf5c..7338e1c 100644 --- a/lib/autoconf/lang.m4 +++ b/lib/autoconf/lang.m4 @@ -179,6 +179,7 @@ m4_define([AC_LANG_DEFINE], [m4_copy([AC_LANG_PROGRAM($5)], [AC_LANG_PROGRAM($1)])] [m4_copy([AC_LANG_CALL($5)], [AC_LANG_CALL($1)])] [m4_copy([AC_LANG_FUNC_LINK_TRY($5)], [AC_LANG_FUNC_LINK_TRY($1)])] +[m4_copy([AC_LANG_FUNC_LINK_TRY_GCC_BUILTIN($5)], [AC_LANG_FUNC_LINK_TRY_GCC_BUILTIN($1)])] [m4_copy([AC_LANG_BOOL_COMPILE_TRY($5)], [AC_LANG_BOOL_COMPILE_TRY($1)])] [m4_copy([AC_LANG_INT_SAVE($5)], [AC_LANG_INT_SAVE($1)])] [m4_copy([_AC_LANG_IO_PROGRAM($5)], [_AC_LANG_IO_PROGRAM($1)])])]) @@ -269,6 +270,13 @@ AC_DEFUN([AC_LANG_FUNC_LINK_TRY], _AC_LANG_DISPATCH([$0], _AC_LANG, $@)]) +# AC_LANG_FUNC_LINK_TRY_GCC_BUILTIN(FUNCTION, TYPE) +# ------------------------------- +AC_DEFUN([AC_LANG_FUNC_LINK_TRY_GCC_BUILTIN], +[m4_ifval([$1], [], [m4_warn([syntax], [$0: no function given])])dnl +_AC_LANG_DISPATCH([$0], _AC_LANG, $@)]) + + # AC_LANG_BOOL_COMPILE_TRY(PROLOGUE, EXPRESSION) # ---------------------------------------------- # Produce a program that compiles with success iff the boolean EXPRESSION -- ldv
pgpYcKed8Df7r.pgp
Description: PGP signature