Muffle GCC warnings in various ways.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 19 Jun 2013 02:09:46 +0000 (03:09 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 28 Jun 2013 23:30:17 +0000 (00:30 +0100)
Some don't require much in the way of contortion to muffle without using
GCC-specific tricks.  Others are hard or impossible to avoid -- because
they're to do with macro definitions, or even actually GCC bugs (e.g.,
the array-bounds warning in `square.c') -- without just muffling the
warnings explicitly, by name.

key/key-data.h
math/mpint.h
math/mpx.c
math/pgen-simul.c
symm/rc4.c
symm/seal.c
symm/square.c

index 9c00908..cfeff82 100644 (file)
@@ -160,10 +160,26 @@ typedef struct key_filter {
   unsigned m;
 } key_filter;
 
-/* --- Matching aginst key selection --- */
+/* --- Matching aginst key selection --- *
+ *
+ * GCC will warn about constant addresses in this test, which is rather
+ * unfortunate.  Muffle the warning.  This is rather hideous because of the
+ * way GCC's parser handles pragmata.
+ */
+
+#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#  define KEY_MATCH_MUFFLE_WARNING(x) __extension__ ({                 \
+       _Pragma("GCC diagnostic push")                                  \
+       _Pragma("GCC diagnostic ignored \"-Waddress\"")                 \
+       (x);                                                            \
+       _Pragma("GCC diagnostic pop")                                   \
+   })
+#else
+#  define KEY_MATCH_MUFFLE_WARNING(x) (x)
+#endif
 
 #define KEY_MATCH(kd, kf)                                              \
-  (!(kf) ||                                                            \
+  (KEY_MATCH_MUFFLE_WARNING(!(kf)) ||                                  \
    ((kd)->e & KF_ENCMASK) == KENC_STRUCT ||                            \
    ((kd)->e & (kf)->m) == (kf)->f)
 
index 7867f6a..f551980 100644 (file)
 
 /*----- Generic translation macros ----------------------------------------*/
 
+/* --- Warning damage control --- *
+ *
+ * GCC (at least) isn't clever enough to work out that the division in
+ * @MP_FROMINT@ is actually safe (since it will only be executed if @_i >
+ * MPW_MAX@, which would prove that @(type)MPW_MAX + 1 != 0@).  So here's
+ * some machinery to shut it up.
+ */
+
+#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#  define MP_FROMINT_MUFFLE_WARNING(x) do {                            \
+       _Pragma("GCC diagnostic push")                                  \
+       _Pragma("GCC diagnostic ignored \"-Wdiv-by-zero\"")             \
+       x                                                               \
+       _Pragma("GCC diagnostic pop")                                   \
+   } while (0)
+#else
+#  define MP_FROMINT_MUFFLE_WARNING(x) do { x } while (0)
+#endif
+
 /* --- @MP_FROMINT@ --- *
  *
  * Arguments:  @d@ = destination multiprecision integer
@@ -71,7 +90,7 @@
       if (_i <= MPW_MAX)                                               \
        break;                                                          \
       else                                                             \
-       _i /= (type)MPW_MAX + 1;                                        \
+       MP_FROMINT_MUFFLE_WARNING({ _i /= (type)MPW_MAX + 1; });        \
     }                                                                  \
   } else {                                                             \
     _d->f |= MP_NEG;                                                   \
       if (_i >= -MPW_MAX)                                              \
        break;                                                          \
       else                                                             \
-       _i /= (type)MPW_MAX + 1;                                        \
+       MP_FROMINT_MUFFLE_WARNING({ _i /= (type)MPW_MAX + 1; });        \
     }                                                                  \
   }                                                                    \
                                                                        \
index 1294124..37a8a4e 100644 (file)
@@ -661,6 +661,12 @@ done:;
  * Use;                Provides the dyadic boolean functions.
  */
 
+/* GCC complains about the generated code, so try to silence it. */
+#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#  pragma GCC diagnostic push
+#  pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
+
 #define MPX_BITBINOP(string)                                           \
                                                                        \
 void mpx_bit##string(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl, \
@@ -679,6 +685,10 @@ void mpx_bit##string(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl,     \
 
 MPX_DOBIN(MPX_BITBINOP)
 
+#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#  pragma GCC diagnostic pop
+#endif
+
 void mpx_not(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl)
 {
   MPX_SHRINK(av, avl);
index 03deeb1..7321362 100644 (file)
@@ -134,7 +134,7 @@ int pgen_simultest(int rq, pgen_event *ev, void *p)
 {
   pgen_simulctx *ss = p;
   pgen_simulprime *sp;
-  int rc;
+  int rc = -1;
   unsigned i;
   mp *m;
 
index 0d02062..303b76e 100644 (file)
@@ -122,7 +122,7 @@ void rc4_encrypt(rc4_ctx *ctx, const void *src, void *dest, size_t sz)
   octet *d = dest;
 
   if (!d)
-    RC4_OPEN(ctx, while (sz) { unsigned x; RC4_BYTE(x); sz--; });
+    RC4_OPEN(ctx, while (sz) { unsigned x; RC4_BYTE(x); (void)x; sz--; });
   else if (!s)
     RC4_OPEN(ctx, while (sz) { RC4_BYTE(*d++); sz--; });
   else
index df7cd1b..da9d084 100644 (file)
@@ -58,7 +58,7 @@ const octet seal_keysz[] = { KSZ_ANY, SHA_HASHSZ };
  * Use:                Initializes a SEAL key table.
  */
 
-static void gamma(uint32 *p, size_t sz, const void *k, unsigned i)
+static void sealgamma(uint32 *p, size_t sz, const void *k, unsigned i)
 {
   uint32 buf[80] = { 0 };
   const octet *kk = k;
@@ -168,9 +168,9 @@ void seal_initkey(seal_key *k, const void *buf, size_t sz)
 
   /* --- Expand the key to fit the various tables --- */
 
-  gamma(k->t, 512, k->k, 0);
-  gamma(k->s, 256, k->k, 0x1000);
-  gamma(k->r, SEAL_R, k->k, 0x2000);
+  sealgamma(k->t, 512, k->k, 0);
+  sealgamma(k->s, 256, k->k, 0x1000);
+  sealgamma(k->r, SEAL_R, k->k, 0x2000);
 }
 
 /* --- @seal_reset@ --- *
@@ -193,7 +193,7 @@ static void seal_reset(seal_ctx *c)
   /* --- Initialize the new chaining variables --- */
 
   if (c->l >= SEAL_R) {
-    gamma(c->rbuf, SEAL_R, k->k, c->ri);
+    sealgamma(c->rbuf, SEAL_R, k->k, c->ri);
     c->ri += SEAL_R;
     c->l = 0;
     c->r = c->rbuf;
index f3056de..73b22bb 100644 (file)
@@ -92,10 +92,26 @@ void square_init(square_ctx *k, const void *buf, size_t sz)
   }
   nr = 8;
 
+  /* --- GCC complains about an out-of-bounds subscript here --- *
+   *
+   * This is impossible.  Thanks to @KSZ_ASSERT@, we know that @sz <= 16@ and
+   * hence @i <= nk <= 4@; but @SQUARE_KWORDS == 36@.
+   */
+
+#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#  pragma GCC diagnostic push
+#  pragma GCC diagnostic ignored "-Warray-bounds"
+#endif
+
+  ww = kk[i - 1];
+
+#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#  pragma GCC diagnostic pop
+#endif
+
   /* --- Expand this material to fill the rest of the table --- */
 
   nw = (nr + 1) * 4;
-  ww = kk[i - 1];
   p = RCON;
   for (; i < nw; i++) {
     uint32 w = kk[i - nk];