Browse Source

Fix configure's AC_CHECK_DECLS tests to work correctly with clang.

The test case that Autoconf uses to discover whether a function has
been declared doesn't work reliably with clang, because clang reports
a warning not an error if the name is a known built-in function.
On some platforms, this results in a lot of compile-time warnings about
strlcpy and related functions not having been declared.

There is a fix for this (by Noah Misch) in the upstream Autoconf sources,
but since they've not made a release in years and show no indication of
doing so anytime soon, let's just absorb their fix directly.  We can
revert this when and if we update to a newer Autoconf release.

Back-patch to all supported branches.

Discussion: https://postgr.es/m/26819.1542515567@sss.pgh.pa.us
tags/REL_12_BETA1
Tom Lane 7 months ago
parent
commit
16fbac39ff
4 changed files with 223 additions and 7 deletions
  1. 1
    0
      aclocal.m4
  2. 116
    0
      config/check_decls.m4
  3. 100
    4
      configure
  4. 6
    3
      configure.in

+ 1
- 0
aclocal.m4 View File

@@ -4,6 +4,7 @@ m4_include([config/ax_prog_perl_modules.m4])
4 4
 m4_include([config/ax_pthread.m4])
5 5
 m4_include([config/c-compiler.m4])
6 6
 m4_include([config/c-library.m4])
7
+m4_include([config/check_decls.m4])
7 8
 m4_include([config/docbook.m4])
8 9
 m4_include([config/general.m4])
9 10
 m4_include([config/libtool.m4])

+ 116
- 0
config/check_decls.m4 View File

@@ -0,0 +1,116 @@
1
+# config/check_decls.m4
2
+
3
+# This file redefines the standard Autoconf macro _AC_CHECK_DECL_BODY,
4
+# and adds a supporting function _AC_UNDECLARED_WARNING, to make
5
+# AC_CHECK_DECLS behave correctly when checking for built-in library
6
+# functions with clang.
7
+
8
+# This is based on commit 82ef7805faffa151e724aa76c245ec590d174580
9
+# in the Autoconf git repository.  We can drop it if they ever get
10
+# around to releasing a new version of Autoconf.  In the meantime,
11
+# it's distributed under Autoconf's license:
12
+
13
+# This file is part of Autoconf.  This program is free
14
+# software; you can redistribute it and/or modify it under the
15
+# terms of the GNU General Public License as published by the
16
+# Free Software Foundation, either version 3 of the License, or
17
+# (at your option) any later version.
18
+#
19
+# This program is distributed in the hope that it will be useful,
20
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
+# GNU General Public License for more details.
23
+#
24
+# Under Section 7 of GPL version 3, you are granted additional
25
+# permissions described in the Autoconf Configure Script Exception,
26
+# version 3.0, as published by the Free Software Foundation.
27
+#
28
+# You should have received a copy of the GNU General Public License
29
+# and a copy of the Autoconf Configure Script Exception along with
30
+# this program; see the files COPYINGv3 and COPYING.EXCEPTION
31
+# respectively.  If not, see <http://www.gnu.org/licenses/>.
32
+
33
+# Written by David MacKenzie, with help from
34
+# Franc,ois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
35
+# Roland McGrath, Noah Friedman, david d zuhn, and many others.
36
+
37
+
38
+# _AC_UNDECLARED_WARNING
39
+# ----------------------
40
+# Set ac_[]_AC_LANG_ABBREV[]_decl_warn_flag=yes if the compiler uses a warning,
41
+# not a more-customary error, to report some undeclared identifiers.  Fail when
42
+# an affected compiler warns also on valid input.  _AC_PROG_PREPROC_WORKS_IFELSE
43
+# solves a related problem.
44
+AC_DEFUN([_AC_UNDECLARED_WARNING],
45
+[# The Clang compiler raises a warning for an undeclared identifier that matches
46
+# a compiler builtin function.  All extant Clang versions are affected, as of
47
+# Clang 3.6.0.  Test a builtin known to every version.  This problem affects the
48
+# C and Objective C languages, but Clang does report an error under C++ and
49
+# Objective C++.
50
+#
51
+# Passing -fno-builtin to the compiler would suppress this problem.  That
52
+# strategy would have the advantage of being insensitive to stray warnings, but
53
+# it would make tests less realistic.
54
+AC_CACHE_CHECK([how $[]_AC_CC[] reports undeclared, standard C functions],
55
+[ac_cv_[]_AC_LANG_ABBREV[]_decl_report],
56
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [(void) strchr;])],
57
+  [AS_IF([test -s conftest.err], [dnl
58
+    # For AC_CHECK_DECL to react to warnings, the compiler must be silent on
59
+    # valid AC_CHECK_DECL input.  No library function is consistently available
60
+    # on freestanding implementations, so test against a dummy declaration.
61
+    # Include always-available headers on the off chance that they somehow
62
+    # elicit warnings.
63
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([dnl
64
+#include <float.h>
65
+#include <limits.h>
66
+#include <stdarg.h>
67
+#include <stddef.h>
68
+extern void ac_decl (int, char *);],
69
+[@%:@ifdef __cplusplus
70
+  (void) ac_decl ((int) 0, (char *) 0);
71
+  (void) ac_decl;
72
+@%:@else
73
+  (void) ac_decl;
74
+@%:@endif
75
+])],
76
+      [AS_IF([test -s conftest.err],
77
+	[AC_MSG_FAILURE([cannot detect from compiler exit status or warnings])],
78
+	[ac_cv_[]_AC_LANG_ABBREV[]_decl_report=warning])],
79
+      [AC_MSG_FAILURE([cannot compile a simple declaration test])])],
80
+    [AC_MSG_FAILURE([compiler does not report undeclared identifiers])])],
81
+  [ac_cv_[]_AC_LANG_ABBREV[]_decl_report=error])])
82
+
83
+case $ac_cv_[]_AC_LANG_ABBREV[]_decl_report in
84
+  warning) ac_[]_AC_LANG_ABBREV[]_decl_warn_flag=yes ;;
85
+  *) ac_[]_AC_LANG_ABBREV[]_decl_warn_flag= ;;
86
+esac
87
+])# _AC_UNDECLARED_WARNING
88
+
89
+# _AC_CHECK_DECL_BODY
90
+# -------------------
91
+# Shell function body for AC_CHECK_DECL.
92
+m4_define([_AC_CHECK_DECL_BODY],
93
+[  AS_LINENO_PUSH([$[]1])
94
+  # Initialize each $ac_[]_AC_LANG_ABBREV[]_decl_warn_flag once.
95
+  AC_DEFUN([_AC_UNDECLARED_WARNING_]_AC_LANG_ABBREV,
96
+	   [_AC_UNDECLARED_WARNING])dnl
97
+  AC_REQUIRE([_AC_UNDECLARED_WARNING_]_AC_LANG_ABBREV)dnl
98
+  [as_decl_name=`echo $][2|sed 's/ *(.*//'`]
99
+  [as_decl_use=`echo $][2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`]
100
+  AC_CACHE_CHECK([whether $as_decl_name is declared], [$[]3],
101
+  [ac_save_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag
102
+  ac_[]_AC_LANG_ABBREV[]_werror_flag="$ac_[]_AC_LANG_ABBREV[]_decl_warn_flag$ac_[]_AC_LANG_ABBREV[]_werror_flag"
103
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$[]4],
104
+[@%:@ifndef $[]as_decl_name
105
+@%:@ifdef __cplusplus
106
+  (void) $[]as_decl_use;
107
+@%:@else
108
+  (void) $[]as_decl_name;
109
+@%:@endif
110
+@%:@endif
111
+])],
112
+		   [AS_VAR_SET([$[]3], [yes])],
113
+		   [AS_VAR_SET([$[]3], [no])])
114
+  ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_save_werror_flag])
115
+  AS_LINENO_POP
116
+])# _AC_CHECK_DECL_BODY

+ 100
- 4
configure View File

@@ -1756,13 +1756,16 @@ fi
1756 1756
 ac_fn_c_check_decl ()
1757 1757
 {
1758 1758
   as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
1759
-  as_decl_name=`echo $2|sed 's/ *(.*//'`
1759
+  # Initialize each $ac_[]_AC_LANG_ABBREV[]_decl_warn_flag once.
1760
+      as_decl_name=`echo $2|sed 's/ *(.*//'`
1760 1761
   as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
1761 1762
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
1762 1763
 $as_echo_n "checking whether $as_decl_name is declared... " >&6; }
1763 1764
 if eval \${$3+:} false; then :
1764 1765
   $as_echo_n "(cached) " >&6
1765 1766
 else
1767
+  ac_save_werror_flag=$ac_c_werror_flag
1768
+  ac_c_werror_flag="$ac_c_decl_warn_flag$ac_c_werror_flag"
1766 1769
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1767 1770
 /* end confdefs.h.  */
1768 1771
 $4
@@ -1787,6 +1790,7 @@ else
1787 1790
   eval "$3=no"
1788 1791
 fi
1789 1792
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
1793
+  ac_c_werror_flag=$ac_save_werror_flag
1790 1794
 fi
1791 1795
 eval ac_res=\$$3
1792 1796
 	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
@@ -4990,11 +4994,100 @@ fi
4990 4994
   test -n "$AWK" && break
4991 4995
 done
4992 4996
 
4997
+# The Clang compiler raises a warning for an undeclared identifier that matches
4998
+# a compiler builtin function.  All extant Clang versions are affected, as of
4999
+# Clang 3.6.0.  Test a builtin known to every version.  This problem affects the
5000
+# C and Objective C languages, but Clang does report an error under C++ and
5001
+# Objective C++.
5002
+#
5003
+# Passing -fno-builtin to the compiler would suppress this problem.  That
5004
+# strategy would have the advantage of being insensitive to stray warnings, but
5005
+# it would make tests less realistic.
5006
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how $CC reports undeclared, standard C functions" >&5
5007
+$as_echo_n "checking how $CC reports undeclared, standard C functions... " >&6; }
5008
+if ${ac_cv_c_decl_report+:} false; then :
5009
+  $as_echo_n "(cached) " >&6
5010
+else
5011
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
5012
+/* end confdefs.h.  */
5013
+
5014
+int
5015
+main ()
5016
+{
5017
+(void) strchr;
5018
+  ;
5019
+  return 0;
5020
+}
5021
+_ACEOF
5022
+if ac_fn_c_try_compile "$LINENO"; then :
5023
+  if test -s conftest.err; then :
5024
+      # For AC_CHECK_DECL to react to warnings, the compiler must be silent on
5025
+    # valid AC_CHECK_DECL input.  No library function is consistently available
5026
+    # on freestanding implementations, so test against a dummy declaration.
5027
+    # Include always-available headers on the off chance that they somehow
5028
+    # elicit warnings.
5029
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
5030
+/* end confdefs.h.  */
5031
+#include <float.h>
5032
+#include <limits.h>
5033
+#include <stdarg.h>
5034
+#include <stddef.h>
5035
+extern void ac_decl (int, char *);
5036
+int
5037
+main ()
5038
+{
5039
+#ifdef __cplusplus
5040
+  (void) ac_decl ((int) 0, (char *) 0);
5041
+  (void) ac_decl;
5042
+#else
5043
+  (void) ac_decl;
5044
+#endif
5045
+
5046
+  ;
5047
+  return 0;
5048
+}
5049
+_ACEOF
5050
+if ac_fn_c_try_compile "$LINENO"; then :
5051
+  if test -s conftest.err; then :
5052
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
5053
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
5054
+as_fn_error $? "cannot detect from compiler exit status or warnings
5055
+See \`config.log' for more details" "$LINENO" 5; }
5056
+else
5057
+  ac_cv_c_decl_report=warning
5058
+fi
5059
+else
5060
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
5061
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
5062
+as_fn_error $? "cannot compile a simple declaration test
5063
+See \`config.log' for more details" "$LINENO" 5; }
5064
+fi
5065
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
5066
+else
5067
+  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
5068
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
5069
+as_fn_error $? "compiler does not report undeclared identifiers
5070
+See \`config.log' for more details" "$LINENO" 5; }
5071
+fi
5072
+else
5073
+  ac_cv_c_decl_report=error
5074
+fi
5075
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
5076
+fi
5077
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_decl_report" >&5
5078
+$as_echo "$ac_cv_c_decl_report" >&6; }
5079
+
5080
+case $ac_cv_c_decl_report in
5081
+  warning) ac_c_decl_warn_flag=yes ;;
5082
+  *) ac_c_decl_warn_flag= ;;
5083
+esac
5084
+
4993 5085
 if test "$with_llvm" = yes; then :
4994 5086
 
4995 5087
 
4996 5088
 
4997 5089
 
5090
+
4998 5091
   if test -z "$LLVM_CONFIG"; then
4999 5092
   for ac_prog in llvm-config llvm-config-7 llvm-config-6.0 llvm-config-5.0 llvm-config-4.0 llvm-config-3.9
5000 5093
 do
@@ -5250,7 +5343,8 @@ _ACEOF
5250 5343
 
5251 5344
 
5252 5345
 
5253
-fi
5346
+
5347
+fi # fi
5254 5348
 
5255 5349
 
5256 5350
 unset CFLAGS
@@ -15197,7 +15291,8 @@ esac
15197 15291
 # posix_fadvise() is a no-op on Solaris, so don't incur function overhead
15198 15292
 # by calling it, 2009-04-02
15199 15293
 # http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/port/gen/posix_fadvise.c
15200
-if test "$PORTNAME" != "solaris"; then
15294
+if test "$PORTNAME" != "solaris"; then :
15295
+
15201 15296
 for ac_func in posix_fadvise
15202 15297
 do :
15203 15298
   ac_fn_c_check_func "$LINENO" "posix_fadvise" "ac_cv_func_posix_fadvise"
@@ -15221,7 +15316,8 @@ cat >>confdefs.h <<_ACEOF
15221 15316
 #define HAVE_DECL_POSIX_FADVISE $ac_have_decl
15222 15317
 _ACEOF
15223 15318
 
15224
-fi
15319
+
15320
+fi # fi
15225 15321
 
15226 15322
 ac_fn_c_check_decl "$LINENO" "fdatasync" "ac_cv_have_decl_fdatasync" "#include <unistd.h>
15227 15323
 "

+ 6
- 3
configure.in View File

@@ -392,7 +392,9 @@ PGAC_ARG_BOOL(with, llvm, no, [build with LLVM based JIT support],
392 392
               [AC_DEFINE([USE_LLVM], 1, [Define to 1 to build with LLVM based JIT support. (--with-llvm)])])
393 393
 AC_SUBST(with_llvm)
394 394
 dnl must use AS_IF here, else AC_REQUIRES inside PGAC_LLVM_SUPPORT malfunctions
395
-AS_IF([test "$with_llvm" = yes], [PGAC_LLVM_SUPPORT()])
395
+AS_IF([test "$with_llvm" = yes], [
396
+  PGAC_LLVM_SUPPORT()
397
+]) # fi
396 398
 
397 399
 
398 400
 unset CFLAGS
@@ -1640,10 +1642,11 @@ esac
1640 1642
 # posix_fadvise() is a no-op on Solaris, so don't incur function overhead
1641 1643
 # by calling it, 2009-04-02
1642 1644
 # http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/port/gen/posix_fadvise.c
1643
-if test "$PORTNAME" != "solaris"; then
1645
+dnl must use AS_IF here, else AC_REQUIRES inside AC_CHECK_DECLS malfunctions
1646
+AS_IF([test "$PORTNAME" != "solaris"], [
1644 1647
 AC_CHECK_FUNCS(posix_fadvise)
1645 1648
 AC_CHECK_DECLS(posix_fadvise, [], [], [#include <fcntl.h>])
1646
-fi
1649
+]) # fi
1647 1650
 
1648 1651
 AC_CHECK_DECLS(fdatasync, [], [], [#include <unistd.h>])
1649 1652
 AC_CHECK_DECLS([strlcat, strlcpy, strnlen])

Loading…
Cancel
Save