Skip to content

Commit 8af1511

Browse files
committed
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
1 parent b9cce9d commit 8af1511

File tree

4 files changed

+217
-5
lines changed

4 files changed

+217
-5
lines changed

aclocal.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ m4_include([config/ac_func_accept_argtypes.m4])
33
m4_include([config/ax_pthread.m4])
44
m4_include([config/c-compiler.m4])
55
m4_include([config/c-library.m4])
6+
m4_include([config/check_decls.m4])
67
m4_include([config/docbook.m4])
78
m4_include([config/general.m4])
89
m4_include([config/libtool.m4])

config/check_decls.m4

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

configure

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,13 +2287,16 @@ rm -f conftest.val
22872287
ac_fn_c_check_decl ()
22882288
{
22892289
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
2290-
as_decl_name=`echo $2|sed 's/ *(.*//'`
2290+
# Initialize each $ac_[]_AC_LANG_ABBREV[]_decl_warn_flag once.
2291+
as_decl_name=`echo $2|sed 's/ *(.*//'`
22912292
as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
22922293
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
22932294
$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
22942295
if eval \${$3+:} false; then :
22952296
$as_echo_n "(cached) " >&6
22962297
else
2298+
ac_save_werror_flag=$ac_c_werror_flag
2299+
ac_c_werror_flag="$ac_c_decl_warn_flag$ac_c_werror_flag"
22972300
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
22982301
/* end confdefs.h. */
22992302
$4
@@ -2318,6 +2321,7 @@ else
23182321
eval "$3=no"
23192322
fi
23202323
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
2324+
ac_c_werror_flag=$ac_save_werror_flag
23212325
fi
23222326
eval ac_res=\$$3
23232327
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
@@ -12755,7 +12759,96 @@ esac
1275512759
# posix_fadvise() is a no-op on Solaris, so don't incur function overhead
1275612760
# by calling it, 2009-04-02
1275712761
# http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/port/gen/posix_fadvise.c
12758-
if test "$PORTNAME" != "solaris"; then
12762+
# The Clang compiler raises a warning for an undeclared identifier that matches
12763+
# a compiler builtin function. All extant Clang versions are affected, as of
12764+
# Clang 3.6.0. Test a builtin known to every version. This problem affects the
12765+
# C and Objective C languages, but Clang does report an error under C++ and
12766+
# Objective C++.
12767+
#
12768+
# Passing -fno-builtin to the compiler would suppress this problem. That
12769+
# strategy would have the advantage of being insensitive to stray warnings, but
12770+
# it would make tests less realistic.
12771+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how $CC reports undeclared, standard C functions" >&5
12772+
$as_echo_n "checking how $CC reports undeclared, standard C functions... " >&6; }
12773+
if ${ac_cv_c_decl_report+:} false; then :
12774+
$as_echo_n "(cached) " >&6
12775+
else
12776+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
12777+
/* end confdefs.h. */
12778+
12779+
int
12780+
main ()
12781+
{
12782+
(void) strchr;
12783+
;
12784+
return 0;
12785+
}
12786+
_ACEOF
12787+
if ac_fn_c_try_compile "$LINENO"; then :
12788+
if test -s conftest.err; then :
12789+
# For AC_CHECK_DECL to react to warnings, the compiler must be silent on
12790+
# valid AC_CHECK_DECL input. No library function is consistently available
12791+
# on freestanding implementations, so test against a dummy declaration.
12792+
# Include always-available headers on the off chance that they somehow
12793+
# elicit warnings.
12794+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
12795+
/* end confdefs.h. */
12796+
#include <float.h>
12797+
#include <limits.h>
12798+
#include <stdarg.h>
12799+
#include <stddef.h>
12800+
extern void ac_decl (int, char *);
12801+
int
12802+
main ()
12803+
{
12804+
#ifdef __cplusplus
12805+
(void) ac_decl ((int) 0, (char *) 0);
12806+
(void) ac_decl;
12807+
#else
12808+
(void) ac_decl;
12809+
#endif
12810+
12811+
;
12812+
return 0;
12813+
}
12814+
_ACEOF
12815+
if ac_fn_c_try_compile "$LINENO"; then :
12816+
if test -s conftest.err; then :
12817+
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
12818+
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
12819+
as_fn_error $? "cannot detect from compiler exit status or warnings
12820+
See \`config.log' for more details" "$LINENO" 5; }
12821+
else
12822+
ac_cv_c_decl_report=warning
12823+
fi
12824+
else
12825+
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
12826+
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
12827+
as_fn_error $? "cannot compile a simple declaration test
12828+
See \`config.log' for more details" "$LINENO" 5; }
12829+
fi
12830+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
12831+
else
12832+
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
12833+
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
12834+
as_fn_error $? "compiler does not report undeclared identifiers
12835+
See \`config.log' for more details" "$LINENO" 5; }
12836+
fi
12837+
else
12838+
ac_cv_c_decl_report=error
12839+
fi
12840+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
12841+
fi
12842+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_decl_report" >&5
12843+
$as_echo "$ac_cv_c_decl_report" >&6; }
12844+
12845+
case $ac_cv_c_decl_report in
12846+
warning) ac_c_decl_warn_flag=yes ;;
12847+
*) ac_c_decl_warn_flag= ;;
12848+
esac
12849+
12850+
if test "$PORTNAME" != "solaris"; then :
12851+
1275912852
for ac_func in posix_fadvise
1276012853
do :
1276112854
ac_fn_c_check_func "$LINENO" "posix_fadvise" "ac_cv_func_posix_fadvise"
@@ -12779,7 +12872,8 @@ cat >>confdefs.h <<_ACEOF
1277912872
#define HAVE_DECL_POSIX_FADVISE $ac_have_decl
1278012873
_ACEOF
1278112874

12782-
fi
12875+
12876+
fi # fi
1278312877

1278412878
ac_fn_c_check_decl "$LINENO" "fdatasync" "ac_cv_have_decl_fdatasync" "#include <unistd.h>
1278512879
"

configure.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,10 +1519,11 @@ esac
15191519
# posix_fadvise() is a no-op on Solaris, so don't incur function overhead
15201520
# by calling it, 2009-04-02
15211521
# http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/port/gen/posix_fadvise.c
1522-
if test "$PORTNAME" != "solaris"; then
1522+
dnl must use AS_IF here, else AC_REQUIRES inside AC_CHECK_DECLS malfunctions
1523+
AS_IF([test "$PORTNAME" != "solaris"], [
15231524
AC_CHECK_FUNCS(posix_fadvise)
15241525
AC_CHECK_DECLS(posix_fadvise, [], [], [#include <fcntl.h>])
1525-
fi
1526+
]) # fi
15261527

15271528
AC_CHECK_DECLS(fdatasync, [], [], [#include <unistd.h>])
15281529
AC_CHECK_DECLS([strlcat, strlcpy])

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy