From 568c985113b29574c4e25e1a016475668fc17c28 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 14 May 2020 08:53:03 +0200 Subject: [PATCH] middle-end/95118 - fix printing of denormal zero This fixes printing a REAL_CST generated from value-numbering punning some bits to a real which turns out as zero with big negative exponent. This causes the loop in real_to_decimal_for_mode to never terminate. 2020-05-14 Richard Biener PR middle-end/95118 * real.c (real_to_decimal_for_mode): Make sure we handle a zero with nonzero exponent. * gcc.dg/pr95118.c: New testcase. --- gcc/ChangeLog | 6 ++++++ gcc/real.c | 4 ++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr95118.c | 11 +++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr95118.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 360ad7a5b58..e0a50f10e85 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2020-05-14 Richard Biener + + PR middle-end/95118 + * real.c (real_to_decimal_for_mode): Make sure we handle + a zero with nonzero exponent. + 2020-05-14 Jakub Jelinek * Makefile.in (GTFILES): Add omp-general.c. diff --git a/gcc/real.c b/gcc/real.c index 00b23ceb41e..09ec5c08c38 100644 --- a/gcc/real.c +++ b/gcc/real.c @@ -1714,8 +1714,8 @@ real_to_decimal_for_mode (char *str, const REAL_VALUE_TYPE *r_orig, do_multiply (&u, &v, ten); - /* Stop if we're now >= 1. */ - if (REAL_EXP (&u) > 0) + /* Stop if we're now >= 1 or zero. */ + if (REAL_EXP (&u) > 0 || u.cl == rvc_zero) break; v = u; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2b6d4becf4e..b731544a8c6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-05-14 Richard Biener + + PR middle-end/95118 + * gcc.dg/pr95118.c: New testcase. + 2020-05-14 Jakub Jelinek * c-c++-common/gomp/declare-variant-14.c: New test. diff --git a/gcc/testsuite/gcc.dg/pr95118.c b/gcc/testsuite/gcc.dg/pr95118.c new file mode 100644 index 00000000000..69bc47fd7aa --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr95118.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-fre" } */ + +void a(); +void b() { + union { + int c[4]; + long double d; + } e = {{0, 0, 4}}; + a(e.d); +}