Fix configure's AC_CHECK_DECLS tests to work correctly with clang.
authorTom Lane <[email protected]>
Wed, 21 Sep 2022 19:42:00 +0000 (15:42 -0400)
committerTom Lane <[email protected]>
Wed, 21 Sep 2022 19:42:00 +0000 (15:42 -0400)
Back-port commit 16fbac39f into 9.3 and 9.2, so that these
out-of-support branches can be built with clang without wading
through a pile of warnings about strlcpy and related functions.
check_decls.m4 required some adaptation to work with autoconf 2.63,
but nothing too major.

Discussion: https://postgr.es/m/26819.1542515567@sss.pgh.pa.us
Discussion: https://postgr.es/m/1081321.1663775084@sss.pgh.pa.us

aclocal.m4
config/check_decls.m4 [new file with mode: 0644]
configure
configure.in

index eaf98007e5b191016c8b77df02d071493ff230b9..43d908b5422904af14796ecf0821453c1960f99e 100644 (file)
@@ -3,6 +3,7 @@ m4_include([config/ac_func_accept_argtypes.m4])
 m4_include([config/acx_pthread.m4])
 m4_include([config/c-compiler.m4])
 m4_include([config/c-library.m4])
+m4_include([config/check_decls.m4])
 m4_include([config/docbook.m4])
 m4_include([config/general.m4])
 m4_include([config/libtool.m4])
diff --git a/config/check_decls.m4 b/config/check_decls.m4
new file mode 100644 (file)
index 0000000..2712daa
--- /dev/null
@@ -0,0 +1,112 @@
+# config/check_decls.m4
+
+# This file redefines the standard Autoconf macro AC_CHECK_DECL,
+# and adds a supporting function _AC_UNDECLARED_WARNING, to make
+# AC_CHECK_DECLS behave correctly when checking for built-in library
+# functions with clang.
+
+# This is based on commit 82ef7805faffa151e724aa76c245ec590d174580
+# in the Autoconf git repository, adapted to work with Autoconf 2.63.
+# It's still mostly their code, so
+# it's distributed under Autoconf's license:
+
+# This file is part of Autoconf.  This program is free
+# software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# Under Section 7 of GPL version 3, you are granted additional
+# permissions described in the Autoconf Configure Script Exception,
+# version 3.0, as published by the Free Software Foundation.
+#
+# You should have received a copy of the GNU General Public License
+# and a copy of the Autoconf Configure Script Exception along with
+# this program; see the files COPYINGv3 and COPYING.EXCEPTION
+# respectively.  If not, see <http://www.gnu.org/licenses/>.
+
+# Written by David MacKenzie, with help from
+# Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
+# Roland McGrath, Noah Friedman, david d zuhn, and many others.
+
+
+# _AC_UNDECLARED_WARNING
+# ----------------------
+# Set ac_[]_AC_LANG_ABBREV[]_decl_warn_flag=yes if the compiler uses a warning,
+# not a more-customary error, to report some undeclared identifiers.  Fail when
+# an affected compiler warns also on valid input.  _AC_PROG_PREPROC_WORKS_IFELSE
+# solves a related problem.
+AC_DEFUN([_AC_UNDECLARED_WARNING],
+[# The Clang compiler raises a warning for an undeclared identifier that matches
+# a compiler builtin function.  All extant Clang versions are affected, as of
+# Clang 3.6.0.  Test a builtin known to every version.  This problem affects the
+# C and Objective C languages, but Clang does report an error under C++ and
+# Objective C++.
+#
+# Passing -fno-builtin to the compiler would suppress this problem.  That
+# strategy would have the advantage of being insensitive to stray warnings, but
+# it would make tests less realistic.
+AC_CACHE_CHECK([how $CC reports undeclared, standard C functions],
+[ac_cv_[]_AC_LANG_ABBREV[]_decl_report],
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [(void) strchr;])],
+  [AS_IF([test -s conftest.err], [dnl
+    # For AC_CHECK_DECL to react to warnings, the compiler must be silent on
+    # valid AC_CHECK_DECL input.  No library function is consistently available
+    # on freestanding implementations, so test against a dummy declaration.
+    # Include always-available headers on the off chance that they somehow
+    # elicit warnings.
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([dnl
+#include <float.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stddef.h>
+extern void ac_decl (int, char *);],
+[@%:@ifdef __cplusplus
+  (void) ac_decl ((int) 0, (char *) 0);
+  (void) ac_decl;
+@%:@else
+  (void) ac_decl;
+@%:@endif
+])],
+      [AS_IF([test -s conftest.err],
+   [AC_MSG_FAILURE([cannot detect from compiler exit status or warnings])],
+   [ac_cv_[]_AC_LANG_ABBREV[]_decl_report=warning])],
+      [AC_MSG_FAILURE([cannot compile a simple declaration test])])],
+    [AC_MSG_FAILURE([compiler does not report undeclared identifiers])])],
+  [ac_cv_[]_AC_LANG_ABBREV[]_decl_report=error])])
+
+case $ac_cv_[]_AC_LANG_ABBREV[]_decl_report in
+  warning) ac_[]_AC_LANG_ABBREV[]_decl_warn_flag=yes ;;
+  *) ac_[]_AC_LANG_ABBREV[]_decl_warn_flag= ;;
+esac
+])# _AC_UNDECLARED_WARNING
+
+# AC_CHECK_DECL
+# -------------
+# Replace Autoconf 2.63's standard definition of AC_CHECK_DECL,
+# setting it up to treat warnings as errors if necessary.
+m4_define([AC_CHECK_DECL],
+[dnl Initialize each $ac_[]_AC_LANG_ABBREV[]_decl_warn_flag once.
+AC_DEFUN([_AC_UNDECLARED_WARNING_]_AC_LANG_ABBREV,
+         [_AC_UNDECLARED_WARNING])dnl
+AC_REQUIRE([_AC_UNDECLARED_WARNING_]_AC_LANG_ABBREV)dnl
+AS_VAR_PUSHDEF([ac_Symbol], [ac_cv_have_decl_$1])dnl
+AC_CACHE_CHECK([whether $1 is declared], [ac_Symbol],
+[ac_save_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag
+ac_[]_AC_LANG_ABBREV[]_werror_flag="$ac_[]_AC_LANG_ABBREV[]_decl_warn_flag$ac_[]_AC_LANG_ABBREV[]_werror_flag"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT([$4])],
+[#ifndef $1
+  (void) $1;
+#endif
+])],
+          [AS_VAR_SET([ac_Symbol], [yes])],
+          [AS_VAR_SET([ac_Symbol], [no])])
+ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_save_werror_flag])
+AS_VAR_IF([ac_Symbol], [yes], [$2], [$3])[]dnl
+AS_VAR_POPDEF([ac_Symbol])dnl
+])# AC_CHECK_DECL
index 50803aba6bfc52599807f7bc19ab9023084b0b0c..ba520952fd269f43b476642475a8a79dbc45898d 100755 (executable)
--- a/configure
+++ b/configure
@@ -20526,8 +20526,158 @@ esac
 # posix_fadvise() is a no-op on Solaris, so don't incur function overhead
 # by calling it, 2009-04-02
 # http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/port/gen/posix_fadvise.c
+# The Clang compiler raises a warning for an undeclared identifier that matches
+# a compiler builtin function.  All extant Clang versions are affected, as of
+# Clang 3.6.0.  Test a builtin known to every version.  This problem affects the
+# C and Objective C languages, but Clang does report an error under C++ and
+# Objective C++.
+#
+# Passing -fno-builtin to the compiler would suppress this problem.  That
+# strategy would have the advantage of being insensitive to stray warnings, but
+# it would make tests less realistic.
+{ $as_echo "$as_me:$LINENO: checking how $CC reports undeclared, standard C functions" >&5
+$as_echo_n "checking how $CC reports undeclared, standard C functions... " >&6; }
+if test "${ac_cv_c_decl_report+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+int
+main ()
+{
+(void) strchr;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+    test -z "$ac_c_werror_flag" ||
+    test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  if test -s conftest.err; then
+      # For AC_CHECK_DECL to react to warnings, the compiler must be silent on
+    # valid AC_CHECK_DECL input.  No library function is consistently available
+    # on freestanding implementations, so test against a dummy declaration.
+    # Include always-available headers on the off chance that they somehow
+    # elicit warnings.
+    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <float.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stddef.h>
+extern void ac_decl (int, char *);
+int
+main ()
+{
+#ifdef __cplusplus
+  (void) ac_decl ((int) 0, (char *) 0);
+  (void) ac_decl;
+#else
+  (void) ac_decl;
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+    test -z "$ac_c_werror_flag" ||
+    test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  if test -s conftest.err; then
+  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+{ { $as_echo "$as_me:$LINENO: error: cannot detect from compiler exit status or warnings
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: cannot detect from compiler exit status or warnings
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
+else
+  ac_cv_c_decl_report=warning
+fi
+
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+   { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+{ { $as_echo "$as_me:$LINENO: error: cannot compile a simple declaration test
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: cannot compile a simple declaration test
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+else
+  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+{ { $as_echo "$as_me:$LINENO: error: compiler does not report undeclared identifiers
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: compiler does not report undeclared identifiers
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
+fi
+
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+   ac_cv_c_decl_report=error
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_decl_report" >&5
+$as_echo "$ac_cv_c_decl_report" >&6; }
+
+case $ac_cv_c_decl_report in
+  warning) ac_c_decl_warn_flag=yes ;;
+  *) ac_c_decl_warn_flag= ;;
+esac
+
 if test "$PORTNAME" != "solaris"; then
 
+
 for ac_func in posix_fadvise
 do
 as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
@@ -20633,7 +20783,9 @@ $as_echo_n "checking whether posix_fadvise is declared... " >&6; }
 if test "${ac_cv_have_decl_posix_fadvise+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  cat >conftest.$ac_ext <<_ACEOF
+  ac_save_werror_flag=$ac_c_werror_flag
+ac_c_werror_flag="$ac_c_decl_warn_flag$ac_c_werror_flag"
+cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -20679,6 +20831,7 @@ sed 's/^/| /' conftest.$ac_ext >&5
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_c_werror_flag=$ac_save_werror_flag
 fi
 { $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_posix_fadvise" >&5
 $as_echo "$ac_cv_have_decl_posix_fadvise" >&6; }
@@ -20698,14 +20851,18 @@ _ACEOF
 fi
 
 
+
 fi
+ # fi
 
 { $as_echo "$as_me:$LINENO: checking whether fdatasync is declared" >&5
 $as_echo_n "checking whether fdatasync is declared... " >&6; }
 if test "${ac_cv_have_decl_fdatasync+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  cat >conftest.$ac_ext <<_ACEOF
+  ac_save_werror_flag=$ac_c_werror_flag
+ac_c_werror_flag="$ac_c_decl_warn_flag$ac_c_werror_flag"
+cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -20751,6 +20908,7 @@ sed 's/^/| /' conftest.$ac_ext >&5
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_c_werror_flag=$ac_save_werror_flag
 fi
 { $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_fdatasync" >&5
 $as_echo "$ac_cv_have_decl_fdatasync" >&6; }
@@ -20775,7 +20933,9 @@ $as_echo_n "checking whether strlcat is declared... " >&6; }
 if test "${ac_cv_have_decl_strlcat+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  cat >conftest.$ac_ext <<_ACEOF
+  ac_save_werror_flag=$ac_c_werror_flag
+ac_c_werror_flag="$ac_c_decl_warn_flag$ac_c_werror_flag"
+cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -20820,6 +20980,7 @@ sed 's/^/| /' conftest.$ac_ext >&5
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_c_werror_flag=$ac_save_werror_flag
 fi
 { $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_strlcat" >&5
 $as_echo "$ac_cv_have_decl_strlcat" >&6; }
@@ -20842,7 +21003,9 @@ $as_echo_n "checking whether strlcpy is declared... " >&6; }
 if test "${ac_cv_have_decl_strlcpy+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  cat >conftest.$ac_ext <<_ACEOF
+  ac_save_werror_flag=$ac_c_werror_flag
+ac_c_werror_flag="$ac_c_decl_warn_flag$ac_c_werror_flag"
+cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -20887,6 +21050,7 @@ sed 's/^/| /' conftest.$ac_ext >&5
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_c_werror_flag=$ac_save_werror_flag
 fi
 { $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_strlcpy" >&5
 $as_echo "$ac_cv_have_decl_strlcpy" >&6; }
@@ -20912,7 +21076,9 @@ $as_echo_n "checking whether F_FULLFSYNC is declared... " >&6; }
 if test "${ac_cv_have_decl_F_FULLFSYNC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  cat >conftest.$ac_ext <<_ACEOF
+  ac_save_werror_flag=$ac_c_werror_flag
+ac_c_werror_flag="$ac_c_decl_warn_flag$ac_c_werror_flag"
+cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -20958,6 +21124,7 @@ sed 's/^/| /' conftest.$ac_ext >&5
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_c_werror_flag=$ac_save_werror_flag
 fi
 { $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_F_FULLFSYNC" >&5
 $as_echo "$ac_cv_have_decl_F_FULLFSYNC" >&6; }
@@ -21408,7 +21575,9 @@ $as_echo_n "checking whether snprintf is declared... " >&6; }
 if test "${ac_cv_have_decl_snprintf+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  cat >conftest.$ac_ext <<_ACEOF
+  ac_save_werror_flag=$ac_c_werror_flag
+ac_c_werror_flag="$ac_c_decl_warn_flag$ac_c_werror_flag"
+cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -21453,6 +21622,7 @@ sed 's/^/| /' conftest.$ac_ext >&5
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_c_werror_flag=$ac_save_werror_flag
 fi
 { $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_snprintf" >&5
 $as_echo "$ac_cv_have_decl_snprintf" >&6; }
@@ -21475,7 +21645,9 @@ $as_echo_n "checking whether vsnprintf is declared... " >&6; }
 if test "${ac_cv_have_decl_vsnprintf+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  cat >conftest.$ac_ext <<_ACEOF
+  ac_save_werror_flag=$ac_c_werror_flag
+ac_c_werror_flag="$ac_c_decl_warn_flag$ac_c_werror_flag"
+cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -21520,6 +21692,7 @@ sed 's/^/| /' conftest.$ac_ext >&5
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_c_werror_flag=$ac_save_werror_flag
 fi
 { $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_vsnprintf" >&5
 $as_echo "$ac_cv_have_decl_vsnprintf" >&6; }
@@ -22583,7 +22756,9 @@ $as_echo_n "checking whether sys_siglist is declared... " >&6; }
 if test "${ac_cv_have_decl_sys_siglist+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  cat >conftest.$ac_ext <<_ACEOF
+  ac_save_werror_flag=$ac_c_werror_flag
+ac_c_werror_flag="$ac_c_decl_warn_flag$ac_c_werror_flag"
+cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
@@ -22634,6 +22809,7 @@ sed 's/^/| /' conftest.$ac_ext >&5
 fi
 
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_c_werror_flag=$ac_save_werror_flag
 fi
 { $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_sys_siglist" >&5
 $as_echo "$ac_cv_have_decl_sys_siglist" >&6; }
index 61fc5dcc1d83da59bec44324184df7af8b53fab4..93d62944db66908b99f4c40afd515d3cf89781bb 100644 (file)
@@ -1314,10 +1314,11 @@ esac
 # posix_fadvise() is a no-op on Solaris, so don't incur function overhead
 # by calling it, 2009-04-02
 # http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/port/gen/posix_fadvise.c
-if test "$PORTNAME" != "solaris"; then
+dnl must use AS_IF here, else AC_REQUIRES inside AC_CHECK_DECLS malfunctions
+AS_IF([test "$PORTNAME" != "solaris"], [
 AC_CHECK_FUNCS(posix_fadvise)
 AC_CHECK_DECLS(posix_fadvise, [], [], [#include <fcntl.h>])
-fi
+]) # fi
 
 AC_CHECK_DECLS(fdatasync, [], [], [#include <unistd.h>])
 AC_CHECK_DECLS([strlcat, strlcpy])