Reorganized mini-gmp/tests/t-signed.

Niels Möller nisse at lysator.liu.se
Sun Nov 20 21:22:31 UTC 2016


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

> Anyway, I can now repro locally, by running 
>
>   make check CFLAGS="-O -Wall -g -fsanitize=undefined -fno-sanitize-recover"
>
> in the mini-gmp/tests source directory. This fails with
>
>   t-signed.c:93:8: runtime error: signed integer overflow: -1 +
> -9223372036854775808 cannot be represented in type 'long int'
>   FAIL: t-signed

I've checked in a fix for this.
https://gmplib.org/repo/gmp/rev/6a2a9d2f639c

Marco, would mind having a look at the reorganized test? I deleted
checks at the end of the loop which I didn't quite understand, and which
didn't quite fit with the new stop condition.

The idea is to instead of checking for overflow by examining signed
integer values, compute the mpz version first and use mpz_fits_slong_p
to check if the computation on signed long makes sense. And I added
tests to check that that function agrees with LONG_MAX and LONG_MIN.

I also avoid even computing the signed values when they wouldn't fit, to
make it possible to use -fsanitizer=undefined without complaints. 

It would be cool if -fsanitizer=undefined could cooperate with valgrind,
and not complain immediately when there's an undefined value, but
instead taint that value, and complain if it or anything which depends
in it is ever used for a branch condition, memory access or system call.
(And strictly speaking, that would make sense only for implementation
defined behaviour, not undefied behaviour, I guess).

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