mini-gmp warnings

Niels Möller nisse at lysator.liu.se
Sun Apr 26 13:11:06 UTC 2020


nisse at lysator.liu.se (Niels Möller) writes:

> There are a couple of other uses of LOCAL_SHIFT_BITS,
> LOCAL_GMP_LIMB_BITS, LOCAL_CHAR_BIT, added as part of the support for
> testing with small limb sizes. Is it for some reason important to refer
> to these constants via int variables? They all look a bit odd to me.

Now I've tried changing it, and it seems to also be a hack to avoid
warnings?

In this macro,

#define gmp_umul_ppmm(w1, w0, u, v)					\
  do {									\
    int LOCAL_GMP_LIMB_BITS = GMP_LIMB_BITS;				\
    if (sizeof(unsigned int) * CHAR_BIT >= 2 * GMP_LIMB_BITS)		\
      {									\
	unsigned int __ww = (unsigned int) (u) * (v);			\
	w0 = (mp_limb_t) __ww;						\
	w1 = (mp_limb_t) (__ww >> LOCAL_GMP_LIMB_BITS);			\
      }									\

if I change the shift to

	w1 = (mp_limb_t) (__ww >> GMP_LIMB_BITS);			\

I get another warning,

gcc -O2 -pedantic -fomit-frame-pointer -m64 -mtune=broadwell -march=broadwell -I../.. -c /home/nisse/hack/gmp/mini-gmp/tests/testutils.c -o testutils.o
In file included from
/home/nisse/hack/gmp/mini-gmp/tests/testutils.c:24: /home/nisse/hack/gmp/mini-gmp/tests/../mini-gmp.c: In function ‘mpn_mul_1’:
/home/nisse/hack/gmp/mini-gmp/tests/../mini-gmp.c:137:25: warning: right shift count >= width of type [-Wshift-count-overflow]
  w1 = (mp_limb_t) (__ww >> GMP_LIMB_BITS);   \
                         ^~                                                               

This is with gcc-8.3. I don't think it's reasonable for the compiler to
complain about this, when the code is not reachable. Maybe I should
install gcc-9 (or even gcc-10) and see if it behaves differently.

Regards,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.


More information about the gmp-devel mailing list