all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alex Gramiak <agrambot@gmail.com>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: emacs-devel@gnu.org
Subject: Re: Checking all C warning flags at once during configuration
Date: Tue, 30 Apr 2019 12:52:21 -0600	[thread overview]
Message-ID: <87y33rmil6.fsf@gmail.com> (raw)
In-Reply-To: <55b92b63-d99d-fd5d-f6f0-58d8aec57f6a@cs.ucla.edu> (Paul Eggert's message of "Mon, 29 Apr 2019 12:39:10 -0700")

[-- Attachment #1: Type: text/plain, Size: 672 bytes --]

Paul Eggert <eggert@cs.ucla.edu> writes:

> On 4/29/19 7:53 AM, Alex Gramiak wrote:
>> would it make sense to first check _all_ (or, at least the
>> commonly supported) warning flags simultaneously and then only check
>> them individually if there was an error?
>
> Sure. That would be a nice thing to add to Gnulib (which is the upstream
> source for this).

Evidently I don't know enough autoconf to be able to do this myself,
since I couldn't figure out how to implement the fallback behaviour.
I've included a diff below that implements multiple-checking (~29s to
~22s configure time for me), with a faulty loop in the else clause
commented out. Is this salvageable?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: nocheck --]
[-- Type: text/x-patch, Size: 5507 bytes --]

diff --git a/configure.ac b/configure.ac
index 79fe0c98c6..0be51e0236 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1011,10 +1011,10 @@ AC_DEFUN
   AS_IF([test "$emacs_cv_clang" = yes],
    [
      # Turn off some warnings if supported.
-     gl_WARN_ADD([-Wno-switch])
-     gl_WARN_ADD([-Wno-pointer-sign])
-     gl_WARN_ADD([-Wno-string-plus-int])
-     gl_WARN_ADD([-Wno-unknown-attributes])
+     gl_WARN_ADD_NOCHECK([-Wno-switch])
+     gl_WARN_ADD_NOCHECK([-Wno-pointer-sign])
+     gl_WARN_ADD_NOCHECK([-Wno-string-plus-int])
+     gl_WARN_ADD_NOCHECK([-Wno-unknown-attributes])
    ])
  ],[
   isystem='-isystem '
@@ -1091,25 +1091,25 @@ AC_DEFUN
   gl_MANYWARN_ALL_GCC([ws])
   gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
   for w in $ws; do
-    gl_WARN_ADD([$w])
+    gl_WARN_ADD_NOCHECK([$w])
   done
-  gl_WARN_ADD([-Wredundant-decls])     # Prefer this, as we don't use Bison.
-  gl_WARN_ADD([-Wno-missing-field-initializers]) # We need this one
-  gl_WARN_ADD([-Wno-override-init])    # More trouble than it is worth
-  gl_WARN_ADD([-Wno-sign-compare])     # Too many warnings for now
-  gl_WARN_ADD([-Wno-type-limits])      # Too many warnings for now
-  gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now
-  gl_WARN_ADD([-Wno-format-nonliteral])
+  gl_WARN_ADD_NOCHECK([-Wredundant-decls])     # Prefer this, as we don't use Bison.
+  gl_WARN_ADD_NOCHECK([-Wno-missing-field-initializers]) # We need this one
+  gl_WARN_ADD_NOCHECK([-Wno-override-init])    # More trouble than it is worth
+  gl_WARN_ADD_NOCHECK([-Wno-sign-compare])     # Too many warnings for now
+  gl_WARN_ADD_NOCHECK([-Wno-type-limits])      # Too many warnings for now
+  gl_WARN_ADD_NOCHECK([-Wno-unused-parameter]) # Too many warnings for now
+  gl_WARN_ADD_NOCHECK([-Wno-format-nonliteral])
 
   # clang is unduly picky about some things.
   if test "$emacs_cv_clang" = yes; then
-    gl_WARN_ADD([-Wno-missing-braces])
-    gl_WARN_ADD([-Wno-null-pointer-arithmetic])
+    gl_WARN_ADD_NOCHECK([-Wno-missing-braces])
+    gl_WARN_ADD_NOCHECK([-Wno-null-pointer-arithmetic])
   fi
 
   # This causes too much noise in the MinGW build
   if test $opsys = mingw32; then
-    gl_WARN_ADD([-Wno-pointer-sign])
+    gl_WARN_ADD_NOCHECK([-Wno-pointer-sign])
   fi
 
   AC_DEFINE([GCC_LINT], [1], [Define to 1 if --enable-gcc-warnings.])
@@ -1127,11 +1127,13 @@ AC_DEFUN
 # clang is picky about these regardless of whether
 # --enable-gcc-warnings is specified.
 if test "$emacs_cv_clang" = yes; then
-  gl_WARN_ADD([-Wno-initializer-overrides])
-  gl_WARN_ADD([-Wno-tautological-compare])
-  gl_WARN_ADD([-Wno-tautological-constant-out-of-range-compare])
+  gl_WARN_ADD_NOCHECK([-Wno-initializer-overrides])
+  gl_WARN_ADD_NOCHECK([-Wno-tautological-compare])
+  gl_WARN_ADD_NOCHECK([-Wno-tautological-constant-out-of-range-compare])
 fi
 
+gl_COMPILER_OPTIONS_CHECK
+
 # Use a slightly smaller set of warning options for lib/.
 nw=
 nw="$nw -Wunused-macros"
diff --git a/m4/warnings.m4 b/m4/warnings.m4
index 235cac6171..4d8831cd59 100644
--- a/m4/warnings.m4
+++ b/m4/warnings.m4
@@ -49,6 +49,53 @@ AC_DEFUN
 AS_VAR_POPDEF([gl_Warn])dnl
 ])
 
+# gl_COMPILER_OPTIONS_CHECK([VARIABLE = WARN_CFLAGS/WARN_CXXFLAGS],
+#                            [PROGRAM = AC_LANG_PROGRAM()])
+# -----------------------------------------------------------------
+# Check if the compiler supports OPTIONS when compiling PROGRAM.
+#
+# The effects of this macro depend on the current language (_AC_LANG).
+AC_DEFUN([gl_COMPILER_OPTIONS_CHECK],
+[
+dnl FIXME: gl_Warn must be used unquoted until we can assume Autoconf
+dnl 2.64 or newer.
+AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_[]_AC_LANG_ABBREV[]_$1])dnl
+AS_VAR_PUSHDEF([gl_Flags], [_AC_LANG_PREFIX[]FLAGS])dnl
+AS_VAR_PUSHDEF([gl_warnings], [[WARN_]_AC_LANG_PREFIX[FLAGS_ONCE]])dnl
+gl_positives=
+for gl_warn_item in $gl_warnings; do
+  case $gl_warn_item in
+    -Wno-*) gl_positives="$gl_positives -W`expr "X$gl_warn_item" : 'X-Wno-\(.*\)'`" ;;
+    *) gl_positives="$gl_positives $gl_warn_item"
+  esac
+done
+m4_pushdef([gl_Positives], [$gl_positives])dnl
+AC_CACHE_CHECK([whether _AC_LANG compiler handles $gl_warnings], m4_defn([gl_Warn]), [
+  gl_save_compiler_FLAGS="$gl_Flags"
+  gl_AS_VAR_APPEND(m4_defn([gl_Flags]),
+    [" $gl_unknown_warnings_are_errors ]m4_defn([gl_Positives])["])
+  AC_LINK_IFELSE([m4_default([$2], [AC_LANG_PROGRAM([])])],
+                 [AS_VAR_SET(gl_Warn, [yes])],
+                 [AS_VAR_SET(gl_Warn, [no])])
+  gl_Flags="$gl_save_compiler_FLAGS"
+])
+AS_VAR_IF(gl_Warn,
+          [yes],
+          [gl_AS_VAR_APPEND(m4_if([$1], [], [[WARN_]_AC_LANG_PREFIX[FLAGS]], [[$1]]),
+            [" $gl_warnings"])],
+          dnl [for gl_warn_item in $gl_warnings; do
+          dnl    gl_WARN_ADD (gl_warn_item, [$1], [$2])
+          dnl  done
+          dnl ]
+          [echo ":("]
+          )
+m4_popdef([gl_Positives])dnl
+AS_VAR_POPDEF([gl_warnings])dnl
+AS_VAR_POPDEF([gl_Flags])dnl
+AS_VAR_POPDEF([gl_Warn])dnl
+AC_SUBST([WARN_]_AC_LANG_PREFIX[FLAGS])
+])
+
 # gl_UNKNOWN_WARNINGS_ARE_ERRORS
 # ------------------------------
 # Clang doesn't complain about unknown warning options unless one also
@@ -110,6 +157,11 @@ AC_DEFUN
          [AC_SUBST([WARN_]_AC_LANG_PREFIX[FLAGS])])dnl
 ])
 
+AC_DEFUN([gl_WARN_ADD_NOCHECK],
+[AC_REQUIRE([gl_UNKNOWN_WARNINGS_ARE_ERRORS(]_AC_LANG[)])
+gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_]_AC_LANG_PREFIX[FLAGS_ONCE]], [[$2]]), [" $1"])
+])
+
 # Local Variables:
 # mode: autoconf
 # End:

  reply	other threads:[~2019-04-30 18:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-29 14:53 Checking all C warning flags at once during configuration Alex Gramiak
2019-04-29 19:39 ` Paul Eggert
2019-04-30 18:52   ` Alex Gramiak [this message]
2019-04-30 19:38     ` Paul Eggert
2019-05-01 18:25       ` Alex Gramiak
2019-05-01 18:31         ` Paul Eggert
2019-05-01 23:13           ` Alex Gramiak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y33rmil6.fsf@gmail.com \
    --to=agrambot@gmail.com \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.