Likely GMP bug

Niels Möller nisse at
Fri May 25 12:10:54 UTC 2018

Dennis Clarke <dclarke at> writes:

> gcd_1.c:187:13: runtime error: shift exponent 32 is too large for
> 32-bit type 'long unsigned int'
> FAIL t-cmp_ui (exit status: 1)

And code is essentially 

      count_trailing_zeros (c, t);
      ulimb >>= (c + 1);

The intention is to shift right to get rid of both trailing zero bits,
and the redundant least significant one bit.

That fails with undefined behavior if by chance t == 2^31, so that c ==

I don't see how that can happen, though, since ulimb, vlimb < 2^31
through out the loop, and t = (ulimb - vlimb) mod 2^32.

And I also wonder why USE_ZEROTAB is set to 0 here.


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

More information about the gmp-bugs mailing list