diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2020-09-24 23:59:02 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2020-09-24 23:59:02 +0000 |
commit | a18e4fa5ee223c6d96df5450eb7b1983ae35f980 (patch) | |
tree | e79d6886d2c1689ca09539b1c8a7a171f64c1d71 /tests | |
parent | dd5c08353c5de1913446473110af4b9fe72a97f5 (diff) | |
download | mpfr-a18e4fa5ee223c6d96df5450eb7b1983ae35f980.tar.gz |
[tests/tset_z_2exp.c] Added another test that fails with just
"-m32 -fsanitize=undefined -fno-sanitize-recover".
This corresponds to what is described in the FIXME in src/set_z_2exp.c
(about the modified tnrandom.c test yielding an integer overflow).
git-svn-id: https://scm.gforge.inria.fr/anonscm/svn/mpfr/trunk@14141 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tset_z_2exp.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/tests/tset_z_2exp.c b/tests/tset_z_2exp.c index 2e1b5fb21..bc77b56e0 100644 --- a/tests/tset_z_2exp.c +++ b/tests/tset_z_2exp.c @@ -147,20 +147,44 @@ check_huge (void) { mpfr_t x; mpz_t z; + long e; /* Increase tests_memory_limit to the maximum in order to avoid an obvious failure due to insufficient memory. */ tests_memory_limit = (size_t) -1; /* no memory limit */ - mpfr_init2 (x, 64); + mpfr_init2 (x, 32); + + /* In r14140, with a 32-bit ABI (GCC's -m32): + - With UBsan (-fsanitize=undefined -fno-sanitize-recover), + this fails with: + set_z_2exp.c:71:26: runtime error: signed integer overflow: + 67108864 * 32 cannot be represented in type 'long int' + - With -D_MPFR_EXP_FORMAT=4, this fails with: + Expected 0.10001000000000000000000000000000E5 + Got 0 + */ + mpz_init_set_ui (z, 17); + e = 0x7ffffff0; + mpz_mul_2exp (z, z, e); + mpz_add_ui (z, z, 1); + mpfr_set_z_2exp (x, z, -e, MPFR_RNDN); + if (mpfr_cmp_ui0 (x, 17) != 0) + { + printf ("Error 1 in check_huge\n"); + printf ("Expected 0.10001000000000000000000000000000E5\n"); + printf ("Got "); + mpfr_dump (x); + exit (1); + } + mpz_clear (z); mpz_init_set_ui (z, 17); mpz_mul_2exp (z, z, 0xffffffb0); mpz_add_ui (z, z, 1); - mpfr_set_z_2exp (x, z, -1, MPFR_RNDN); - mpz_clear (z); + mpfr_clear (x); } } |