From aa02ed367404c659ab7205ef9662ef92032d7786 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 19 Jun 2013 03:09:46 +0100 Subject: [PATCH] Muffle GCC warnings in various ways. 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 | 20 ++++++++++++++++++-- math/mpint.h | 23 +++++++++++++++++++++-- math/mpx.c | 10 ++++++++++ math/pgen-simul.c | 2 +- symm/rc4.c | 2 +- symm/seal.c | 10 +++++----- symm/square.c | 18 +++++++++++++++++- 7 files changed, 73 insertions(+), 12 deletions(-) diff --git a/key/key-data.h b/key/key-data.h index 9c00908..cfeff82 100644 --- a/key/key-data.h +++ b/key/key-data.h @@ -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) diff --git a/math/mpint.h b/math/mpint.h index 7867f6a..f551980 100644 --- a/math/mpint.h +++ b/math/mpint.h @@ -42,6 +42,25 @@ /*----- 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; \ @@ -84,7 +103,7 @@ if (_i >= -MPW_MAX) \ break; \ else \ - _i /= (type)MPW_MAX + 1; \ + MP_FROMINT_MUFFLE_WARNING({ _i /= (type)MPW_MAX + 1; }); \ } \ } \ \ diff --git a/math/mpx.c b/math/mpx.c index 1294124..37a8a4e 100644 --- a/math/mpx.c +++ b/math/mpx.c @@ -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); diff --git a/math/pgen-simul.c b/math/pgen-simul.c index 03deeb1..7321362 100644 --- a/math/pgen-simul.c +++ b/math/pgen-simul.c @@ -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; diff --git a/symm/rc4.c b/symm/rc4.c index 0d02062..303b76e 100644 --- a/symm/rc4.c +++ b/symm/rc4.c @@ -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 diff --git a/symm/seal.c b/symm/seal.c index df7cd1b..da9d084 100644 --- a/symm/seal.c +++ b/symm/seal.c @@ -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; diff --git a/symm/square.c b/symm/square.c index f3056de..73b22bb 100644 --- a/symm/square.c +++ b/symm/square.c @@ -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]; -- 2.11.0