aboutsummaryrefslogtreecommitdiff
path: root/gcc/real.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-02-12 22:14:27 +0100
committerJakub Jelinek <jakub@redhat.com>2020-02-12 22:15:40 +0100
commit3f3932a0ec875cb7cca187018f3f8f05f2519d3e (patch)
treea87f5f837e40faeb1209cda65f5acce18836fc3d /gcc/real.c
parentb32a3f324367ca470aaec1866abe7edf5616bb7c (diff)
downloadgcc-3f3932a0ec875cb7cca187018f3f8f05f2519d3e.zip
gcc-3f3932a0ec875cb7cca187018f3f8f05f2519d3e.tar.gz
gcc-3f3932a0ec875cb7cca187018f3f8f05f2519d3e.tar.bz2
real: Fix roundeven on inf/nan [PR93663]
As can be seen in the testcase, roundeven with inf or nan arguments ICE because of those asserts where nothing prevents from is_halfway_below being called with those arguments. The following patch fixes that by just returning false for rvc_inf/rvc_nan like it returns for rvc_zero, so that we handle roundeven with all those values as round. Inf/NaN are not halfway in between two integers... 2020-02-12 Jakub Jelinek <jakub@redhat.com> PR middle-end/93663 * real.c (is_even): Make static. Function comment fix. (is_halfway_below): Make static, don't assert R is not inf/nan, instead return false for those. Small formatting fixes. * gcc.dg/torture/builtin-round-roundeven.c (main): Add tests for DBL_MAX, inf, their negations and nan.
Diffstat (limited to 'gcc/real.c')
-rw-r--r--gcc/real.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/gcc/real.c b/gcc/real.c
index 46d8126..00b23ce 100644
--- a/gcc/real.c
+++ b/gcc/real.c
@@ -5150,10 +5150,10 @@ real_round (REAL_VALUE_TYPE *r, format_helper fmt,
real_convert (r, fmt, r);
}
-/* Return true including 0 if integer part of R is even, else return
+/* Return true (including 0) if integer part of R is even, else return
false. The function is not valid for rvc_inf and rvc_nan classes. */
-bool
+static bool
is_even (REAL_VALUE_TYPE *r)
{
gcc_assert (r->cl != rvc_inf);
@@ -5184,16 +5184,12 @@ is_even (REAL_VALUE_TYPE *r)
}
/* Return true if R is halfway between two integers, else return
- false. The function is not valid for rvc_inf and rvc_nan classes. */
+ false. */
-bool
+static bool
is_halfway_below (const REAL_VALUE_TYPE *r)
{
- gcc_assert (r->cl != rvc_inf);
- gcc_assert (r->cl != rvc_nan);
- int i;
-
- if (r->cl == rvc_zero)
+ if (r->cl != rvc_normal)
return false;
/* For numbers (-0.5,0) and (0,0.5). */
@@ -5205,13 +5201,13 @@ is_halfway_below (const REAL_VALUE_TYPE *r)
unsigned int n = SIGNIFICAND_BITS - REAL_EXP (r) - 1;
int w = n / HOST_BITS_PER_LONG;
- for (i = 0; i < w; ++i)
+ for (int i = 0; i < w; ++i)
if (r->sig[i] != 0)
return false;
- unsigned long num = ((unsigned long)1 << (n % HOST_BITS_PER_LONG));
+ unsigned long num = 1UL << (n % HOST_BITS_PER_LONG);
- if (((r->sig[w] & num) != 0) && ((r->sig[w] & (num-1)) == 0))
+ if ((r->sig[w] & num) != 0 && (r->sig[w] & (num - 1)) == 0)
return true;
}
return false;