bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Alex Gramiak <agrambot@gmail.com>
To: bug-gnulib@gnu.org
Subject: Add new macro gl_WARN_ADD_MULTIPLE
Date: Wed, 01 May 2019 17:00:24 -0600	[thread overview]
Message-ID: <87muk5n5kn.fsf@gmail.com> (raw)

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

GNU Emacs spends about ~6s out of ~28s in its configuration process to
determine supported C compiler warnings. The attached patch introduces a
new macro, gl_WARN_ADD_MULTIPLE, that brings this down to about half a
second. This macro first checks if all the supplied warnings are
supported, and then only checks them individually (via gl_WARN_ADD) if
that check fails.

I have also attached sample files configure-prev.ac and configure-new.ac
that were extracted from Emacs's configure.ac for testing. I created a
new directory, copied m4/warnings.m4 and m4/manywarnings.m4 to a new m4
subdirectory, and ran:

  autoconf -f <sample file>

then benchmarked using:

  perf stat -r 20 ./configure

Results of configure-prev.ac:

 Performance counter stats for './configure' (20 runs):

          6,285.79 msec task-clock:u              
                 0      context-switches:u        
                 0      cpu-migrations:u          
           918,039      page-faults:u             
    11,101,658,357      cycles:u                  
    12,777,542,067      stalled-cycles-frontend:u 
    11,234,412,307      stalled-cycles-backend:u  
    14,261,222,341      instructions:u            
                                                  
     2,906,440,712      branches:u                
       100,574,333      branch-misses:u           

           6.34363 +- 0.00614 seconds time elapsed  ( +-  0.10% )


Results of configure-new.ac:

 Performance counter stats for './configure' (20 runs):

            530.29 msec task-clock:u              
                 0      context-switches:u        
                 0      cpu-migrations:u          
            72,010      page-faults:u             
       901,496,456      cycles:u                  
     1,066,313,480      stalled-cycles-frontend:u 
       949,724,068      stalled-cycles-backend:u  
     1,240,144,586      instructions:u            
                                                  
       254,307,360      branches:u                
         7,217,416      branch-misses:u           

           0.53320 +- 0.00210 seconds time elapsed  ( +-  0.39% )

Results of configure-new.ac with a forced fallback (I added a
nonexistent warning to ws):

 Performance counter stats for './configure' (20 runs):

          5,992.42 msec task-clock:u              
                 0      context-switches:u        
                 0      cpu-migrations:u          
           935,599      page-faults:u             
    11,197,607,809      cycles:u                  
    12,982,878,617      stalled-cycles-frontend:u 
    11,427,814,210      stalled-cycles-backend:u  
    14,333,736,238      instructions:u            
                                                  
     2,918,880,583      branches:u                
       100,570,882      branch-misses:u           

            6.0497 +- 0.0468 seconds time elapsed  ( +-  0.77% )


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

From ec89f6d04a6b5ac67ec787d28943e4fa4188e5f4 Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <agrambot@gmail.com>
Date: Wed, 1 May 2019 16:31:23 -0600
Subject: [PATCH] warnings: Add new macro gl_WARN_ADD_MULTIPLE

* m4/warnings.m4 (gl_WARN_ADD_MULTIPLE): New macro.
---
 ChangeLog      |  5 +++++
 m4/warnings.m4 | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index cf4116bf3..324112055 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2019-05-01  Alexander Gramiak <agrambot@gmail.com>
+
+	warnings: Add new macro gl_WARN_ADD_MULTIPLE
+	* m4/warnings.m4 (gl_WARN_ADD_MULTIPLE): New macro.
+
 2019-04-30  Paul Eggert  <eggert@cs.ucla.edu>
 
 	Sync lib/mktime-internal.h from glibc
diff --git a/m4/warnings.m4 b/m4/warnings.m4
index 235cac617..92939233d 100644
--- a/m4/warnings.m4
+++ b/m4/warnings.m4
@@ -49,6 +49,52 @@ AS_VAR_POPDEF([gl_Flags])dnl
 AS_VAR_POPDEF([gl_Warn])dnl
 ])
 
+# gl_WARN_ADD_MULTIPLE(OPTIONS, [VARIABLE = WARN_CFLAGS/WARN_CXXFLAGS],
+#                       [PROGRAM = AC_LANG_PROGRAM()])
+# -----------------------------------------------------------------
+# Check if the compiler supports OPTIONS when compiling PROGRAM
+# First check if all OPTIONS are supported together, and if not,
+# check each option individually.
+#
+# The effects of this macro depend on the current language (_AC_LANG).
+AC_DEFUN([gl_WARN_ADD_MULTIPLE],
+[
+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
+gl_positives=
+for gl_warn_item in $1; 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 $1], 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([$3], [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([$2], [], [[WARN_]_AC_LANG_PREFIX[FLAGS]], [[$2]]),
+            [" $1"])],
+          [for gl_warn_item in $1; do
+             gl_WARN_ADD([$gl_warn_item])
+           done])
+m4_popdef([gl_Positives])dnl
+AS_VAR_POPDEF([gl_Flags])dnl
+AS_VAR_POPDEF([gl_Warn])dnl
+m4_ifval([$2],
+         [AS_LITERAL_IF([$2], [AC_SUBST([$2])])],
+         [AC_SUBST([WARN_]_AC_LANG_PREFIX[FLAGS])])dnl
+])
+
 # gl_UNKNOWN_WARNINGS_ARE_ERRORS
 # ------------------------------
 # Clang doesn't complain about unknown warning options unless one also
-- 
2.21.0


[-- Attachment #3: gl_WARN_ADD --]
[-- Type: text/plain, Size: 2621 bytes --]

AC_INIT(GNU Emacs, 27.0.50, bug-gnu-emacs@gnu.org, , https://www.gnu.org/software/emacs/)
# This, $nw, is the list of warnings we disable.
nw=

nw="$nw -Wcast-align -Wcast-align=strict" # Emacs is tricky with pointers.
nw="$nw -Wduplicated-branches"    # Too many false alarms
nw="$nw -Wformat-overflow=2"      # False alarms due to GCC bug 80776
nw="$nw -Wsystem-headers"         # Don't let system headers trigger warnings
nw="$nw -Woverlength-strings"     # Not a problem these days
nw="$nw -Wformat-nonliteral"      # we do this a lot
nw="$nw -Wvla"                    # Emacs uses <vla.h>.
nw="$nw -Wunused-const-variable=2" # lisp.h declares const objects.
nw="$nw -Winline"                 # OK to ignore 'inline'
nw="$nw -Wstrict-overflow"        # OK to optimize assuming that
                                  # signed overflow has undefined behavior
nw="$nw -Wsync-nand"              # irrelevant here, and provokes ObjC warning
nw="$nw -Wunsafe-loop-optimizations" # OK to suppress unsafe optimizations
nw="$nw -Wbad-function-cast"      # These casts are no worse than others.
nw="$nw -Wabi"                    # Not useful, perceived as noise

# Emacs doesn't care about shadowing; see
# <https://lists.gnu.org/r/emacs-diffs/2011-11/msg00265.html>.
nw="$nw -Wshadow"

# Emacs's use of alloca inhibits protecting the stack.
nw="$nw -Wstack-protector"

# Emacs's use of __attribute__ ((cold)) causes false alarms with this option.
nw="$nw -Wsuggest-attribute=cold"

# Emacs's use of partly-const functions such as Fgnutls_available_p
# make this option problematic.
nw="$nw -Wsuggest-attribute=const"

# Emacs's use of partly-pure functions such as CHECK_TYPE make this
# option problematic.
nw="$nw -Wsuggest-attribute=pure"

# This part is merely for shortening the command line,
# since -Wall implies -Wswitch.
nw="$nw -Wswitch"

# This part is merely for shortening the command line,
# since -Wno-FOO needs to be added below regardless.
nw="$nw -Wmissing-field-initializers"
nw="$nw -Woverride-init"
nw="$nw -Wtype-limits"
nw="$nw -Wunused-parameter"

gl_MANYWARN_ALL_GCC([ws])
gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
for w in $ws; do
  gl_WARN_ADD([$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])

[-- Attachment #4: gl_WARN_ADD_MULTIPLE --]
[-- Type: text/plain, Size: 2597 bytes --]

AC_INIT(GNU Emacs, 27.0.50, bug-gnu-emacs@gnu.org, , https://www.gnu.org/software/emacs/)
# This, $nw, is the list of warnings we disable.
nw=

nw="$nw -Wcast-align -Wcast-align=strict" # Emacs is tricky with pointers.
nw="$nw -Wduplicated-branches"    # Too many false alarms
nw="$nw -Wformat-overflow=2"      # False alarms due to GCC bug 80776
nw="$nw -Wsystem-headers"         # Don't let system headers trigger warnings
nw="$nw -Woverlength-strings"     # Not a problem these days
nw="$nw -Wformat-nonliteral"      # we do this a lot
nw="$nw -Wvla"                    # Emacs uses <vla.h>.
nw="$nw -Wunused-const-variable=2" # lisp.h declares const objects.
nw="$nw -Winline"                 # OK to ignore 'inline'
nw="$nw -Wstrict-overflow"        # OK to optimize assuming that
                                  # signed overflow has undefined behavior
nw="$nw -Wsync-nand"              # irrelevant here, and provokes ObjC warning
nw="$nw -Wunsafe-loop-optimizations" # OK to suppress unsafe optimizations
nw="$nw -Wbad-function-cast"      # These casts are no worse than others.
nw="$nw -Wabi"                    # Not useful, perceived as noise

# Emacs doesn't care about shadowing; see
# <https://lists.gnu.org/r/emacs-diffs/2011-11/msg00265.html>.
nw="$nw -Wshadow"

# Emacs's use of alloca inhibits protecting the stack.
nw="$nw -Wstack-protector"

# Emacs's use of __attribute__ ((cold)) causes false alarms with this option.
nw="$nw -Wsuggest-attribute=cold"

# Emacs's use of partly-const functions such as Fgnutls_available_p
# make this option problematic.
nw="$nw -Wsuggest-attribute=const"

# Emacs's use of partly-pure functions such as CHECK_TYPE make this
# option problematic.
nw="$nw -Wsuggest-attribute=pure"

# This part is merely for shortening the command line,
# since -Wall implies -Wswitch.
nw="$nw -Wswitch"

# This part is merely for shortening the command line,
# since -Wno-FOO needs to be added below regardless.
nw="$nw -Wmissing-field-initializers"
nw="$nw -Woverride-init"
nw="$nw -Wtype-limits"
nw="$nw -Wunused-parameter"

gl_MANYWARN_ALL_GCC([ws])
gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])

ws="$ws -Wredundant-decls"     # Prefer this, as we don't use Bison.
ws="$ws -Wno-missing-field-initializers" # We need this one
ws="$ws -Wno-override-init"    # More trouble than it is worth
ws="$ws -Wno-sign-compare"     # Too many warnings for now
ws="$ws -Wno-type-limits"      # Too many warnings for now
ws="$ws -Wno-unused-parameter" # Too many warnings for now
ws="$ws -Wno-format-nonliteral"

dnl ws="$ws -Wbogus-warning"

gl_WARN_ADD_MULTIPLE([$ws])

             reply	other threads:[~2019-05-01 23:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-01 23:00 Alex Gramiak [this message]
2019-05-02  8:16 ` Add new macro gl_WARN_ADD_MULTIPLE Bruno Haible
2019-05-02  8:48   ` Tim Rühsen
2019-05-02 11:28     ` Bruno Haible
2019-05-02 17:39       ` Tim Rühsen
2019-05-02 19:12         ` Bruno Haible
2019-05-02 19:38           ` Tim Rühsen

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

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

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

  git send-email \
    --in-reply-to=87muk5n5kn.fsf@gmail.com \
    --to=agrambot@gmail.com \
    --cc=bug-gnulib@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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).