Sophie

Sophie

distrib > Mageia > 8 > aarch64 > by-pkgid > 989cad948401331d8daff2b8031964d3 > files > 8

autoconf-2.70-4.mga8.src.rpm

From de36ccf6637974f4faba3747813d38ee46e77d69 Mon Sep 17 00:00:00 2001
From: Zack Weinberg <zackw@panix.com>
Date: Wed, 23 Dec 2020 12:14:06 -0500
Subject: [PATCH 07/12] Use -fno-builtin, not -Werror, in AC_CHECK_DECLS
 (#110400)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

clang issues only a warning, not an error, when an undeclared
identifier that names a built-in function is used: for instance

    char *(*p)(const char *, int) = strchr;

(with no `#include <string.h>`) is an error with most compilers,
a warning with clang.  This broke the 2.69 implementation of
AC_CHECK_DECL.  In commit 82ef7805faffa151e724aa76c245ec590d174580,
we tried to work around this quirk by using -Werror, but that put us
at risk of being tripped up by other warnings.  Bug 110400 reports,
for instance, that this fragment (which is roughly what you get, after
preprocessing, when AC_CHECK_DECL is applied to a function that *is*
properly declared)

    extern void ac_decl (int, char *);
    int main (void)
    {
      (void) ac_decl;
      ;
      return 0;
    }

provokes a warning from clang (and thus an error) when -Wextra-semi-stmt
has been added to CFLAGS earlier in the configure script.  The extra
semicolon comes from AC_LANG_PROGRAM, and we can’t get rid of it
because we have no way of telling reliably when someone wrote
something like

    AC_LANG_PROGRAM([[#include <stdio.h>]],
                    [[puts("hello world")]])

with no semicolon at the end of the statement; this has been
acceptable for decades.  Besides, that’s just one warning, who knows
what compilers will start complaining about tomorrow?

So: change AC_CHECK_DECL to compile its programs with -fno-builtin,
instead, when the default compilation mode fails to detect an
undeclared strchr.  The code is restructured so that we can try other
options as well, if we find another compiler with the same quirk but
different command-line syntax.

(All of this logic is very C-family specific, but it appears to me
that AC_CHECK_DECL has never worked with other languages, so we can
continue to live with that for now.)

Fixes bug 110400; partially reverts 82ef7805faffa151e724aa76c245ec590d174580.

 * lib/autoconf/general.m4 (_AC_UNDECLARED_WARNING): Rename to
   _AC_UNDECLARED_BUILTIN.  Instead of looking at diagnostic output,
   loop trying to find a command-line option that makes the compiler
   error out on undeclared builtins.
   (_AC_CHECK_DECL_BODY): Don’t AC_REQUIRE anything here.
   Make shell code language-agnostic, except for the actual test program.
   Add arguments to the shell function for additional compiler options
   to use.
   (AC_CHECK_DECL): AC_REQUIRE _AC_UNDECLARED_BUILTIN here.
   Supply $ac_{AC_LANG_ABBREV}_undeclared_builtin_options to
   ac_fn_check_decl.

 * tests/local.at (AT_CONFIG_CMP): Update list of variables to ignore
   when comparing C and C++ configure runs.
 * tests/semantics.at (AC_CHECK_DECLS): Add memcpy and strchr to
   AC_CHECK_DECLS call for functions that may be known to the compiler.

 * doc/autoconf.texi (AC_CHECK_DECL, AC_CHECK_DECLS): Remove note
   about compiler warnings.
---
 doc/autoconf.texi       |  12 ---
 lib/autoconf/general.m4 | 158 +++++++++++++++++++++-------------------
 tests/local.at          |  10 +--
 tests/semantics.at      |  10 ++-
 4 files changed, 95 insertions(+), 95 deletions(-)

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index a67cccb2..5e17280e 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -6583,12 +6583,6 @@ parentheses for types which can be zero-initialized:
 AC_CHECK_DECL([basename(char *)])
 @end example
 
-Some compilers don't indicate every missing declaration by the error
-status.  This macro checks the standard error from such compilers and
-considers a declaration missing if any warnings have been reported.  For
-most compilers, though, warnings do not affect this macro's outcome
-unless @code{AC_LANG_WERROR} is also specified.
-
 This macro caches its result in the @code{ac_cv_have_decl_@var{symbol}}
 variable, with characters not suitable for a variable name mapped to
 underscores.
@@ -6649,12 +6643,6 @@ You fall into the second category only in extreme situations: either
 your files may be used without being configured, or they are used during
 the configuration.  In most cases the traditional approach is enough.
 
-Some compilers don't indicate every missing declaration by the error
-status.  This macro checks the standard error from such compilers and
-considers a declaration missing if any warnings have been reported.  For
-most compilers, though, warnings do not affect this macro's outcome
-unless @code{AC_LANG_WERROR} is also specified.
-
 This macro caches its results in @code{ac_cv_have_decl_@var{symbol}}
 variables, with characters not suitable for a variable name mapped to
 underscores.
diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index 16f0d074..47f7ee42 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -3046,84 +3046,89 @@ AC_DEFUN([AC_CHECK_FILES],
 ## Checking for declared symbols.  ##
 ## ------------------------------- ##
 
-
-# _AC_UNDECLARED_WARNING
+# _AC_UNDECLARED_BUILTIN
 # ----------------------
-# 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 $[]_AC_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>
+# Set ac_[]_AC_LANG_ABBREV[]_undeclared_builtin_options to any options
+# needed to make the compiler issue a hard error, not a warning, when
+# an undeclared function is used whose declaration happens to be
+# built into the compiler (e.g. 'strchr' is often known in advance to
+# the C compiler).  These options should not cause any other unrelated
+# warnings to become errors.  If no such options can be found, or if
+# they make the compiler error out on a correct program of the form
+# used by AC_CHECK_DECL, report failure.
+AC_DEFUN([_AC_UNDECLARED_BUILTIN],
+[AC_CACHE_CHECK(
+  [for $[]_AC_CC options needed to detect all undeclared functions],
+  [ac_cv_[]_AC_LANG_ABBREV[]_undeclared_builtin_options],
+  [ac_save_CFLAGS=$CFLAGS
+   ac_cv_[]_AC_LANG_ABBREV[]_undeclared_builtin_options='cannot detect'
+   for ac_arg in '' -fno-builtin; do
+     CFLAGS="$ac_save_CFLAGS $ac_arg"
+     # This test program should *not* compile successfully.
+     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [(void) strchr;])],
+       [],
+       [# This test program should compile successfully.
+        # 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(
+[[#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
+extern void ac_decl (int, char *);
+]],
+[[(void) ac_decl (0, (char *) 0);
   (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
+]])],
+         [AS_IF([test x"$ac_arg" = x],
+           [ac_cv_[]_AC_LANG_ABBREV[]_undeclared_builtin_options='none needed'],
+           [ac_cv_[]_AC_LANG_ABBREV[]_undeclared_builtin_options=$ac_arg])
+          break],
+         [])])
+    done
+    CFLAGS=$ac_save_CFLAGS
+  ])
+  AS_CASE([$ac_cv_[]_AC_LANG_ABBREV[]_undeclared_builtin_options],
+    ['cannot detect'],
+      [AC_MSG_FAILURE([cannot make $[]_AC_CC report undeclared builtins])],
+    ['none needed'],
+      [ac_[]_AC_LANG_ABBREV[]_undeclared_builtin_options=''],
+      [ac_[]_AC_LANG_ABBREV[]_undeclared_builtin_options=$ac_cv_[]_AC_LANG_ABBREV[]_undeclared_builtin_options])
+])
 
 # _AC_CHECK_DECL_BODY
 # -------------------
 # Shell function body for AC_CHECK_DECL.
+# If we are compiling C, just refer to the name of the function, so we
+# don't implicitly declare it.  However, if we are compiling C++,
+# `(void) function_name;' won't work when function_name has more than one
+# overload, we need to fabricate a function call.  Fortunately, there is
+# no such thing as an implicit function declaration in C++.
+# If the function is defined as a macro, we cannot verify its signature
+# without calling it, and it might not expand to a construct that's valid
+# as the only statement in a function body; just report it as available.
 m4_define([_AC_CHECK_DECL_BODY],
 [  AS_LINENO_PUSH([$[]1])
-  # 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_decl_name=`echo $][2|sed 's/ *(.*//'`]
-  [as_decl_use=`echo $][2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`]
-  AC_CACHE_CHECK([whether $as_decl_name is declared], [$[]3],
-  [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([$[]4],
-[@%:@ifndef $[]as_decl_name
-@%:@ifdef __cplusplus
-  (void) $[]as_decl_use;
-@%:@else
-  (void) $[]as_decl_name;
-@%:@endif
-@%:@endif
-])],
+  as_decl_name=`echo $[]2|sed 's/ *(.*//'`
+  AC_CACHE_CHECK([whether $][as_decl_name is declared], [$[]3],
+  [as_decl_use=`echo $[]2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
+  AS_VAR_COPY([ac_save_FLAGS], [$[]6])
+  AS_VAR_APPEND([$[]6], [" $[]5"])
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[$][4]],
+[[#ifndef $][as_decl_name
+#ifdef __cplusplus
+  (void) $][as_decl_use;
+#else
+  (void) $][as_decl_name;
+#endif
+#endif
+]])],
 		   [AS_VAR_SET([$[]3], [yes])],
 		   [AS_VAR_SET([$[]3], [no])])
-  ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_save_werror_flag])
+  AS_VAR_COPY([$[]6], [ac_save_FLAGS])
+])
   AS_LINENO_POP
 ])# _AC_CHECK_DECL_BODY
 
@@ -3133,18 +3138,23 @@ m4_define([_AC_CHECK_DECL_BODY],
 # -------------------------------------------------------
 # Check whether SYMBOL (a function, variable, or constant) is declared.
 AC_DEFUN([AC_CHECK_DECL],
-[AC_REQUIRE_SHELL_FN([ac_fn_]_AC_LANG_ABBREV[_check_decl],
-  [AS_FUNCTION_DESCRIBE([ac_fn_]_AC_LANG_ABBREV[_check_decl],
-    [LINENO SYMBOL VAR INCLUDES],
+[AC_REQUIRE_SHELL_FN([ac_fn_check_decl],
+  [AS_FUNCTION_DESCRIBE([ac_fn_check_decl],
+    [LINENO SYMBOL VAR INCLUDES EXTRA-OPTIONS FLAG-VAR],
     [Tests whether SYMBOL is declared in INCLUDES, setting cache variable
-     VAR accordingly.])],
+     VAR accordingly.  Pass EXTRA-OPTIONS to the compiler, using FLAG-VAR.])],
   [_$0_BODY])]dnl
+dnl Initialize each $ac_[]_AC_LANG_ABBREV[]_undeclared_builtin_options once.
+[AC_DEFUN([_AC_UNDECLARED_BUILTIN_]_AC_LANG_ABBREV,
+          [_AC_UNDECLARED_BUILTIN])]dnl
+[AC_REQUIRE([_AC_UNDECLARED_BUILTIN_]_AC_LANG_ABBREV)]dnl
 [AS_VAR_PUSHDEF([ac_Symbol], [ac_cv_have_decl_$1])]dnl
-[ac_fn_[]_AC_LANG_ABBREV[]_check_decl ]dnl
-["$LINENO" "$1" "ac_Symbol" "AS_ESCAPE([AC_INCLUDES_DEFAULT([$4])], [""])"
-AS_VAR_IF([ac_Symbol], [yes], [$2], [$3])
-AS_VAR_POPDEF([ac_Symbol])dnl
-])# AC_CHECK_DECL
+[ac_fn_check_decl ]dnl
+["$LINENO" "$1" "ac_Symbol" "AS_ESCAPE([AC_INCLUDES_DEFAULT([$4])], [""])" ]dnl
+["$ac_[]_AC_LANG_ABBREV[]_undeclared_builtin_options" "_AC_LANG_PREFIX[]FLAGS"]
+[AS_VAR_IF([ac_Symbol], [yes], [$2], [$3])]dnl
+[AS_VAR_POPDEF([ac_Symbol])]dnl
+)# AC_CHECK_DECL
 
 
 # _AC_CHECK_DECLS(SYMBOL, ACTION-IF_FOUND, ACTION-IF-NOT-FOUND,
diff --git a/tests/local.at b/tests/local.at
index 536f9a54..9ab903be 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -452,9 +452,9 @@ fi
 #   cxx: ignore all of:
 #     - CC, CPP, CCC, CXX, CXXCPP, CFLAGS, CXXFLAGS, GCC, GXX
 #     - ac_cv_env_(any of the above)_(set|value)
-#     - ac_cv_c_compiler_gnu, ac_cv_cxx_compiler_gnu
-#     - ac_cv_c_decl_report, ac_cv_cxx_decl_report
-#     - ac_cv_prog_c_*, ac_cv_prog_cxx_*,
+#     - ac_cv_(c|cxx)_compiler_gnu
+#     - ac_cv_(c|cxx)_undeclared_builtin_options
+#     - ac_cv_prog_c_*, ac_cv_prog_cxx_*
 #     - ac_cv_prog_(ac_ct_)?(CC|CXX|CPP|CXXCPP)
 #     + other ac_cv_c_* are renamed to ac_cv_cxx_*
 #     + OPENMP_CFLAGS is renamed to OPENMP_CXXFLAGS
@@ -546,8 +546,8 @@ m4_define([_AT_CONFIG_CMP_PRUNE],
 	/^ac_cv_prog_ac_ct_CXXCPP=/ d
 	/^ac_cv_c_compiler_gnu=/ d
 	/^ac_cv_cxx_compiler_gnu=/ d
-	/^ac_cv_c_decl_report=/ d
-	/^ac_cv_cxx_decl_report=/ d
+	/^ac_cv_c_undeclared_builtin_options=/ d
+	/^ac_cv_cxx_undeclared_builtin_options=/ d
 	/^ac_cv_prog_c_@<:@^=@:>@*=/ d
 	/^ac_cv_prog_cc_@<:@^=@:>@*=/ d
 	/^ac_cv_prog_cxx_@<:@^=@:>@*=/ d
diff --git a/tests/semantics.at b/tests/semantics.at
index ac7fe013..d449ce00 100644
--- a/tests/semantics.at
+++ b/tests/semantics.at
@@ -201,8 +201,7 @@ fi
 
 # AC_CHECK_DECLS
 # --------------
-# For the benefit of _AC_UNDECLARED_WARNING compilers, these INCLUDES sections
-# should not elicit warnings.
+# Check that it performs the correct actions:
 AT_CHECK_MACRO([AC_CHECK_DECLS],
 [[AC_CHECK_DECLS([yes, no, myenum, mystruct, myfunc, mymacro1, mymacro2],,,
 		 [[extern int yes;
@@ -211,8 +210,9 @@ AT_CHECK_MACRO([AC_CHECK_DECLS],
 		   extern int myfunc();
 		   #define mymacro1(arg) arg
 		   #define mymacro2]])
-  # Clang reports a warning for an undeclared builtin.
-  AC_CHECK_DECLS([strerror],,, [[]])
+  # Ensure we can detect missing declarations of functions whose
+  # signature may be built into the compiler.
+  AC_CHECK_DECLS([memcpy, strchr, strerror],,, [[]])
   # The difference in space-before-open-paren is intentional.
   AC_CHECK_DECLS([basenam (char *), dirnam(char *),
 		  moreargs (char, short, int, long, void *, char *, float, double)],,,
@@ -248,6 +248,7 @@ AT_CHECK_MACRO([AC_CHECK_DECLS],
 [AT_CHECK_DEFINES(
 [#define HAVE_DECL_BASENAM 1
 #define HAVE_DECL_DIRNAM 0
+#define HAVE_DECL_MEMCPY 0
 #define HAVE_DECL_MOREARGS 1
 #define HAVE_DECL_MYENUM 1
 #define HAVE_DECL_MYFUNC 1
@@ -255,6 +256,7 @@ AT_CHECK_MACRO([AC_CHECK_DECLS],
 #define HAVE_DECL_MYMACRO2 1
 #define HAVE_DECL_MYSTRUCT 1
 #define HAVE_DECL_NO 0
+#define HAVE_DECL_STRCHR 0
 #define HAVE_DECL_STRERROR 0
 #define HAVE_DECL_YES 1
 ])])
-- 
2.30.0