]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: port --enable-gcc-warnings to clang
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 19 May 2013 00:49:32 +0000 (17:49 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 19 May 2013 00:55:07 +0000 (17:55 -0700)
* configure.ac: If clang, add -Wno-format-extra-args and
-Wno-tautological-constant-out-of-range-compare.
* gl/lib/rand-isaac.c (ind):
* gl/lib/randread.c (readisaac):
* src/ls.c (dev_ino_push, dev_ino_pop):
* src/sort.c (buffer_linelim):
* src/system.h (is_nul):
* src/tail.c (tail_forever_inotify):
Rewrite to avoid casts that clang dislikes.
It's good to avoid casts anyway.
* src/expr.c (integer_overflow): Declare only if it exists.
(die): Remove; unused.
* src/ls.c (dev_ino_push): New function, replacing ...
(DEV_INO_PUSH): ... this removed macro.  All uses changed.
(decode_switches): Rewrite "str"+i to &str[i].

configure.ac
gl/lib/rand-isaac.c
gl/lib/randread.c
src/expr.c
src/ls.c
src/sort.c
src/system.h
src/tail.c

index 3f0c58b9e9c5d377568103d75976934835b04e8a..8a3ac48a01d9149cfae12d11d9a857640c26a3f1 100644 (file)
@@ -164,6 +164,21 @@ if test "$gl_gcc_warnings" = yes; then
   # gcc 4.5.0 20090517, and it provokes warnings in cat.c, dd.c, truncate.c
   gl_WARN_ADD([-Wno-logical-op])
 
+  # clang is unduly picky about some things.
+  AC_CACHE_CHECK([whether the compiler is clang], [utils_cv_clang],
+    [AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM([[
+            #ifndef __clang__
+              #error "not clang"
+            #endif
+          ]])],
+       [utils_cv_clang=yes],
+       [utils_cv_clang=no])])
+  if test $utils_cv_clang = yes; then
+    gl_WARN_ADD([-Wno-format-extra-args])
+    gl_WARN_ADD([-Wno-tautological-constant-out-of-range-compare])
+  fi
+
   gl_WARN_ADD([-fdiagnostics-show-option])
   gl_WARN_ADD([-funit-at-a-time])
 
index defd21778f2a5abb41278dba34b2d4f8e780d6a1..04af2e782a480fc406a154b42443516f30c5eb9a 100644 (file)
@@ -58,16 +58,26 @@ just (isaac_word a)
   return a & desired_bits;
 }
 
-/* The index operation.  On typical machines whose words are exactly
-   the right size, this is optimized to a mask, an addition, and an
-   indirect load.  Atypical machines need more work.  */
+/* The index operation.  */
 static inline isaac_word
 ind (isaac_word const *m, isaac_word x)
 {
-  return (sizeof *m * CHAR_BIT == ISAAC_BITS
-          ? (* (isaac_word *) ((char *) m
-                               + (x & ((ISAAC_WORDS - 1) * sizeof *m))))
-          : m[(x / (ISAAC_BITS / CHAR_BIT)) & (ISAAC_WORDS - 1)]);
+  if (sizeof *m * CHAR_BIT == ISAAC_BITS)
+    {
+      /* The typical case, where words are exactly the right size.
+         Optimize this to a mask, an addition, and an indirect
+         load.  */
+      void const *void_m = m;
+      char const *base_p = void_m;
+      void const *word_p = base_p + (x & ((ISAAC_WORDS - 1) * sizeof *m));
+      isaac_word const *p = word_p;
+      return *p;
+    }
+  else
+    {
+      /* Atypical machines need more work.  */
+      return m[(x / (ISAAC_BITS / CHAR_BIT)) & (ISAAC_WORDS - 1)];
+    }
 }
 
 /* Use and update *S to generate random data to fill RESULT.  */
index dfba61182219eb6c1f6486efe588f8d95d878bf4..8ee38475188c83a015f6b19e047d79c181e5960c 100644 (file)
@@ -275,12 +275,14 @@ readsource (struct randread_source *s, unsigned char *p, size_t size)
    the buffered ISAAC generator in ISAAC.  */
 
 static void
-readisaac (struct isaac *isaac, unsigned char *p, size_t size)
+readisaac (struct isaac *isaac, void *p, size_t size)
 {
   size_t inbytes = isaac->buffered;
 
   while (true)
     {
+      char *char_p = p;
+
       if (size <= inbytes)
         {
           memcpy (p, isaac->data.b + ISAAC_BYTES - inbytes, size);
@@ -289,14 +291,14 @@ readisaac (struct isaac *isaac, unsigned char *p, size_t size)
         }
 
       memcpy (p, isaac->data.b + ISAAC_BYTES - inbytes, inbytes);
-      p += inbytes;
+      p = char_p + inbytes;
       size -= inbytes;
 
       /* If P is aligned, write to *P directly to avoid the overhead
          of copying from the buffer.  */
       if (ALIGNED_POINTER (p, isaac_word))
         {
-          isaac_word *wp = (isaac_word *) p;
+          isaac_word *wp = p;
           while (ISAAC_BYTES <= size)
             {
               isaac_refill (&isaac->state, wp);
@@ -308,7 +310,7 @@ readisaac (struct isaac *isaac, unsigned char *p, size_t size)
                   return;
                 }
             }
-          p = (unsigned char *) wp;
+          p = wp;
         }
 
       isaac_refill (&isaac->state, isaac->data.w);
index b4fa808a02e132ab87e9f7e9cf5745ea341f9164..9d21ca87f94a270ff0bdb2d0ebec72c50767b8bf 100644 (file)
@@ -44,8 +44,6 @@
    int, the widest unsigned type that GMP supports.  */
 verify (SIZE_MAX <= ULONG_MAX);
 
-static void integer_overflow (char) ATTRIBUTE_NORETURN;
-
 #ifndef HAVE_GMP
 # define HAVE_GMP 0
 #endif
@@ -53,6 +51,7 @@ static void integer_overflow (char) ATTRIBUTE_NORETURN;
 #if HAVE_GMP
 # include <gmp.h>
 #else
+static void integer_overflow (char) ATTRIBUTE_NORETURN;
 /* Approximate gmp.h well enough for expr.c's purposes.  */
 typedef intmax_t mpz_t[1];
 static void mpz_clear (mpz_t z) { (void) z; }
@@ -278,6 +277,7 @@ syntax_error (void)
   error (EXPR_INVALID, 0, _("syntax error"));
 }
 
+#if ! HAVE_GMP
 /* Report an integer overflow for operation OP and exit.  */
 static void
 integer_overflow (char op)
@@ -285,15 +285,7 @@ integer_overflow (char op)
   error (EXPR_FAILURE, ERANGE, "%c", op);
   abort (); /* notreached */
 }
-
-static void die (int errno_val, char const *msg)
-  ATTRIBUTE_NORETURN;
-static void
-die (int errno_val, char const *msg)
-{
-  error (EXPR_FAILURE, errno_val, "%s", msg);
-  abort (); /* notreached */
-}
+#endif
 
 int
 main (int argc, char **argv)
index d9876f842794f075895a74dfc5bddf716c6c408e..72aee994f32874d9dd939683189156b15481d019 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -962,25 +962,33 @@ static struct obstack subdired_obstack;
 static struct obstack dev_ino_obstack;
 
 /* Push a pair onto the device/inode stack.  */
-#define DEV_INO_PUSH(Dev, Ino)                                         \
-  do                                                                   \
-    {                                                                  \
-      struct dev_ino *di;                                              \
-      obstack_blank (&dev_ino_obstack, sizeof (struct dev_ino));       \
-      di = -1 + (struct dev_ino *) obstack_next_free (&dev_ino_obstack); \
-      di->st_dev = (Dev);                                              \
-      di->st_ino = (Ino);                                              \
-    }                                                                  \
-  while (0)
+static void
+dev_ino_push (dev_t dev, ino_t ino)
+{
+  void *vdi;
+  struct dev_ino *di;
+  int dev_ino_size = sizeof *di;
+  obstack_blank (&dev_ino_obstack, dev_ino_size);
+  vdi = obstack_next_free (&dev_ino_obstack);
+  di = vdi;
+  di--;
+  di->st_dev = dev;
+  di->st_ino = ino;
+}
 
 /* Pop a dev/ino struct off the global dev_ino_obstack
    and return that struct.  */
 static struct dev_ino
 dev_ino_pop (void)
 {
-  assert (sizeof (struct dev_ino) <= obstack_object_size (&dev_ino_obstack));
-  obstack_blank (&dev_ino_obstack, -(int) (sizeof (struct dev_ino)));
-  return *(struct dev_ino *) obstack_next_free (&dev_ino_obstack);
+  void *vdi;
+  struct dev_ino *di;
+  int dev_ino_size = sizeof *di;
+  assert (dev_ino_size <= obstack_object_size (&dev_ino_obstack));
+  obstack_blank (&dev_ino_obstack, -dev_ino_size);
+  vdi = obstack_next_free (&dev_ino_obstack);
+  di = vdi;
+  return *di;
 }
 
 /* Note the use commented out below:
@@ -1978,7 +1986,7 @@ decode_switches (int argc, char **argv)
   if (file_type <= indicator_style)
     {
       char const *p;
-      for (p = "*=>@|" + indicator_style - file_type; *p; p++)
+      for (p = &"*=>@|"[indicator_style - file_type]; *p; p++)
         set_char_quoting (filename_quoting_options, *p, 1);
     }
 
@@ -2542,7 +2550,7 @@ print_dir (char const *name, char const *realname, bool command_line_arg)
           return;
         }
 
-      DEV_INO_PUSH (dir_stat.st_dev, dir_stat.st_ino);
+      dev_ino_push (dir_stat.st_dev, dir_stat.st_ino);
     }
 
   if (recursive || print_dir_name)
index 7410abca6e03784d26cdd497a84f1f2ca776f724..062b5f946fd4cd08dd4ac04c7cc135a2b0f366cf 100644 (file)
@@ -1557,7 +1557,8 @@ initbuf (struct buffer *buf, size_t line_bytes, size_t alloc)
 static inline struct line *
 buffer_linelim (struct buffer const *buf)
 {
-  return (struct line *) (buf->buf + buf->alloc);
+  void *linelim = buf->buf + buf->alloc;
+  return linelim;
 }
 
 /* Return a pointer to the first character of the field specified
index 94c968fbd37a9f3201346916cb6d064dba60ab5f..db8931635a45598ceff66d2f645fbbdb54f63f9c 100644 (file)
@@ -496,21 +496,24 @@ ptr_align (void const *ptr, size_t alignment)
    Note the word after the buffer must be non NUL. */
 
 static inline bool _GL_ATTRIBUTE_PURE
-is_nul (const char *buf, size_t bufsize)
+is_nul (void const *buf, size_t bufsize)
 {
   typedef uintptr_t word;
+  void const *vp;
+  char const *cbuf = buf;
+  word const *wp = buf;
 
   /* Find first nonzero *word*, or the word with the sentinel.  */
-  word *wp = (word *) buf;
   while (*wp++ == 0)
     continue;
 
   /* Find the first nonzero *byte*, or the sentinel.  */
-  char *cp = (char *) (wp - 1);
+  vp = wp - 1;
+  char const *cp = vp;
   while (*cp++ == 0)
     continue;
 
-  return cp > buf + bufsize;
+  return cbuf + bufsize < cp;
 }
 
 /* If 10*Accum + Digit_val is larger than the maximum value for Type,
index 6bbc7251f980cf01aa7cf08358f03c9ac35b0415..0f1a37c07a6945967b099df23b5e0b14994cda6f 100644 (file)
@@ -1446,6 +1446,7 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
     {
       struct File_spec *fspec;
       struct inotify_event *ev;
+      void *void_ev;
 
       /* When following by name without --retry, and the last file has
          been unlinked or renamed-away, diagnose it and return.  */
@@ -1507,7 +1508,8 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
             error (EXIT_FAILURE, errno, _("error reading inotify event"));
         }
 
-      ev = (struct inotify_event *) (evbuf + evbuf_off);
+      void_ev = evbuf + evbuf_off;
+      ev = void_ev;
       evbuf_off += sizeof (*ev) + ev->len;
 
       if (ev->len) /* event on ev->name in watched directory  */