https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87276
Bug ID: 87276 Summary: Buggy code with -O2 in trunk revision 264170: MPFR test tstrtofr fails Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: vincent-gcc at vinc17 dot net Target Milestone: --- On Debian x86_64, I get the following failure with gcc (Debian 20180908-1) 9.0.0 20180908 (experimental) [trunk revision 264170] This is a regression, as there are no issues with either GCC 8 or with gcc (Debian 20180822-1) 9.0.0 20180822 (experimental) [trunk revision 263760] When building the MPFR trunk revision 13165 with ./configure --enable-assert=full CC=gcc-snapshot CFLAGS="-O2" (no issues with -O or with -O2 -fsanitize=undefined -fno-sanitize-recover), I get a failure in tstrtofr: Check overflow failed (2) with: s='' x=0 I've modified MPFR's strtofr.c to the following (i.e. adding printf's): [...] long read_exp = strtol (str + 1, &endptr, 10); if (endptr != str+1) str = endptr; sum = read_exp < MPFR_EXP_MIN ? (str = endptr, MPFR_EXP_MIN) : read_exp > MPFR_EXP_MAX ? (str = endptr, MPFR_EXP_MAX) : (mpfr_exp_t) read_exp; printf ("%ld %d\n", sum, res); printf ("%ld\n", pstr->exp_base); MPFR_SADD_OVERFLOW (sum, sum, pstr->exp_base, mpfr_exp_t, mpfr_uexp_t, MPFR_EXP_MIN, MPFR_EXP_MAX, res = 2, res = 3); // printf ("%ld %d\n", sum, res); [...] and reduced tstrtofr.c to: #include "mpfr-test.h" static void check_overflow (void) { mpfr_t x; char *s; mpfr_init (x); mpfr_strtofr (x, "123456789E9223372036854775807", &s, 0, MPFR_RNDN); if (s[0] != 0 || !MPFR_IS_INF (x) || !MPFR_IS_POS (x) ) { printf ("Check overflow failed (2) with:\n s='%s'\n x=", s); mpfr_dump (x); exit (1); } mpfr_clear (x); } int main (int argc, char *argv[]) { tests_start_mpfr (); check_overflow (); tests_end_mpfr (); return 0; } I get the following failure: 9223372036854775807 1 9 Check overflow failed (2) with: s='' x=0 Then, if I uncomment the last printf line, the failure disappears, and I get: 9223372036854775807 1 9 9223372036854775807 2