public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/maskray/grte] Make zero volatile to defeat constant-folding of 0.0/0.0
@ 2021-08-27 23:21 Fangrui Song
  0 siblings, 0 replies; only message in thread
From: Fangrui Song @ 2021-08-27 23:21 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=fe9f4b71d6f55e3f4a13090749603bf747a45ab7

commit fe9f4b71d6f55e3f4a13090749603bf747a45ab7
Author: Stan Shebs <stanshebs@google.com>
Date:   Tue Jan 23 08:28:31 2018 -0800

    Make zero volatile to defeat constant-folding of 0.0/0.0

Diff:
---
 sysdeps/ieee754/dbl-64/e_log.c | 6 ++++--
 sysdeps/ieee754/k_standard.c   | 2 +-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/sysdeps/ieee754/dbl-64/e_log.c b/sysdeps/ieee754/dbl-64/e_log.c
index 6a18ebb904..1558a2ec4e 100644
--- a/sysdeps/ieee754/dbl-64/e_log.c
+++ b/sysdeps/ieee754/dbl-64/e_log.c
@@ -69,6 +69,8 @@ __ieee754_log (double x)
   number num;
   mp_no mpx, mpy, mpy1, mpy2, mperr;
 
+  volatile double zero = 0.0;
+
 #include "ulog.tbl"
 #include "ulog.h"
 
@@ -81,9 +83,9 @@ __ieee754_log (double x)
   if (__glibc_unlikely (ux < 0x00100000))
     {
       if (__glibc_unlikely (((ux & 0x7fffffff) | dx) == 0))
-	return MHALF / 0.0;     /* return -INF */
+	return MHALF / zero;     /* return -INF */
       if (__glibc_unlikely (ux < 0))
-	return (x - x) / 0.0;   /* return NaN  */
+	return (x - x) / zero;   /* return NaN  */
       n -= 54;
       x *= two54.d;             /* scale x     */
       num.d = x;
diff --git a/sysdeps/ieee754/k_standard.c b/sysdeps/ieee754/k_standard.c
index f74f9c712e..f0436cc4a1 100644
--- a/sysdeps/ieee754/k_standard.c
+++ b/sysdeps/ieee754/k_standard.c
@@ -38,7 +38,7 @@ static char rcsid[] = "$NetBSD: k_standard.c,v 1.6 1995/05/10 20:46:35 jtc Exp $
 # if 0
 static const double zero = 0.0;	/* used as const */
 # else
-static double zero = 0.0;	/* used as const */
+volatile static double zero = 0.0;	/* used as const */
 # endif
 
 /*


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-27 23:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-27 23:21 [glibc/maskray/grte] Make zero volatile to defeat constant-folding of 0.0/0.0 Fangrui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).