bug-gzip
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/5] maint: merge build improvements from coreutils


From: Paul Eggert
Subject: [PATCH 4/5] maint: merge build improvements from coreutils
Date: Fri, 16 Nov 2012 13:50:08 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121029 Thunderbird/16.0.2

* configure.ac: Invoke gl_ASSERT_NO_GNULIB_POSIXCHECK.
(--enable-gcc-warnings): Change help message.
(gl_GCC_VERSION_IFELSE): New macro.
Do not omit -Wunused-macros for main code.
Adjust other -W options as per coreutils.
* lib/Makefile.am (AM_CFLAGS): Use GNULIB_WARN_CFLAGS, not WARN_CFLAGS.
* unlzw.c (REGISTERS, REG1, REG2, ..., REG16): Remove.
All uses removed.  These provoked -Wunused-macros warnings.
This sort of fiddling with registers hasn't been needed for years.
---
 configure.ac    |  71 +++++++++++++++++++++++++++------
 lib/Makefile.am |   2 +-
 unlzw.c         | 120 +++++++++-----------------------------------------------
 3 files changed, 78 insertions(+), 115 deletions(-)

diff --git a/configure.ac b/configure.ac
index 64112da..a73d5a5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,6 +30,20 @@ AC_CONFIG_HEADERS([lib/config.h:lib/config.hin])
 AM_INIT_AUTOMAKE([1.11 dist-xz color-tests parallel-tests])
 AM_SILENT_RULES([yes]) # make --enable-silent-rules the default.
 
+dnl POSIXCHECK is worthwhile for maintainers, but adds several seconds
+dnl (more than 10% execution time) to ./configure, with no benefit for
+dnl most users.  Using it to look for bugs requires:
+dnl   GNULIB_POSIXCHECK=1 autoreconf -f
+dnl   ./configure
+dnl   make
+dnl   make -C src clean
+dnl   make CFLAGS=-DGNULIB_POSIXCHECK=1
+dnl FIXME: Once we figure out how to avoid false positives, we should
+dnl have 'make my-distcheck' in dist-check.mk exercise this.
+m4_syscmd([test "${GNULIB_POSIXCHECK+set}" = set])
+m4_if(m4_sysval, [0], [], [dnl
+gl_ASSERT_NO_GNULIB_POSIXCHECK])
+
 AC_PROG_CC_STDC
 AM_PROG_CC_C_O
 AC_PROG_CPP
@@ -45,7 +59,7 @@ gl_INIT
 
 AC_ARG_ENABLE([gcc-warnings],
   [AS_HELP_STRING([--enable-gcc-warnings],
-                  [turn on lots of GCC warnings (for developers)])],
+     [turn on many GCC warnings (for developers; best with GNU make)])],
   [case $enableval in
      yes|no) ;;
      *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
@@ -58,6 +72,24 @@ AC_ARG_ENABLE([gcc-warnings],
    fi]
 )
 
+# gl_GCC_VERSION_IFELSE([major], [minor], [run-if-found], [run-if-not-found])
+# ------------------------------------------------
+# If $CPP is gcc-MAJOR.MINOR or newer, then run RUN-IF-FOUND.
+# Otherwise, run RUN-IF-NOT-FOUND.
+AC_DEFUN([gl_GCC_VERSION_IFELSE],
+  [AC_PREPROC_IFELSE(
+    [AC_LANG_PROGRAM(
+      [[
+#if ($1) < __GNUC__ || (($1) == __GNUC__ && ($2) <= __GNUC_MINOR__)
+/* ok */
+#else
+# error "your version of gcc is older than $1.$2"
+#endif
+      ]]),
+    ], [$3], [$4])
+  ]
+)
+
 if test "$gl_gcc_warnings" = yes; then
   gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
   AC_SUBST([WERROR_CFLAGS])
@@ -90,26 +122,34 @@ if test "$gl_gcc_warnings" = yes; then
   nw="$nw -Wmissing-format-attribute" # copy.c
   nw="$nw -Wunsafe-loop-optimizations" # a few src/*.c
   nw="$nw -Winline"                 # system.h's 
readdir_ignoring_dot_and_dotdot
-  nw="$nw -Wstrict-overflow"        # expr.c, pr.c, tr.c, factor.c
-  # initial problems in gzip
+
+  # Warnings that gzip runs afoul of but coreutils does not.
   nw="$nw -Wold-style-definition"
   nw="$nw -Wshadow"
-  nw="$nw -Wunused-macros"
-  # ?? -Wstrict-overflow
+  nw="$nw -Wstrict-overflow"
+
+  # Using -Wstrict-overflow is a pain, but the alternative is worse.
+  # For an example, see the code that provoked this report:
+  # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33498
+  # Code like that still infloops with gcc-4.6.0 and -O2.  Scary indeed.
 
   gl_MANYWARN_ALL_GCC([ws])
   gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
   for w in $ws; do
     gl_WARN_ADD([$w])
   done
-  gl_WARN_ADD([-Wno-missing-field-initializers]) # We need this one
   gl_WARN_ADD([-Wno-sign-compare])     # Too many warnings for now
-  gl_WARN_ADD([-Wno-pointer-sign])     # Too many warnings for now
   gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now
-  gl_WARN_ADD([-Wno-overflow])         # util.c
-  gl_WARN_ADD([-Wno-type-limits])      # util.c
+  gl_WARN_ADD([-Wsuggest-attribute=const])
+  gl_WARN_ADD([-Wsuggest-attribute=noreturn])
   gl_WARN_ADD([-Wno-format-nonliteral])
-  gl_WARN_ADD([-Wno-unsuffixed-float-constants])
+
+  # Enable this warning only with gcc-4.7 and newer.  With 4.6.2 20111027,
+  # it suggests test.c's advance function may be pure, even though it
+  # increments a global variable.  Oops.
+  # Normally we'd write code to test for the precise failure, but that
+  # requires a relatively large input to make gcc exhibit the failure.
+  gl_GCC_VERSION_IFELSE([4], [7], [gl_WARN_ADD([-Wsuggest-attribute=pure])])
 
   # In spite of excluding -Wlogical-op above, it is enabled, as of
   # gcc 4.5.0 20090517, and it provokes warnings in cat.c, dd.c, truncate.c
@@ -121,14 +161,21 @@ if test "$gl_gcc_warnings" = yes; then
   AC_SUBST([WARN_CFLAGS])
 
   AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
-  AC_DEFINE([_FORTIFY_SOURCE], [2],
-    [enable compile-time and run-time bounds-checking, and some warnings])
+  AH_VERBATIM([FORTIFY_SOURCE],
+  [/* Enable compile-time and run-time bounds-checking, and some warnings,
+      without upsetting glibc 2.15+. */
+   #if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__
+   # define _FORTIFY_SOURCE 2
+   #endif
+  ])
   AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
 
   # We use a slightly smaller set of warning options for lib/.
   # Remove the following and save the result in GNULIB_WARN_CFLAGS.
   nw=
+  nw="$nw -Wstrict-overflow"
   nw="$nw -Wuninitialized"
+  nw="$nw -Wunused-macros"
   nw="$nw -Wmissing-prototypes"
   nw="$nw -Wold-style-definition"
   gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw])
diff --git a/lib/Makefile.am b/lib/Makefile.am
index f31fd9a..5bc40eb 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -29,7 +29,7 @@ include gnulib.mk
 
 libgzip_a_LIBADD += $(LIBOBJS)
 libgzip_a_DEPENDENCIES += $(LIBOBJS)
-AM_CFLAGS += $(WARN_CFLAGS) $(WERROR_CFLAGS)
+AM_CFLAGS += $(GNULIB_WARN_CFLAGS) $(WERROR_CFLAGS)
 
 match.$(OBJEXT): match.c
        $(AM_V_GEN)cp $(srcdir)/match.c _match.S
diff --git a/unlzw.c b/unlzw.c
index 63f941c..994a86b 100644
--- a/unlzw.c
+++ b/unlzw.c
@@ -24,90 +24,6 @@ typedef unsigned long        cmp_code_int;
 
 #define MAXCODE(n)     (1L << (n))
 
-#ifndef        REGISTERS
-#      define  REGISTERS       2
-#endif
-#define        REG1
-#define        REG2
-#define        REG3
-#define        REG4
-#define        REG5
-#define        REG6
-#define        REG7
-#define        REG8
-#define        REG9
-#define        REG10
-#define        REG11
-#define        REG12
-#define        REG13
-#define        REG14
-#define        REG15
-#define        REG16
-#if REGISTERS >= 1
-#      undef   REG1
-#      define  REG1    register
-#endif
-#if REGISTERS >= 2
-#      undef   REG2
-#      define  REG2    register
-#endif
-#if REGISTERS >= 3
-#      undef   REG3
-#      define  REG3    register
-#endif
-#if REGISTERS >= 4
-#      undef   REG4
-#      define  REG4    register
-#endif
-#if REGISTERS >= 5
-#      undef   REG5
-#      define  REG5    register
-#endif
-#if REGISTERS >= 6
-#      undef   REG6
-#      define  REG6    register
-#endif
-#if REGISTERS >= 7
-#      undef   REG7
-#      define  REG7    register
-#endif
-#if REGISTERS >= 8
-#      undef   REG8
-#      define  REG8    register
-#endif
-#if REGISTERS >= 9
-#      undef   REG9
-#      define  REG9    register
-#endif
-#if REGISTERS >= 10
-#      undef   REG10
-#      define  REG10   register
-#endif
-#if REGISTERS >= 11
-#      undef   REG11
-#      define  REG11   register
-#endif
-#if REGISTERS >= 12
-#      undef   REG12
-#      define  REG12   register
-#endif
-#if REGISTERS >= 13
-#      undef   REG13
-#      define  REG13   register
-#endif
-#if REGISTERS >= 14
-#      undef   REG14
-#      define  REG14   register
-#endif
-#if REGISTERS >= 15
-#      undef   REG15
-#      define  REG15   register
-#endif
-#if REGISTERS >= 16
-#      undef   REG16
-#      define  REG16   register
-#endif
-
 #ifndef        BYTEORDER
 #      define  BYTEORDER       0000
 #endif
@@ -146,7 +62,7 @@ union        bytes {
    }
 #else
 #  define input(b,o,c,n,m){ \
-     REG1 char_type *p = &(b)[(o)>>3]; \
+     char_type *p = &(b)[(o)>>3]; \
      (c) = ((((long)(p[0]))|((long)(p[1])<<8)| \
      ((long)(p[2])<<16))>>((o)&0x7))&(m); \
      (o) += (n); \
@@ -183,21 +99,21 @@ int block_mode = BLOCK_MODE; /* block compress mode -C 
compatible with 2.0 */
 int unlzw(in, out)
     int in, out;    /* input and output file descriptors */
 {
-    REG2   char_type  *stackp;
-    REG3   code_int   code;
-    REG4   int        finchar;
-    REG5   code_int   oldcode;
-    REG6   code_int   incode;
-    REG7   long       inbits;
-    REG8   long       posbits;
-    REG9   int        outpos;
-/*  REG10  int        insize; (global) */
-    REG11  unsigned   bitmask;
-    REG12  code_int   free_ent;
-    REG13  code_int   maxcode;
-    REG14  code_int   maxmaxcode;
-    REG15  int        n_bits;
-    REG16  int        rsize;
+    char_type  *stackp;
+    code_int   code;
+    int        finchar;
+    code_int   oldcode;
+    code_int   incode;
+    long       inbits;
+    long       posbits;
+    int        outpos;
+/*  int        insize; (global) */
+    unsigned   bitmask;
+    code_int   free_ent;
+    code_int   maxcode;
+    code_int   maxmaxcode;
+    int        n_bits;
+    int        rsize;
 
 #ifdef MAXSEG_64K
     tab_prefix[0] = tab_prefix0;
@@ -235,7 +151,7 @@ int unlzw(in, out)
         tab_suffixof(code) = (char_type)code;
     }
     do {
-        REG1 int i;
+        int i;
         int  e;
         int  o;
 
@@ -329,7 +245,7 @@ int unlzw(in, out)
 
             /* And put them out in forward order */
             {
-                REG1 int       i;
+                int i;
 
                 if (outpos+(i = (de_stack-stackp)) >= OUTBUFSIZ) {
                     do {
-- 
1.7.11.7




reply via email to

[Prev in Thread] Current Thread [Next in Thread]