public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/6] Fixes inspired by building with clang
@ 2020-08-20 22:14 Keith Packard
  2020-08-20 22:14 ` [PATCH 1/6] libm/stdlib: Recover from realloc failure when shrinking Keith Packard
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Keith Packard @ 2020-08-20 22:14 UTC (permalink / raw)
  To: newlib

I had a picolibc user building the library with clang and they
reported a number of warnings. I also have another minor nano-mallocr
patch in this series.

 * [PATCH 1/6] libm/stdlib: Recover from realloc failure when shrinking

Last in my nano-mallocr series -- this has realloc always succeed when
shrinking the allocation.

 * [PATCH 2/6] libc/iconv: Check ces handlers table value in

This catches a failure which would otherwise be missed causing crashes
later on.

 * [PATCH 3/6] Avoid implicit floating point conversions

A large-ish patch that fixes warnings generated by clang's
-Wdouble-promotion flag. Fixing these will avoid accidentally using
double-precision computations, which can be expensive on machines
without hardware double support.

 * [PATCH 4/6] libc/stdlib: Undefined shift negative value in a64l

This code was using undefined behaviour from the compiler. As GCC and
clang both continue to 'improve', it's good to keep undefined
behaviour out of code.

 * [PATCH 5/6] libc/stdlib: Clean up clang warnings
 * [PATCH 6/6] libc/stdio: Conditionally declare vars for

These just fix some warnings generated when compiling with various
configurations using clang.  None of these should change the resulting
code.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/6] libm/stdlib: Recover from realloc failure when shrinking
  2020-08-20 22:14 [PATCH 0/6] Fixes inspired by building with clang Keith Packard
@ 2020-08-20 22:14 ` Keith Packard
  2020-08-20 22:14 ` [PATCH 2/6] libc/iconv: Check ces handlers table value in euc_from_ucs_init Keith Packard
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Keith Packard @ 2020-08-20 22:14 UTC (permalink / raw)
  To: newlib

When shrinking and the new allocation fails, just leave things as they
were and keep going. Applications may well expect shrinking
reallocations to always succeed.

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 newlib/libc/stdlib/nano-mallocr.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/newlib/libc/stdlib/nano-mallocr.c b/newlib/libc/stdlib/nano-mallocr.c
index 6ba0eb74b..0b032d833 100644
--- a/newlib/libc/stdlib/nano-mallocr.c
+++ b/newlib/libc/stdlib/nano-mallocr.c
@@ -481,7 +481,12 @@ void * nano_realloc(RARG void * ptr, malloc_size_t size)
       return ptr;
 
     mem = nano_malloc(RCALL size);
-    if (mem != NULL)
+    if (mem == NULL)
+    {
+	if (size <= old_size)
+	    return ptr;
+    }
+    else
     {
 	if (old_size > size)
 	    old_size = size;
-- 
2.28.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/6] libc/iconv: Check ces handlers table value in euc_from_ucs_init
  2020-08-20 22:14 [PATCH 0/6] Fixes inspired by building with clang Keith Packard
  2020-08-20 22:14 ` [PATCH 1/6] libm/stdlib: Recover from realloc failure when shrinking Keith Packard
@ 2020-08-20 22:14 ` Keith Packard
  2020-08-20 22:14 ` [PATCH 3/6] Avoid implicit floating point conversions Keith Packard
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Keith Packard @ 2020-08-20 22:14 UTC (permalink / raw)
  To: newlib

Need to check the value returned from
_iconv_from_ucs_ces_handlers_table.init -- the test was
incorrectly comparing the array holding the value.

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 newlib/libc/iconv/ces/euc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/newlib/libc/iconv/ces/euc.c b/newlib/libc/iconv/ces/euc.c
index ebd7091b0..56c0c6a6c 100644
--- a/newlib/libc/iconv/ces/euc.c
+++ b/newlib/libc/iconv/ces/euc.c
@@ -149,7 +149,7 @@ ok:
       data->data[i] = _iconv_from_ucs_ces_handlers_table.init (
                                                         rptr,
                                                         data->desc[i].csname);
-      if (data->data == NULL)
+      if (data->data[i] == NULL)
         goto error;
     } 
 
-- 
2.28.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/6] Avoid implicit floating point conversions
  2020-08-20 22:14 [PATCH 0/6] Fixes inspired by building with clang Keith Packard
  2020-08-20 22:14 ` [PATCH 1/6] libm/stdlib: Recover from realloc failure when shrinking Keith Packard
  2020-08-20 22:14 ` [PATCH 2/6] libc/iconv: Check ces handlers table value in euc_from_ucs_init Keith Packard
@ 2020-08-20 22:14 ` Keith Packard
  2020-08-20 22:43   ` Joseph Myers
       [not found]   ` <SN5P110MB03830A3D8272D82A089605659A5A0@SN5P110MB0383.NAMP110.PROD.OUTLOOK.COM>
  2020-08-20 22:14 ` [PATCH 4/6] libc/stdlib: Undefined shift negative value in a64l Keith Packard
                   ` (2 subsequent siblings)
  5 siblings, 2 replies; 10+ messages in thread
From: Keith Packard @ 2020-08-20 22:14 UTC (permalink / raw)
  To: newlib

These were found with clang -Wdouble-promotion and show places where
floating point values were being implicitly converted between
representations. These conversions can result in unexpected use of
double precision arithmetic. Those which are intentional all have an
explicit cast added.

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 newlib/libc/include/complex.h      |  4 +++-
 newlib/libc/include/limits.h       |  5 +++++
 newlib/libc/include/math.h         | 20 ++++++++++++++++++--
 newlib/libc/stdlib/efgcvt.c        |  4 ++--
 newlib/libc/stdlib/strtod.c        |  4 ++--
 newlib/libc/stdlib/wcstod.c        |  6 +++---
 newlib/libm/common/cosf.c          |  2 +-
 newlib/libm/common/math_errf.c     |  2 +-
 newlib/libm/common/nexttowardf.c   |  8 ++++----
 newlib/libm/common/sf_logb.c       |  2 +-
 newlib/libm/common/sf_pow.c        |  2 +-
 newlib/libm/common/sincosf.c       |  2 +-
 newlib/libm/common/sinf.c          |  2 +-
 newlib/libm/common/sqrtl.c         | 25 +++----------------------
 newlib/libm/complex/cacosf.c       |  6 +++---
 newlib/libm/complex/cacoshf.c      |  4 ++--
 newlib/libm/complex/casinf.c       | 18 +++++++++---------
 newlib/libm/complex/casinhf.c      |  6 +++---
 newlib/libm/complex/catanf.c       |  8 ++++----
 newlib/libm/complex/catanhf.c      |  6 +++---
 newlib/libm/complex/ccosf.c        |  6 +++---
 newlib/libm/complex/ccoshf.c       |  6 +++---
 newlib/libm/complex/cephes_subrf.c |  8 ++++----
 newlib/libm/complex/cexpf.c        |  6 +++---
 newlib/libm/complex/clog10f.c      |  2 +-
 newlib/libm/complex/clogf.c        |  6 +++---
 newlib/libm/complex/cpowf.c        |  8 ++++----
 newlib/libm/complex/cprojf.c       |  8 ++++----
 newlib/libm/complex/csinf.c        |  6 +++---
 newlib/libm/complex/csinhf.c       |  6 +++---
 newlib/libm/complex/csqrtf.c       | 20 ++++++++++----------
 newlib/libm/complex/ctanf.c        |  8 ++++----
 newlib/libm/complex/ctanhf.c       |  6 +++---
 newlib/libm/math/ef_scalb.c        | 10 +++++-----
 newlib/libm/math/wf_acos.c         |  2 +-
 newlib/libm/math/wf_acosh.c        |  2 +-
 newlib/libm/math/wf_asin.c         |  2 +-
 newlib/libm/math/wf_atanh.c        |  2 +-
 newlib/libm/math/wf_cosh.c         |  2 +-
 newlib/libm/math/wf_fmod.c         |  2 +-
 newlib/libm/math/wf_j0.c           |  4 ++--
 newlib/libm/math/wf_j1.c           |  4 ++--
 newlib/libm/math/wf_jn.c           |  4 ++--
 newlib/libm/math/wf_log.c          |  2 +-
 newlib/libm/math/wf_log10.c        |  2 +-
 newlib/libm/math/wf_pow.c          |  4 ++--
 newlib/libm/math/wf_remainder.c    |  2 +-
 newlib/libm/math/wf_scalb.c        |  6 +++---
 newlib/libm/math/wf_sqrt.c         |  2 +-
 49 files changed, 144 insertions(+), 140 deletions(-)

diff --git a/newlib/libc/include/complex.h b/newlib/libc/include/complex.h
index 0a3ea97ed..13b300021 100644
--- a/newlib/libc/include/complex.h
+++ b/newlib/libc/include/complex.h
@@ -9,8 +9,10 @@
 #define	_COMPLEX_H
 
 #define complex _Complex
-#define _Complex_I 1.0fi
+#define _Complex_I 1.0i
+#define _Complex_If 1.0if
 #define I _Complex_I
+#define I_f _Complex_If
 
 #include <sys/cdefs.h>
 
diff --git a/newlib/libc/include/limits.h b/newlib/libc/include/limits.h
index 893f10834..011a888e6 100644
--- a/newlib/libc/include/limits.h
+++ b/newlib/libc/include/limits.h
@@ -129,6 +129,11 @@
 
 #if defined __GNUC__ && !defined _GCC_LIMITS_H_
 /* `_GCC_LIMITS_H_' is what GCC's file defines.  */
+#ifdef __clang__
+#ifndef __GLIBC_USE
+#define __GLIBC_USE(x) 1
+#endif
+#endif
 # include_next <limits.h>
 #endif /* __GNUC__ && !_GCC_LIMITS_H_ */
 
diff --git a/newlib/libc/include/math.h b/newlib/libc/include/math.h
index 5e6155cc4..d8e25ab5c 100644
--- a/newlib/libc/include/math.h
+++ b/newlib/libc/include/math.h
@@ -28,11 +28,27 @@ _BEGIN_STD_C
 # endif
 
 # ifndef INFINITY
-#  define INFINITY (__builtin_inff())
+#  define INFINITY (__builtin_inf())
+# endif
+
+# ifndef INFINITYF
+#  define INFINITYF (__builtin_inff())
+# endif
+
+# ifndef INFINITYL
+#  define INFINITYL (__builtin_infl())
 # endif
 
 # ifndef NAN
-#  define NAN (__builtin_nanf(""))
+#  define NAN (__builtin_nan(""))
+# endif
+
+# ifndef NANF
+#  define NANF (__builtin_nanf(""))
+# endif
+
+# ifndef NANL
+#  define NANL (__builtin_nanl(""))
 # endif
 
 #else /* !gcc >= 3.3  */
diff --git a/newlib/libc/stdlib/efgcvt.c b/newlib/libc/stdlib/efgcvt.c
index 3cdb9c420..3328cb75f 100644
--- a/newlib/libc/stdlib/efgcvt.c
+++ b/newlib/libc/stdlib/efgcvt.c
@@ -120,7 +120,7 @@ fcvtf (float d,
 	int *decpt,
 	int *sign)
 {
-  return fcvt ((float) d, ndigit, decpt, sign);
+  return fcvt ((double) d, ndigit, decpt, sign);
 }
 
 
@@ -144,7 +144,7 @@ gcvtf (float d,
 	int ndigit,
 	char *buf)
 {
-  double asd = d;
+  double asd = (double) d;
   return gcvt (asd, ndigit, buf);
 }
 
diff --git a/newlib/libc/stdlib/strtod.c b/newlib/libc/stdlib/strtod.c
index 8bb75ef0a..850393b22 100644
--- a/newlib/libc/stdlib/strtod.c
+++ b/newlib/libc/stdlib/strtod.c
@@ -1292,7 +1292,7 @@ strtof_l (const char *__restrict s00, char **__restrict se, locale_t loc)
     return signbit (val) ? -nanf ("") : nanf ("");
   float retval = (float) val;
 #ifndef NO_ERRNO
-  if (isinf (retval) && !isinf (val))
+  if (isinff (retval) && !isinff (val))
     _REENT->_errno = ERANGE;
 #endif
   return retval;
@@ -1307,7 +1307,7 @@ strtof (const char *__restrict s00,
     return signbit (val) ? -nanf ("") : nanf ("");
   float retval = (float) val;
 #ifndef NO_ERRNO
-  if (isinf (retval) && !isinf (val))
+  if (isinff (retval) && !isinff (val))
     _REENT->_errno = ERANGE;
 #endif
   return retval;
diff --git a/newlib/libc/stdlib/wcstod.c b/newlib/libc/stdlib/wcstod.c
index 375ffe288..6bb01cdd8 100644
--- a/newlib/libc/stdlib/wcstod.c
+++ b/newlib/libc/stdlib/wcstod.c
@@ -227,7 +227,7 @@ _wcstof_r (struct _reent *ptr,
 	wchar_t **endptr)
 {
   double retval = _wcstod_l (ptr, nptr, endptr, __get_current_locale ());
-  if (isnan (retval))
+  if (isnanf (retval))
     return nanf ("");
   return (float)retval;
 }
@@ -256,7 +256,7 @@ wcstof_l (const wchar_t *__restrict nptr, wchar_t **__restrict endptr,
     return nanf ("");
   float retval = (float) val;
 #ifndef NO_ERRNO
-  if (isinf (retval) && !isinf (val))
+  if (isinff (retval) && !isinff (val))
     _REENT->_errno = ERANGE;
 #endif
   return retval;
@@ -271,7 +271,7 @@ wcstof (const wchar_t *__restrict nptr,
     return nanf ("");
   float retval = (float) val;
 #ifndef NO_ERRNO
-  if (isinf (retval) && !isinf (val))
+  if (isinff (retval) && !isinff (val))
     _REENT->_errno = ERANGE;
 #endif
 
diff --git a/newlib/libm/common/cosf.c b/newlib/libm/common/cosf.c
index 1fafcbc24..7f59adf13 100644
--- a/newlib/libm/common/cosf.c
+++ b/newlib/libm/common/cosf.c
@@ -41,7 +41,7 @@
 float
 cosf (float y)
 {
-  double x = y;
+  double x = (double) y;
   double s;
   int n;
   const sincos_t *p = &__sincosf_table[0];
diff --git a/newlib/libm/common/math_errf.c b/newlib/libm/common/math_errf.c
index bb8273b8d..e513d9547 100644
--- a/newlib/libm/common/math_errf.c
+++ b/newlib/libm/common/math_errf.c
@@ -86,5 +86,5 @@ HIDDEN float
 __math_invalidf (float x)
 {
   float y = (x - x) / (x - x);
-  return isnan (x) ? y : with_errnof (y, EDOM);
+  return isnanf (x) ? y : with_errnof (y, EDOM);
 }
diff --git a/newlib/libm/common/nexttowardf.c b/newlib/libm/common/nexttowardf.c
index e2a1d90e6..4c4da6c70 100644
--- a/newlib/libm/common/nexttowardf.c
+++ b/newlib/libm/common/nexttowardf.c
@@ -41,16 +41,16 @@ nexttowardf (float x, long double y)
   union fshape ux;
   uint32_t e;
 
-  if (isnan(x) || isnan(y))
-    return x + y;
-  if (x == y)
+  if (isnanf(x) || isnan(y))
+    return (long double) x + y;
+  if ((long double) x == y)
     return y;
   ux.value = x;
   if (x == 0) {
     ux.bits = 1;
     if (signbit(y))
       ux.bits |= 0x80000000;
-  } else if (x < y) {
+  } else if ((long double) x < y) {
     if (signbit(x))
       ux.bits--;
     else
diff --git a/newlib/libm/common/sf_logb.c b/newlib/libm/common/sf_logb.c
index 75336a1e0..8319a47ff 100644
--- a/newlib/libm/common/sf_logb.c
+++ b/newlib/libm/common/sf_logb.c
@@ -36,7 +36,7 @@ float x;
 		float  xx;
 		/* arg==0:  return -inf and raise divide-by-zero exception */
 		SET_FLOAT_WORD(xx,hx);	/* +0.0 */
-		return -1./xx;	/* logbf(0) = -inf */
+		return -1.f/xx;	/* logbf(0) = -inf */
 		}
 	if(FLT_UWORD_IS_SUBNORMAL(hx)) {
 	    for (ix = -126,hx<<=8; hx>0; hx<<=1) ix -=1;
diff --git a/newlib/libm/common/sf_pow.c b/newlib/libm/common/sf_pow.c
index 2946c611b..1820cc868 100644
--- a/newlib/libm/common/sf_pow.c
+++ b/newlib/libm/common/sf_pow.c
@@ -213,7 +213,7 @@ powf (float x, float y)
 	}
     }
   double_t logx = log2_inline (ix);
-  double_t ylogx = y * logx; /* Note: cannot overflow, y is single prec.  */
+  double_t ylogx = (double) y * logx; /* Note: cannot overflow, y is single prec.  */
   if (__builtin_expect ((asuint64 (ylogx) >> 47 & 0xffff)
 			  >= asuint64 (126.0 * POWF_SCALE) >> 47,
 			0))
diff --git a/newlib/libm/common/sincosf.c b/newlib/libm/common/sincosf.c
index 5053baf26..538cc5673 100644
--- a/newlib/libm/common/sincosf.c
+++ b/newlib/libm/common/sincosf.c
@@ -41,7 +41,7 @@
 void
 sincosf (float y, float *sinp, float *cosp)
 {
-  double x = y;
+  double x = (double) y;
   double s;
   int n;
   const sincos_t *p = &__sincosf_table[0];
diff --git a/newlib/libm/common/sinf.c b/newlib/libm/common/sinf.c
index 8cb77ef81..4f4e6d3ae 100644
--- a/newlib/libm/common/sinf.c
+++ b/newlib/libm/common/sinf.c
@@ -40,7 +40,7 @@
 float
 sinf (float y)
 {
-  double x = y;
+  double x = (double) y;
   double s;
   int n;
   const sincos_t *p = &__sincosf_table[0];
diff --git a/newlib/libm/common/sqrtl.c b/newlib/libm/common/sqrtl.c
index 9976f35e7..234f1b7a3 100644
--- a/newlib/libm/common/sqrtl.c
+++ b/newlib/libm/common/sqrtl.c
@@ -98,25 +98,6 @@ inc (long double x)
   return ux.extu_ld;
 }
 
-/* Return (x - ulp) for normal positive x.  Assumes no underflow.  */
-
-static inline long double
-dec (long double x)
-{
-  union ieee_ext_u ux = { .extu_ld = x, };
-
-  if (ux.extu_ext.ext_fracl-- == 0)
-    {
-      if (ux.extu_ext.ext_frach-- == LDBL_NBIT)
-	{
-	  ux.extu_ext.ext_exp--;
-	  ux.extu_ext.ext_frach |= LDBL_NBIT;
-	}
-    }
-
-  return ux.extu_ld;
-}
-
 /* This is slow, but simple and portable.  */
 
 long double
@@ -143,7 +124,7 @@ sqrtl (long double x)
   if (ux.extu_ext.ext_exp == 0)
     {
       /* Adjust subnormal numbers.  */
-      ux.extu_ld *= 0x1.0p514;
+      ux.extu_ld *= 0x1.0p514l;
       k = -514;
     }
   else
@@ -167,10 +148,10 @@ sqrtl (long double x)
   /* Newton's iteration.
      Split ux.extu_ld into a high and low part to achieve additional precision.  */
 
-  xn = sqrt ((double) ux.extu_ld);	/* 53-bit estimate of sqrtl(x).  */
+  xn = (long double) sqrt ((double) ux.extu_ld);	/* 53-bit estimate of sqrtl(x).  */
 
 #if LDBL_MANT_DIG > 100
-  xn = (xn + (ux.extu_ld / xn)) * 0.5;	/* 106-bit estimate.  */
+  xn = (xn + (ux.extu_ld / xn)) * 0.5l;	/* 106-bit estimate.  */
 #endif
 
   lo = ux.extu_ld;
diff --git a/newlib/libm/complex/cacosf.c b/newlib/libm/complex/cacosf.c
index 3874dd5f6..ba698e584 100644
--- a/newlib/libm/complex/cacosf.c
+++ b/newlib/libm/complex/cacosf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -41,6 +41,6 @@ cacosf(float complex z)
 	float complex w;
 
 	w = casinf(z);
-	w = ((float)M_PI_2 - crealf(w)) - cimagf(w) * I;
+	w = ((float)M_PI_2 - crealf(w)) - cimagf(w) * I_f;
 	return w;
 }
diff --git a/newlib/libm/complex/cacoshf.c b/newlib/libm/complex/cacoshf.c
index 41a557ad7..2ce04258e 100644
--- a/newlib/libm/complex/cacoshf.c
+++ b/newlib/libm/complex/cacoshf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
diff --git a/newlib/libm/complex/casinf.c b/newlib/libm/complex/casinf.c
index 9a9f759ef..c4c120de4 100644
--- a/newlib/libm/complex/casinf.c
+++ b/newlib/libm/complex/casinf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -52,12 +52,12 @@ casinf(float complex z)
 #if 0 /* MD: test is incorrect, casin(>1) is defined */
 	if (y == 0.0f) {
 		if (fabsf(x) > 1.0) {
-			w = M_PI_2 + 0.0f * I;
+			w = M_PI_2 + 0.0f * I_f;
 #if 0
 			mtherr ("casin", DOMAIN);
 #endif
 		} else {
-			w = asinf(x) + 0.0f * I;
+			w = asinf(x) + 0.0f * I_f;
 		}
 		return w;
 	}
@@ -104,19 +104,19 @@ return;
 */
 
 
-	ca = x + y * I;
-	ct = ca * I;
+	ca = x + y * I_f;
+	ct = ca * I_f;
 	/* sqrt( 1 - z*z) */
 	/* cmul( &ca, &ca, &zz ) */
 	/*x * x  -  y * y */
-	zz = (x - y) * (x + y) + (2.0f * x * y) * I;
+	zz = (x - y) * (x + y) + (2.0f * x * y) * I_f;
 
-	zz = 1.0f - crealf(zz) - cimagf(zz) * I;
+	zz = 1.0f - crealf(zz) - cimagf(zz) * I_f;
 	z2 = csqrtf(zz);
 
 	zz = ct + z2;
 	zz = clogf(zz);
 	/* multiply by 1/i = -i */
-	w = zz * (-1.0f * I);
+	w = zz * (-1.0f * I_f);
 	return w;
 }
diff --git a/newlib/libm/complex/casinhf.c b/newlib/libm/complex/casinhf.c
index 0db55a0ad..b9b92d2c7 100644
--- a/newlib/libm/complex/casinhf.c
+++ b/newlib/libm/complex/casinhf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -39,6 +39,6 @@ casinhf(float complex z)
 {
 	float complex w;
 
-	w = -1.0f * I * casinf(z * I);
+	w = -1.0f * I_f * casinf(z * I_f);
 	return w;
 }
diff --git a/newlib/libm/complex/catanf.c b/newlib/libm/complex/catanf.c
index ac1a65c08..1043e193b 100644
--- a/newlib/libm/complex/catanf.c
+++ b/newlib/libm/complex/catanf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -67,13 +67,13 @@ catanf(float complex z)
 
 	t = y + 1.0f;
 	a = (x2 + (t * t))/a;
-	w = w + (0.25f * logf(a)) * I;
+	w = w + (0.25f * logf(a)) * I_f;
 	return w;
 
 ovrf:
 #if 0
 	mtherr ("catan", OVERFLOW);
 #endif
-	w = HUGE_VALF + HUGE_VALF * I;
+	w = HUGE_VALF + HUGE_VALF * I_f;
 	return w;
 }
diff --git a/newlib/libm/complex/catanhf.c b/newlib/libm/complex/catanhf.c
index fe6127a9d..96dfafb26 100644
--- a/newlib/libm/complex/catanhf.c
+++ b/newlib/libm/complex/catanhf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -39,6 +39,6 @@ catanhf(float complex z)
 {
 	float complex w;
 
-	w = -1.0f * I * catanf(z * I);
+	w = -1.0f * I_f * catanf(z * I_f);
 	return w;
 }
diff --git a/newlib/libm/complex/ccosf.c b/newlib/libm/complex/ccosf.c
index 805e24feb..1520aec36 100644
--- a/newlib/libm/complex/ccosf.c
+++ b/newlib/libm/complex/ccosf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -43,6 +43,6 @@ ccosf(float complex z)
 	float ch, sh;
 
 	_cchshf(cimagf(z), &ch, &sh);
-	w = cosf(crealf(z)) * ch - (sinf(crealf(z)) * sh) * I;
+	w = cosf(crealf(z)) * ch - (sinf(crealf(z)) * sh) * I_f;
 	return w;
 }
diff --git a/newlib/libm/complex/ccoshf.c b/newlib/libm/complex/ccoshf.c
index af11353e4..118e85542 100644
--- a/newlib/libm/complex/ccoshf.c
+++ b/newlib/libm/complex/ccoshf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -43,6 +43,6 @@ ccoshf(float complex z)
 
 	x = crealf(z);
 	y = cimagf(z);
-	w = coshf(x) * cosf(y) + (sinhf(x) * sinf(y)) * I;
+	w = coshf(x) * cosf(y) + (sinhf(x) * sinf(y)) * I_f;
 	return w;
 }
diff --git a/newlib/libm/complex/cephes_subrf.c b/newlib/libm/complex/cephes_subrf.c
index 4a325811f..98b5a74f3 100644
--- a/newlib/libm/complex/cephes_subrf.c
+++ b/newlib/libm/complex/cephes_subrf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -61,7 +61,7 @@ _cchshf(float x, float *c, float *s)
 static const double DP1 =  3.140625;
 static const double DP2 =  9.67502593994140625E-4;
 static const double DP3 =  1.509957990978376432E-7;
-#define MACHEPF 3.0e-8
+#define MACHEPF 3.0e-8f
 
 float
 _redupif(float x)
@@ -77,7 +77,7 @@ _redupif(float x)
 
 	i = t;	/* the multiple */
 	t = i;
-	t = ((x - t * DP1) - t * DP2) - t * DP3;
+	t = (((double) x - (double) t * DP1) - (double) t * DP2) - (double) t * DP3;
 	return t;
 }
 
diff --git a/newlib/libm/complex/cexpf.c b/newlib/libm/complex/cexpf.c
index 07fab1f16..85a1579d7 100644
--- a/newlib/libm/complex/cexpf.c
+++ b/newlib/libm/complex/cexpf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -44,6 +44,6 @@ cexpf(float complex z)
 	x = crealf(z);
 	y = cimagf(z);
 	r = expf(x);
-	w = r * cosf(y) + r * sinf(y) * I;
+	w = r * cosf(y) + r * sinf(y) * I_f;
 	return w;
 }
diff --git a/newlib/libm/complex/clog10f.c b/newlib/libm/complex/clog10f.c
index 124273227..d15d89f69 100644
--- a/newlib/libm/complex/clog10f.c
+++ b/newlib/libm/complex/clog10f.c
@@ -10,6 +10,6 @@ clog10f(float complex z)
 	rr = cabsf(z);
 	p = log10f(rr);
 	rr = atan2f(cimagf(z), crealf(z)) * (float) M_IVLN10;
-	w = p + rr * I;
+	w = p + rr * I_f;
 	return w;
 }
diff --git a/newlib/libm/complex/clogf.c b/newlib/libm/complex/clogf.c
index 078cea5d3..25ef42154 100644
--- a/newlib/libm/complex/clogf.c
+++ b/newlib/libm/complex/clogf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -44,6 +44,6 @@ clogf(float complex z)
 	rr = cabsf(z);
 	p = logf(rr);
 	rr = atan2f(cimagf(z), crealf(z));
-	w = p + rr * I;
+	w = p + rr * I_f;
 	return w;
 }
diff --git a/newlib/libm/complex/cpowf.c b/newlib/libm/complex/cpowf.c
index 1e736af36..3b5e9f8ee 100644
--- a/newlib/libm/complex/cpowf.c
+++ b/newlib/libm/complex/cpowf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -45,7 +45,7 @@ cpowf(float complex a, float complex z)
 	y = cimagf(z);
 	absa = cabsf(a);
 	if (absa == 0.0f) {
-		return (0.0f + 0.0f * I);
+		return (0.0f + 0.0f * I_f);
 	}
 	arga = cargf(a);
 	r = powf(absa, x);
@@ -54,6 +54,6 @@ cpowf(float complex a, float complex z)
 		r = r * expf(-y * arga);
 		theta = theta + y * logf(absa);
 	}
-	w = r * cosf(theta) + (r * sinf(theta)) * I;
+	w = r * cosf(theta) + (r * sinf(theta)) * I_f;
 	return w;
 }
diff --git a/newlib/libm/complex/cprojf.c b/newlib/libm/complex/cprojf.c
index 1310170b6..c8dac492d 100644
--- a/newlib/libm/complex/cprojf.c
+++ b/newlib/libm/complex/cprojf.c
@@ -20,7 +20,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -45,9 +45,9 @@
  *
  * z projects to z, except that all complex infinities (even those with one
  * infinite part and one NaN part) project to positive infinity on the real axis.
- * If z has an infinite part, then cproj(z) shall be equivalent to:
+ * I_ff z has an infinite part, then cproj(z) shall be equivalent to:
  *
- * INFINITY + I * copysign(0.0, cimag(z))
+ * I_fNFINITY + I * copysign(0.0, cimag(z))
  */
 
 float complex
@@ -55,7 +55,7 @@ cprojf(float complex z)
 {
 	float_complex w = { .z = z };
 
-	if (isinf(crealf(z)) || isinf(cimagf(z))) {
+	if (isinff(crealf(z)) || isinff(cimagf(z))) {
 #ifdef __INFINITY
 		REAL_PART(w) = __INFINITY;
 #else
diff --git a/newlib/libm/complex/csinf.c b/newlib/libm/complex/csinf.c
index 68cefe4fa..b7db7b3a7 100644
--- a/newlib/libm/complex/csinf.c
+++ b/newlib/libm/complex/csinf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -43,6 +43,6 @@ csinf(float complex z)
 	float ch, sh;
 
 	_cchshf(cimagf(z), &ch, &sh);
-	w = sinf(crealf(z)) * ch + (cosf(crealf(z)) * sh) * I;
+	w = sinf(crealf(z)) * ch + (cosf(crealf(z)) * sh) * I_f;
 	return w;
 }
diff --git a/newlib/libm/complex/csinhf.c b/newlib/libm/complex/csinhf.c
index 3cd6ba7f9..7efa0be33 100644
--- a/newlib/libm/complex/csinhf.c
+++ b/newlib/libm/complex/csinhf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -43,6 +43,6 @@ csinhf(float complex z)
 
 	x = crealf(z);
 	y = cimagf(z);
-	w = sinhf(x) * cosf(y) + (coshf(x) * sinf(y)) * I;
+	w = sinhf(x) * cosf(y) + (coshf(x) * sinf(y)) * I_f;
 	return w;
 }
diff --git a/newlib/libm/complex/csqrtf.c b/newlib/libm/complex/csqrtf.c
index 13451fa5a..5f8a2624a 100644
--- a/newlib/libm/complex/csqrtf.c
+++ b/newlib/libm/complex/csqrtf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -46,12 +46,12 @@ csqrtf(float complex z)
 
 	if (y == 0.0f) {
 		if (x < 0.0f) {
-			w = 0.0f + sqrtf(-x) * I;
+			w = 0.0f + sqrtf(-x) * I_f;
 			return w;
 		} else if (x == 0.0f) {
-			return (0.0f + y * I);
+			return (0.0f + y * I_f);
 		} else {
-			w = sqrtf(x) + y * I;
+			w = sqrtf(x) + y * I_f;
 			return w;
 		}
 	}
@@ -60,9 +60,9 @@ csqrtf(float complex z)
 		r = fabsf(y);
 		r = sqrtf(0.5f * r);
 		if (y > 0)
-			w = r + r * I;
+			w = r + r * I_f;
 		else
-			w = r - r * I;
+			w = r - r * I_f;
 		return w;
 	}
 
@@ -82,7 +82,7 @@ csqrtf(float complex z)
 		scale = 0.5f;
 #endif
 	}
-	w = x + y * I;
+	w = x + y * I_f;
 	r = cabsf(w);
 	if( x > 0 ) {
 		t = sqrtf(0.5f * r + 0.5f * x);
@@ -95,8 +95,8 @@ csqrtf(float complex z)
 	}
 
 	if (y < 0)
-		w = t - r * I;
+		w = t - r * I_f;
 	else
-		w = t + r * I;
+		w = t + r * I_f;
 	return w;
 }
diff --git a/newlib/libm/complex/ctanf.c b/newlib/libm/complex/ctanf.c
index a75ff1c66..63ca30731 100644
--- a/newlib/libm/complex/ctanf.c
+++ b/newlib/libm/complex/ctanf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -49,10 +49,10 @@ ctanf(float complex z)
 
 	if (d == 0.0f) {
 		/* mtherr ("ctan", OVERFLOW); */
-		w = HUGE_VALF + HUGE_VALF * I;
+		w = HUGE_VALF + HUGE_VALF * I_f;
 		return w;
 	}
 
-	w = sinf(2.0f * crealf(z)) / d + (sinhf(2.0f * cimagf(z)) / d) * I;
+	w = sinf(2.0f * crealf(z)) / d + (sinhf(2.0f * cimagf(z)) / d) * I_f;
 	return w;
 }
diff --git a/newlib/libm/complex/ctanhf.c b/newlib/libm/complex/ctanhf.c
index 6aaf20f1d..35dfd981b 100644
--- a/newlib/libm/complex/ctanhf.c
+++ b/newlib/libm/complex/ctanhf.c
@@ -5,7 +5,7 @@
  * All rights reserved.
  *
  * This code is derived from software written by Stephen L. Moshier.
- * It is redistributed by the NetBSD Foundation by permission of the author.
+ * I_ft is redistributed by the NetBSD Foundation by permission of the author.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
@@ -44,7 +44,7 @@ ctanhf(float complex z)
 	x = crealf(z);
 	y = cimagf(z);
 	d = coshf(2.0f * x) + cosf(2.0f * y);
-	w = sinhf(2.0f * x) / d  +  (sinf(2.0f * y) / d) * I;
+	w = sinhf(2.0f * x) / d  +  (sinf(2.0f * y) / d) * I_f;
 
 	return w;
 }
diff --git a/newlib/libm/math/ef_scalb.c b/newlib/libm/math/ef_scalb.c
index 8d973b1e7..ac8020bad 100644
--- a/newlib/libm/math/ef_scalb.c
+++ b/newlib/libm/math/ef_scalb.c
@@ -35,18 +35,18 @@
 #ifdef _SCALB_INT
 	return scalbnf(x,fn);
 #else
-	if (isnan(x)||isnan(fn)) return x*fn;
+	if (isnanf(x)||isnanf(fn)) return x*fn;
 	if (!finitef(fn)) {
 	    if(fn>(float)0.0) return x*fn;
 	    else       return x/(-fn);
 	}
 	if (rintf(fn)!=fn) return (fn-fn)/(fn-fn);
 #if INT_MAX > 65000
-	if ( fn > (float)65000.0) return scalbnf(x, 65000);
-	if (-fn > (float)65000.0) return scalbnf(x,-65000);
+	if ( fn > 65000.0f) return scalbnf(x, 65000);
+	if (-fn > 65000.0f) return scalbnf(x,-65000);
 #else
-	if ( fn > (float)32000.0) return scalbnf(x, 32000);
-	if (-fn > (float)32000.0) return scalbnf(x,-32000);
+	if ( fn > 32000.0f) return scalbnf(x, 32000);
+	if (-fn > 32000.0f) return scalbnf(x,-32000);
 #endif
 	return scalbnf(x,(int)fn);
 #endif
diff --git a/newlib/libm/math/wf_acos.c b/newlib/libm/math/wf_acos.c
index c24912de5..c0d832848 100644
--- a/newlib/libm/math/wf_acos.c
+++ b/newlib/libm/math/wf_acos.c
@@ -27,7 +27,7 @@
 #else
 	float z;
 	z = __ieee754_acosf(x);
-	if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
+	if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
 	if(fabsf(x)>1.0f) {
 	    /* acosf(|x|>1) */
 	    errno = EDOM;
diff --git a/newlib/libm/math/wf_acosh.c b/newlib/libm/math/wf_acosh.c
index 6a8000fee..b919b7464 100644
--- a/newlib/libm/math/wf_acosh.c
+++ b/newlib/libm/math/wf_acosh.c
@@ -33,7 +33,7 @@
 #else
 	float z;
 	z = __ieee754_acoshf(x);
-	if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
+	if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
 	if(x<1.0f) {
 	    /* acoshf(x<1) */
 	    errno = EDOM;
diff --git a/newlib/libm/math/wf_asin.c b/newlib/libm/math/wf_asin.c
index c9f15e352..c435f1725 100644
--- a/newlib/libm/math/wf_asin.c
+++ b/newlib/libm/math/wf_asin.c
@@ -34,7 +34,7 @@
 #else
 	float z;
 	z = __ieee754_asinf(x);
-	if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
+	if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
 	if(fabsf(x)>1.0f) {
 	    /* asinf(|x|>1) */
 	    errno = EDOM;
diff --git a/newlib/libm/math/wf_atanh.c b/newlib/libm/math/wf_atanh.c
index 31e049006..ccbf9452c 100644
--- a/newlib/libm/math/wf_atanh.c
+++ b/newlib/libm/math/wf_atanh.c
@@ -31,7 +31,7 @@
 #else
 	float z,y;
 	z = __ieee754_atanhf(x);
-	if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
+	if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
 	y = fabsf(x);
 	if(y>=1.0f) {
 	    if(y>1.0f) {
diff --git a/newlib/libm/math/wf_cosh.c b/newlib/libm/math/wf_cosh.c
index 976009914..b9cb4891a 100644
--- a/newlib/libm/math/wf_cosh.c
+++ b/newlib/libm/math/wf_cosh.c
@@ -32,7 +32,7 @@
 #else
 	float z;
 	z = __ieee754_coshf(x);
-	if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
+	if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
 	if(fabsf(x)>8.9415985107e+01f) {
 	    /* coshf(finite) overflow */
 	    errno = ERANGE;
diff --git a/newlib/libm/math/wf_fmod.c b/newlib/libm/math/wf_fmod.c
index 451318ea3..22ad50153 100644
--- a/newlib/libm/math/wf_fmod.c
+++ b/newlib/libm/math/wf_fmod.c
@@ -32,7 +32,7 @@
 #else
 	float z;
 	z = __ieee754_fmodf(x,y);
-	if(_LIB_VERSION == _IEEE_ ||isnan(y)||isnan(x)) return z;
+	if(_LIB_VERSION == _IEEE_ ||isnanf(y)||isnanf(x)) return z;
 	if(y==0.0f) {
             /* fmodf(x,0) */
 	    errno = EDOM;
diff --git a/newlib/libm/math/wf_j0.c b/newlib/libm/math/wf_j0.c
index ed21a01f5..2fc2db959 100644
--- a/newlib/libm/math/wf_j0.c
+++ b/newlib/libm/math/wf_j0.c
@@ -31,7 +31,7 @@
 	return __ieee754_j0f(x);
 #else
 	float z = __ieee754_j0f(x);
-	if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
+	if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
 	if(fabsf(x)>(float)X_TLOSS) {
 	    /* j0f(|x|>X_TLOSS) */
 	    errno = ERANGE;
@@ -52,7 +52,7 @@
 #else
 	float z;
 	z = __ieee754_y0f(x);
-	if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
+	if(_LIB_VERSION == _IEEE_ || isnanf(x) ) return z;
         if(x < 0.0f){
 	    /* y0f(x<0) = NaN */
 	    errno = EDOM;
diff --git a/newlib/libm/math/wf_j1.c b/newlib/libm/math/wf_j1.c
index a4609ba28..5ce379660 100644
--- a/newlib/libm/math/wf_j1.c
+++ b/newlib/libm/math/wf_j1.c
@@ -33,7 +33,7 @@
 #else
 	float z;
 	z = __ieee754_j1f(x);
-	if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
+	if(_LIB_VERSION == _IEEE_ || isnanf(x) ) return z;
 	if(fabsf(x)>(float)X_TLOSS) {
 	    /* j1f(|x|>X_TLOSS) */
 	    errno = ERANGE;
@@ -55,7 +55,7 @@
 #else
 	float z;
 	z = __ieee754_y1f(x);
-	if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
+	if(_LIB_VERSION == _IEEE_ || isnanf(x) ) return z;
         if(x < 0.0f){
 	    /* y1f(x<0) = NaN */
 	    errno = EDOM;
diff --git a/newlib/libm/math/wf_jn.c b/newlib/libm/math/wf_jn.c
index b82346d79..54712f86e 100644
--- a/newlib/libm/math/wf_jn.c
+++ b/newlib/libm/math/wf_jn.c
@@ -29,7 +29,7 @@
 #else
 	float z;
 	z = __ieee754_jnf(n,x);
-	if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
+	if(_LIB_VERSION == _IEEE_ || isnanf(x) ) return z;
 	if(fabsf(x)>(float)X_TLOSS) {
 	    /* jnf(|x|>X_TLOSS) */
 	    errno = ERANGE;
@@ -50,7 +50,7 @@
 #else
 	float z;
 	z = __ieee754_ynf(n,x);
-	if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
+	if(_LIB_VERSION == _IEEE_ || isnanf(x) ) return z;
         if(x < 0.0f){
 	    /* ynf(x<0) = NaN */
 	    errno = EDOM;
diff --git a/newlib/libm/math/wf_log.c b/newlib/libm/math/wf_log.c
index 97f4a7f1a..f6b34159a 100644
--- a/newlib/libm/math/wf_log.c
+++ b/newlib/libm/math/wf_log.c
@@ -33,7 +33,7 @@
 #else
 	float z;
 	z = __ieee754_logf(x);
-	if(_LIB_VERSION == _IEEE_ || isnan(x) || x > 0.0f) return z;
+	if(_LIB_VERSION == _IEEE_ || isnanf(x) || x > 0.0f) return z;
 	if(x==0.0f) {
 	    /* logf(0) */
 	    errno = ERANGE;
diff --git a/newlib/libm/math/wf_log10.c b/newlib/libm/math/wf_log10.c
index 529ed6514..f37221d4a 100644
--- a/newlib/libm/math/wf_log10.c
+++ b/newlib/libm/math/wf_log10.c
@@ -32,7 +32,7 @@
 #else
 	float z;
 	z = __ieee754_log10f(x);
-	if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
+	if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
 	if(x<=0.0f) {
 	    if(x==0.0f) {
 		/* log10f(0) */
diff --git a/newlib/libm/math/wf_pow.c b/newlib/libm/math/wf_pow.c
index e9babf67c..12586591c 100644
--- a/newlib/libm/math/wf_pow.c
+++ b/newlib/libm/math/wf_pow.c
@@ -33,7 +33,7 @@
 #else
 	float z;
 	z=__ieee754_powf(x,y);
-	if(_LIB_VERSION == _IEEE_|| isnan(y)) return z;
+	if(_LIB_VERSION == _IEEE_|| isnanf(y)) return z;
 	if(x==0.0f){
 	    if(y==0.0f) {
 		/* powf(0.0,0.0) */
@@ -48,7 +48,7 @@
 	}
 	if(!finitef(z)) {
 	    if(finitef(x)&&finitef(y)) {
-		if(isnan(z)) {
+		if(isnanf(z)) {
 		    /* neg**non-integral */
 		    errno = EDOM;
 		    /* Use a float divide, to avoid a soft-float double
diff --git a/newlib/libm/math/wf_remainder.c b/newlib/libm/math/wf_remainder.c
index 463d1bc32..be6a2614d 100644
--- a/newlib/libm/math/wf_remainder.c
+++ b/newlib/libm/math/wf_remainder.c
@@ -32,7 +32,7 @@
 #else
 	float z;
 	z = __ieee754_remainderf(x,y);
-	if(_LIB_VERSION == _IEEE_ || isnan(y)) return z;
+	if(_LIB_VERSION == _IEEE_ || isnanf(y)) return z;
 	if(y==0.0f) {
 	    /* remainderf(x,0) */
 	    errno = EDOM;
diff --git a/newlib/libm/math/wf_scalb.c b/newlib/libm/math/wf_scalb.c
index e87dc37dd..edb1a0f14 100644
--- a/newlib/libm/math/wf_scalb.c
+++ b/newlib/libm/math/wf_scalb.c
@@ -43,15 +43,15 @@
 	float z;
 	z = __ieee754_scalbf(x,fn);
 	if(_LIB_VERSION == _IEEE_) return z;
-	if(!(finitef(z)||isnan(z))&&finitef(x)) {
+	if(!(finitef(z)||isnanf(z))&&finitef(x)) {
 	    /* scalbf overflow; */
 	    errno = ERANGE;
-	    return (x > 0.0 ? HUGE_VALF : -HUGE_VALF);
+	    return (x > 0.0f ? HUGE_VALF : -HUGE_VALF);
 	}
 	if(z==0.0f&&z!=x) {
 	    /* scalbf underflow */
 	    errno = ERANGE;
-	    return copysign(0.0,x);
+	    return copysignf(0.0,x);
 	} 
 #ifndef _SCALB_INT
 	if(!finitef(fn)) errno = ERANGE;
diff --git a/newlib/libm/math/wf_sqrt.c b/newlib/libm/math/wf_sqrt.c
index 4107511ae..62aca0858 100644
--- a/newlib/libm/math/wf_sqrt.c
+++ b/newlib/libm/math/wf_sqrt.c
@@ -32,7 +32,7 @@
 #else
 	float z;
 	z = __ieee754_sqrtf(x);
-	if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
+	if(_LIB_VERSION == _IEEE_ || isnanf(x)) return z;
 	if(x<0.0f) {
 	    /* sqrtf(negative) */
 	    errno = EDOM;
-- 
2.28.0



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 4/6] libc/stdlib: Undefined shift negative value in a64l
  2020-08-20 22:14 [PATCH 0/6] Fixes inspired by building with clang Keith Packard
                   ` (2 preceding siblings ...)
  2020-08-20 22:14 ` [PATCH 3/6] Avoid implicit floating point conversions Keith Packard
@ 2020-08-20 22:14 ` Keith Packard
  2020-08-20 22:14 ` [PATCH 5/6] libc/stdlib: Clean up clang warnings Keith Packard
  2020-08-20 22:14 ` [PATCH 6/6] libc/stdio: Conditionally declare vars for _FSEEK_OPTIMIZATION Keith Packard
  5 siblings, 0 replies; 10+ messages in thread
From: Keith Packard @ 2020-08-20 22:14 UTC (permalink / raw)
  To: newlib

Shifting a negative value is not defined. Use an unsigned
value with the same bit pattern instead.

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 newlib/libc/stdlib/a64l.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/newlib/libc/stdlib/a64l.c b/newlib/libc/stdlib/a64l.c
index dcac2e050..a8b1b6e45 100644
--- a/newlib/libc/stdlib/a64l.c
+++ b/newlib/libc/stdlib/a64l.c
@@ -177,7 +177,7 @@ a64l (const char *input)
 #if LONG_MAX > 2147483647
   /* for implementations where long is > 32 bits, the result must be sign-extended */
   if (result & 0x80000000)
-      return (((long)-1 >> 32) << 32) + result;
+      return (~0UL << 32) + result;
 #endif
 
   return result;
-- 
2.28.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 5/6] libc/stdlib: Clean up clang warnings
  2020-08-20 22:14 [PATCH 0/6] Fixes inspired by building with clang Keith Packard
                   ` (3 preceding siblings ...)
  2020-08-20 22:14 ` [PATCH 4/6] libc/stdlib: Undefined shift negative value in a64l Keith Packard
@ 2020-08-20 22:14 ` Keith Packard
  2020-08-20 22:14 ` [PATCH 6/6] libc/stdio: Conditionally declare vars for _FSEEK_OPTIMIZATION Keith Packard
  5 siblings, 0 replies; 10+ messages in thread
From: Keith Packard @ 2020-08-20 22:14 UTC (permalink / raw)
  To: newlib

Eliminate hand-written strcpy in setenv.

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 newlib/libc/stdlib/setenv_r.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/newlib/libc/stdlib/setenv_r.c b/newlib/libc/stdlib/setenv_r.c
index 84d87a6ed..cdfa04f33 100644
--- a/newlib/libc/stdlib/setenv_r.c
+++ b/newlib/libc/stdlib/setenv_r.c
@@ -75,7 +75,7 @@ _setenv_r (struct _reent *reent_ptr,
         }
       if (strlen (C) >= l_value)
 	{			/* old larger; copy over */
-	  while ((*C++ = *value++) != 0);
+	  strcpy(C, value);
           ENV_UNLOCK;
 	  return 0;
 	}
-- 
2.28.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 6/6] libc/stdio: Conditionally declare vars for _FSEEK_OPTIMIZATION
  2020-08-20 22:14 [PATCH 0/6] Fixes inspired by building with clang Keith Packard
                   ` (4 preceding siblings ...)
  2020-08-20 22:14 ` [PATCH 5/6] libc/stdlib: Clean up clang warnings Keith Packard
@ 2020-08-20 22:14 ` Keith Packard
  5 siblings, 0 replies; 10+ messages in thread
From: Keith Packard @ 2020-08-20 22:14 UTC (permalink / raw)
  To: newlib

Both versions of fseek declare locals used only with
_FSEEK_OPTIMIZATION unconditionally which causes clang to emit a
warning. Protect those declarations with an #ifdef

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 newlib/libc/stdio/fseeko.c     | 6 ++++--
 newlib/libc/stdio64/fseeko64.c | 7 +++++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/newlib/libc/stdio/fseeko.c b/newlib/libc/stdio/fseeko.c
index 13df28bfc..0394cf183 100644
--- a/newlib/libc/stdio/fseeko.c
+++ b/newlib/libc/stdio/fseeko.c
@@ -99,14 +99,16 @@ _fseeko_r (struct _reent *ptr,
        int whence)
 {
   _fpos_t (*seekfn) (struct _reent *, void *, _fpos_t, int);
+#ifdef _FSEEK_OPTIMIZATION
   _fpos_t target;
-  _fpos_t curoff = 0;
   size_t n;
 #ifdef __USE_INTERNAL_STAT64
   struct stat64 st;
 #else
   struct stat st;
 #endif
+#endif
+  _fpos_t curoff = 0;
   int havepos;
 
   /* Make sure stdio is set up.  */
@@ -327,9 +329,9 @@ _fseeko_r (struct _reent *ptr,
    * We get here if we cannot optimise the seek ... just
    * do it.  Allow the seek function to change fp->_bf._base.
    */
+dumb:
 #endif
 
-dumb:
   if (_fflush_r (ptr, fp)
       || seekfn (ptr, fp->_cookie, offset, whence) == POS_ERR)
     {
diff --git a/newlib/libc/stdio64/fseeko64.c b/newlib/libc/stdio64/fseeko64.c
index 3087bef9e..1ee26750c 100644
--- a/newlib/libc/stdio64/fseeko64.c
+++ b/newlib/libc/stdio64/fseeko64.c
@@ -91,8 +91,11 @@ _fseeko64_r (struct _reent *ptr,
      int whence)
 {
   _fpos64_t (*seekfn) (struct _reent *, void *, _fpos64_t, int);
-  _fpos64_t target, curoff;
+  _fpos64_t curoff;
+#if _FSEEK_OPTIMIZATION
+  _fpos64_t target;
   size_t n;
+#endif
 
   struct stat64 st;
   int havepos;
@@ -318,9 +321,9 @@ _fseeko64_r (struct _reent *ptr,
    * We get here if we cannot optimise the seek ... just
    * do it.  Allow the seek function to change fp->_bf._base.
    */
+dumb:
 #endif
 
-dumb:
   if (_fflush_r (ptr, fp)
       || seekfn (ptr, fp->_cookie, offset, whence) == POS_ERR)
     {
-- 
2.28.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/6] Avoid implicit floating point conversions
  2020-08-20 22:14 ` [PATCH 3/6] Avoid implicit floating point conversions Keith Packard
@ 2020-08-20 22:43   ` Joseph Myers
       [not found]   ` <SN5P110MB03830A3D8272D82A089605659A5A0@SN5P110MB0383.NAMP110.PROD.OUTLOOK.COM>
  1 sibling, 0 replies; 10+ messages in thread
From: Joseph Myers @ 2020-08-20 22:43 UTC (permalink / raw)
  To: Keith Packard; +Cc: newlib

On Thu, 20 Aug 2020, Keith Packard via Newlib wrote:

> diff --git a/newlib/libc/include/complex.h b/newlib/libc/include/complex.h
> index 0a3ea97ed..13b300021 100644
> --- a/newlib/libc/include/complex.h
> +++ b/newlib/libc/include/complex.h
> @@ -9,8 +9,10 @@
>  #define	_COMPLEX_H
>  
>  #define complex _Complex
> -#define _Complex_I 1.0fi
> +#define _Complex_I 1.0i
> +#define _Complex_If 1.0if
>  #define I _Complex_I
> +#define I_f _Complex_If

This is contrary to the standard requirement that _Complex_I and I have 
type const float _Complex.

>  # ifndef INFINITY
> -#  define INFINITY (__builtin_inff())
> +#  define INFINITY (__builtin_inf())
> +# endif

This is contrary to the standard requirement that INFINITY has type float.

>  # ifndef NAN
> -#  define NAN (__builtin_nanf(""))
> +#  define NAN (__builtin_nan(""))
> +# endif

This is contrary to the standard requirement that NAN has type float.

>  #ifndef NO_ERRNO
> -  if (isinf (retval) && !isinf (val))
> +  if (isinff (retval) && !isinff (val))

isinf, isnan, etc. are *type-generic* macros.  If newlib is declaring them 
in a non-type-generic way, that should be fixed, rather than changing 
users to use a type-specific function.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Fw: [PATCH 3/6] Avoid implicit floating point conversions
       [not found]   ` <SN5P110MB03830A3D8272D82A089605659A5A0@SN5P110MB0383.NAMP110.PROD.OUTLOOK.COM>
@ 2020-08-20 23:03     ` C Howland
  2020-08-21  0:01       ` Keith Packard
  0 siblings, 1 reply; 10+ messages in thread
From: C Howland @ 2020-08-20 23:03 UTC (permalink / raw)
  To: newlib

> ------------------------------
> *From:* Newlib <newlib-bounces@sourceware.org> on behalf of Keith Packard
> via Newlib <newlib@sourceware.org>
> *Sent:* Thursday, August 20, 2020 6:14 PM
> *To:* newlib@sourceware.org <newlib@sourceware.org>
> *Subject:* [PATCH 3/6] Avoid implicit floating point conversions
>
>
>
> These were found with clang -Wdouble-promotion and show places where
> floating point values were being implicitly converted between
> representations. These conversions can result in unexpected use of
> double precision arithmetic. Those which are intentional all have an
> explicit cast added.
>
There are many troubles here along with many good things.  Some specific
ones are noted below, but a general one is that clang appears to be
generating spurious complaints--or else we need to fix something else
related to using clang.  The general problem is with replacing isnan() and
isinf() with isnanf() and isinff().  This is spurious because as of C99
isnan() and isinf() are defined to be macros that take a real-floating
type; they should be fine as they are.  In addition, the f variants of
those are not standard and ought to be called as __isinff() and __isnan()
if the subs really still need to be done.  Doesn't clang have something
like GCC's __builtin_isnan() to be used, for example?

>
> diff --git a/newlib/libc/include/complex.h b/newlib/libc/include/complex.h
> index 0a3ea97ed..13b300021 100644
> --- a/newlib/libc/include/complex.h
> +++ b/newlib/libc/include/complex.h
> @@ -9,8 +9,10 @@
>  #define        _COMPLEX_H
>
>  #define complex _Complex
> -#define _Complex_I 1.0fi
> +#define _Complex_I 1.0i
> +#define _Complex_If 1.0if
>  #define I _Complex_I
> +#define I_f _Complex_If
>
The standard defines _Complex_I as being type const float _Complex.

>
>  #include <sys/cdefs.h>
>
>
> diff --git a/newlib/libc/include/math.h b/newlib/libc/include/math.h
> index 5e6155cc4..d8e25ab5c 100644
> --- a/newlib/libc/include/math.h
> +++ b/newlib/libc/include/math.h
> @@ -28,11 +28,27 @@ _BEGIN_STD_C
>  # endif
>
>  # ifndef INFINITY
> -#  define INFINITY (__builtin_inff())
> +#  define INFINITY (__builtin_inf())
> +# endif
>
The standard says INFINITY is type float. Which makes this change wrong and
the following addition superfluous.  (You need INFINIITYD to complete the
set.)

> +
> +# ifndef INFINITYF
> +#  define INFINITYF (__builtin_inff())
> +# endif
> +
> +# ifndef INFINITYL
> +#  define INFINITYL (__builtin_infl())
>  # endif
>
>  # ifndef NAN
> -#  define NAN (__builtin_nanf(""))
> +#  define NAN (__builtin_nan(""))
> +# endif
>
The standard says NAN is type float. Same general problem as for INFINITY.

> +
> +# ifndef NANF
> +#  define NANF (__builtin_nanf(""))
> +# endif
> +
> +# ifndef NANL
> +#  define NANL (__builtin_nanl(""))
>  # endif
>
>  #else /* !gcc >= 3.3  */
>
>
> diff --git a/newlib/libm/common/sqrtl.c b/newlib/libm/common/sqrtl.c
> index 9976f35e7..234f1b7a3 100644
> --- a/newlib/libm/common/sqrtl.c
> +++ b/newlib/libm/common/sqrtl.c
> @@ -98,25 +98,6 @@ inc (long double x)
>    return ux.extu_ld;
>  }
>
> -/* Return (x - ulp) for normal positive x.  Assumes no underflow.  */
> -
> -static inline long double
> -dec (long double x)
> -{
> -  union ieee_ext_u ux = { .extu_ld = x, };
> -
> -  if (ux.extu_ext.ext_fracl-- == 0)
> -    {
> -      if (ux.extu_ext.ext_frach-- == LDBL_NBIT)
> -       {
> -         ux.extu_ext.ext_exp--;
> -         ux.extu_ext.ext_frach |= LDBL_NBIT;
> -       }
> -    }
> -
> -  return ux.extu_ld;
> -}
> -
>  /* This is slow, but simple and portable.  */
>
>  long double
> @@ -143,7 +124,7 @@ sqrtl (long double x)
>    if (ux.extu_ext.ext_exp == 0)
>      {
>        /* Adjust subnormal numbers.  */
> -      ux.extu_ld *= 0x1.0p514;
> +      ux.extu_ld *= 0x1.0p514l;
>        k = -514;
>      }
>    else
> @@ -167,10 +148,10 @@ sqrtl (long double x)
>    /* Newton's iteration.
>       Split ux.extu_ld into a high and low part to achieve additional
> precision.  */
>
> -  xn = sqrt ((double) ux.extu_ld);     /* 53-bit estimate of sqrtl(x).  */
> +  xn = (long double) sqrt ((double) ux.extu_ld);       /* 53-bit estimate
> of sqrtl(x).  */
>
>  #if LDBL_MANT_DIG > 100
> -  xn = (xn + (ux.extu_ld / xn)) * 0.5; /* 106-bit estimate.  */
> +  xn = (xn + (ux.extu_ld / xn)) * 0.5l;        /* 106-bit estimate.  */
>  #endif
>
>    lo = ux.extu_ld;
> diff --git a/newlib/libm/complex/cacosf.c b/newlib/libm/complex/cacosf.c
> index 3874dd5f6..ba698e584 100644
> --- a/newlib/libm/complex/cacosf.c
> +++ b/newlib/libm/complex/cacosf.c
> @@ -5,7 +5,7 @@
>   * All rights reserved.
>   *
>   * This code is derived from software written by Stephen L. Moshier.
> - * It is redistributed by the NetBSD Foundation by permission of the
> author.
> + * I_ft is redistributed by the NetBSD Foundation by permission of the
> author.
>   *
>   * Redistribution and use in source and binary forms, with or without
>   * modification, are permitted provided that the following conditions
> @@ -23,7 +23,7 @@
>   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
>   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
>   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
> IN
>   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
>   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
> THE
>   * POSSIBILITY OF SUCH DAMAGE.
> @@ -41,6 +41,6 @@ cacosf(float complex z)
>         float complex w;
>
>         w = casinf(z);
> -       w = ((float)M_PI_2 - crealf(w)) - cimagf(w) * I;
> +       w = ((float)M_PI_2 - crealf(w)) - cimagf(w) * I_f;
>         return w;
>  }
> diff --git a/newlib/libm/complex/cacoshf.c b/newlib/libm/complex/cacoshf.c
> index 41a557ad7..2ce04258e 100644
> --- a/newlib/libm/complex/cacoshf.c
> +++ b/newlib/libm/complex/cacoshf.c
> @@ -5,7 +5,7 @@
>   * All rights reserved.
>   *
>   * This code is derived from software written by Stephen L. Moshier.
> - * It is redistributed by the NetBSD Foundation by permission of the
> author.
> + * I_ft is redistributed by the NetBSD Foundation by permission of the
> author.
>   *
>   * Redistribution and use in source and binary forms, with or without
>   * modification, are permitted provided that the following conditions
> @@ -23,7 +23,7 @@
>   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
>   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
>   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
> IN
>   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
>   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
> THE
>   * POSSIBILITY OF SUCH DAMAGE.
> diff --git a/newlib/libm/complex/casinf.c b/newlib/libm/complex/casinf.c
> index 9a9f759ef..c4c120de4 100644
> --- a/newlib/libm/complex/casinf.c
> +++ b/newlib/libm/complex/casinf.c
> @@ -5,7 +5,7 @@
>   * All rights reserved.
>   *
>   * This code is derived from software written by Stephen L. Moshier.
> - * It is redistributed by the NetBSD Foundation by permission of the
> author.
> + * I_ft is redistributed by the NetBSD Foundation by permission of the
> author.
>   *
>   * Redistribution and use in source and binary forms, with or without
>   * modification, are permitted provided that the following conditions
> @@ -23,7 +23,7 @@
>   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
>   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
>   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
> IN
>   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
>   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
> THE
>   * POSSIBILITY OF SUCH DAMAGE.
> @@ -52,12 +52,12 @@ casinf(float complex z)
>  #if 0 /* MD: test is incorrect, casin(>1) is defined */
>         if (y == 0.0f) {
>                 if (fabsf(x) > 1.0) {
> -                       w = M_PI_2 + 0.0f * I;
> +                       w = M_PI_2 + 0.0f * I_f;
>  #if 0
>                         mtherr ("casin", DOMAIN);
>  #endif
>                 } else {
> -                       w = asinf(x) + 0.0f * I;
> +                       w = asinf(x) + 0.0f * I_f;
>                 }
>                 return w;
>         }
> @@ -104,19 +104,19 @@ return;
>  */
>
>
> -       ca = x + y * I;
> -       ct = ca * I;
> +       ca = x + y * I_f;
> +       ct = ca * I_f;
>         /* sqrt( 1 - z*z) */
>         /* cmul( &ca, &ca, &zz ) */
>         /*x * x  -  y * y */
> -       zz = (x - y) * (x + y) + (2.0f * x * y) * I;
> +       zz = (x - y) * (x + y) + (2.0f * x * y) * I_f;
>
> -       zz = 1.0f - crealf(zz) - cimagf(zz) * I;
> +       zz = 1.0f - crealf(zz) - cimagf(zz) * I_f;
>         z2 = csqrtf(zz);
>
>         zz = ct + z2;
>         zz = clogf(zz);
>         /* multiply by 1/i = -i */
> -       w = zz * (-1.0f * I);
> +       w = zz * (-1.0f * I_f);
>         return w;
>  }
> diff --git a/newlib/libm/complex/casinhf.c b/newlib/libm/complex/casinhf.c
> index 0db55a0ad..b9b92d2c7 100644
> --- a/newlib/libm/complex/casinhf.c
> +++ b/newlib/libm/complex/casinhf.c
> @@ -5,7 +5,7 @@
>   * All rights reserved.
>   *
>   * This code is derived from software written by Stephen L. Moshier.
> - * It is redistributed by the NetBSD Foundation by permission of the
> author.
> + * I_ft is redistributed by the NetBSD Foundation by permission of the
> author.
>   *
>   * Redistribution and use in source and binary forms, with or without
>   * modification, are permitted provided that the following conditions
> @@ -23,7 +23,7 @@
>   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
>   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
>   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
> IN
>   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
>   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
> THE
>   * POSSIBILITY OF SUCH DAMAGE.
> @@ -39,6 +39,6 @@ casinhf(float complex z)
>  {
>         float complex w;
>
> -       w = -1.0f * I * casinf(z * I);
> +       w = -1.0f * I_f * casinf(z * I_f);
>         return w;
>  }
> diff --git a/newlib/libm/complex/catanf.c b/newlib/libm/complex/catanf.c
> index ac1a65c08..1043e193b 100644
> --- a/newlib/libm/complex/catanf.c
> +++ b/newlib/libm/complex/catanf.c
> @@ -5,7 +5,7 @@
>   * All rights reserved.
>   *
>   * This code is derived from software written by Stephen L. Moshier.
> - * It is redistributed by the NetBSD Foundation by permission of the
> author.
> + * I_ft is redistributed by the NetBSD Foundation by permission of the
> author.
>   *
>   * Redistribution and use in source and binary forms, with or without
>   * modification, are permitted provided that the following conditions
> @@ -23,7 +23,7 @@
>   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
>   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
>   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
> IN
>   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
>   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
> THE
>   * POSSIBILITY OF SUCH DAMAGE.
> @@ -67,13 +67,13 @@ catanf(float complex z)
>
>         t = y + 1.0f;
>         a = (x2 + (t * t))/a;
> -       w = w + (0.25f * logf(a)) * I;
> +       w = w + (0.25f * logf(a)) * I_f;
>         return w;
>
>  ovrf:
>  #if 0
>         mtherr ("catan", OVERFLOW);
>  #endif
> -       w = HUGE_VALF + HUGE_VALF * I;
> +       w = HUGE_VALF + HUGE_VALF * I_f;
>         return w;
>  }
> diff --git a/newlib/libm/complex/catanhf.c b/newlib/libm/complex/catanhf.c
> index fe6127a9d..96dfafb26 100644
> --- a/newlib/libm/complex/catanhf.c
> +++ b/newlib/libm/complex/catanhf.c
> @@ -5,7 +5,7 @@
>   * All rights reserved.
>   *
>   * This code is derived from software written by Stephen L. Moshier.
> - * It is redistributed by the NetBSD Foundation by permission of the
> author.
> + * I_ft is redistributed by the NetBSD Foundation by permission of the
> author.
>   *
>   * Redistribution and use in source and binary forms, with or without
>   * modification, are permitted provided that the following conditions
> @@ -23,7 +23,7 @@
>   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
>   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
>   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
> IN
>   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
>   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
> THE
>   * POSSIBILITY OF SUCH DAMAGE.
> @@ -39,6 +39,6 @@ catanhf(float complex z)
>  {
>         float complex w;
>
> -       w = -1.0f * I * catanf(z * I);
> +       w = -1.0f * I_f * catanf(z * I_f);
>         return w;
>  }
> diff --git a/newlib/libm/complex/ccosf.c b/newlib/libm/complex/ccosf.c
> index 805e24feb..1520aec36 100644
> --- a/newlib/libm/complex/ccosf.c
> +++ b/newlib/libm/complex/ccosf.c
> @@ -5,7 +5,7 @@
>   * All rights reserved.
>   *
>   * This code is derived from software written by Stephen L. Moshier.
> - * It is redistributed by the NetBSD Foundation by permission of the
> author.
> + * I_ft is redistributed by the NetBSD Foundation by permission of the
> author.
>   *
>   * Redistribution and use in source and binary forms, with or without
>   * modification, are permitted provided that the following conditions
> @@ -23,7 +23,7 @@
>   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
>   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
>   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
> IN
>   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
>   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
> THE
>   * POSSIBILITY OF SUCH DAMAGE.
> @@ -43,6 +43,6 @@ ccosf(float complex z)
>         float ch, sh;
>
>         _cchshf(cimagf(z), &ch, &sh);
> -       w = cosf(crealf(z)) * ch - (sinf(crealf(z)) * sh) * I;
> +       w = cosf(crealf(z)) * ch - (sinf(crealf(z)) * sh) * I_f;
>         return w;
>  }
> diff --git a/newlib/libm/complex/ccoshf.c b/newlib/libm/complex/ccoshf.c
> index af11353e4..118e85542 100644
> --- a/newlib/libm/complex/ccoshf.c
> +++ b/newlib/libm/complex/ccoshf.c
> @@ -5,7 +5,7 @@
>   * All rights reserved.
>   *
>   * This code is derived from software written by Stephen L. Moshier.
> - * It is redistributed by the NetBSD Foundation by permission of the
> author.
> + * I_ft is redistributed by the NetBSD Foundation by permission of the
> author.
>   *
>   * Redistribution and use in source and binary forms, with or without
>   * modification, are permitted provided that the following conditions
> @@ -23,7 +23,7 @@
>   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
>   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
>   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
> IN
>   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
>   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
> THE
>   * POSSIBILITY OF SUCH DAMAGE.
> @@ -43,6 +43,6 @@ ccoshf(float complex z)
>
>         x = crealf(z);
>         y = cimagf(z);
> -       w = coshf(x) * cosf(y) + (sinhf(x) * sinf(y)) * I;
> +       w = coshf(x) * cosf(y) + (sinhf(x) * sinf(y)) * I_f;
>         return w;
>  }
> diff --git a/newlib/libm/complex/cephes_subrf.c
> b/newlib/libm/complex/cephes_subrf.c
> index 4a325811f..98b5a74f3 100644
> --- a/newlib/libm/complex/cephes_subrf.c
> +++ b/newlib/libm/complex/cephes_subrf.c
> @@ -5,7 +5,7 @@
>   * All rights reserved.
>   *
>   * This code is derived from software written by Stephen L. Moshier.
> - * It is redistributed by the NetBSD Foundation by permission of the
> author.
> + * I_ft is redistributed by the NetBSD Foundation by permission of the
> author.
>   *
>   * Redistribution and use in source and binary forms, with or without
>   * modification, are permitted provided that the following conditions
> @@ -23,7 +23,7 @@
>   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
>   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
>   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
> BUSINESS
> - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * I_fNTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
> IN
>   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
>   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
> THE
>   * POSSIBILITY OF SUCH DAMAGE.
> @@ -61,7 +61,7 @@ _cchshf(float x, float *c, float *s)
>  static const double DP1 =  3.140625;
>  static const double DP2 =  9.67502593994140625E-4;
>  static const double DP3 =  1.509957990978376432E-7;
> -#define MACHEPF 3.0e-8
> +#define MACHEPF 3.0e-8f
>
>  float
>  _redupif(float x)
> @@ -77,7 +77,7 @@ _redupif(float x)
>
>         i = t;  /* the multiple */
>         t = i;
> -       t = ((x - t * DP1) - t * DP2) - t * DP3;
> +       t = (((double) x - (double) t * DP1) - (double) t * DP2) -
> (double) t * DP3;
>
This is simply nuts:  the language clearly defines promotion rules.  All
get turned into double if there's a single double in it, so one cast should
be enough. If the compiler complains otherwise we should be complaining
about the compiler, not kowtowing to its warnings.  We should not allow
compiler warnings to make code unreadable.

>         return t;
>
>
I did not exhaustively look at every change, only scanning a bit towards
the end.  Except as noted, seemed generally sane.
(I finally got a non-work email address to use for Newlib, since my company
started putting auto-tags on outgoing email that causes the Newlib list
server to bounce them.)
I see that Joseph Myers types faster than me and so some of these comments
have already  been made, but since I've already typed it in I'm not going
back to re-edit.
Craig

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Fw: [PATCH 3/6] Avoid implicit floating point conversions
  2020-08-20 23:03     ` Fw: " C Howland
@ 2020-08-21  0:01       ` Keith Packard
  0 siblings, 0 replies; 10+ messages in thread
From: Keith Packard @ 2020-08-21  0:01 UTC (permalink / raw)
  To: C Howland, newlib

[-- Attachment #1: Type: text/plain, Size: 3108 bytes --]

C Howland via Newlib <newlib@sourceware.org> writes:

> There are many troubles here along with many good things.  Some specific
> ones are noted below, but a general one is that clang appears to be
> generating spurious complaints--or else we need to fix something else
> related to using clang.  The general problem is with replacing isnan() and
> isinf() with isnanf() and isinff().  This is spurious because as of C99
> isnan() and isinf() are defined to be macros that take a real-floating
> type; they should be fine as they are.  In addition, the f variants of
> those are not standard and ought to be called as __isinff() and __isnan()
> if the subs really still need to be done.  Doesn't clang have something
> like GCC's __builtin_isnan() to be used, for example?

Right, but the newlib header files weren't using it due to the tests
being GCC specific. I've fixed that and the resulting patch is
significantly smaller. I'll be posting that as a short series
separately.

> The standard defines _Complex_I as being type const float _Complex.

Thanks; that really helps my understanding here. I've removed those
changes and added a (bunch of) casts from these constants to the
appropriate type when used inside the library.

>>  float
>>  _redupif(float x)
>> @@ -77,7 +77,7 @@ _redupif(float x)
>>
>>         i = t;  /* the multiple */
>>         t = i;
>> -       t = ((x - t * DP1) - t * DP2) - t * DP3;
>> +       t = (((double) x - (double) t * DP1) - (double) t * DP2) -
>> (double) t * DP3;
>>
> This is simply nuts:  the language clearly defines promotion rules.  All
> get turned into double if there's a single double in it, so one cast should
> be enough. If the compiler complains otherwise we should be complaining
> about the compiler, not kowtowing to its warnings.  We should not allow
> compiler warnings to make code unreadable.

Yes, the default promotion rules work for this case, but enabling use of
this extra clang warning resulted in finding numerous places where the
default promotion rules were causing computations to be done in higher
precision than necessary. And, enabling the warning encourages "fixing"
even cases where the code is correct.

So, we can either leave the code generating warnings with the clang
flag, use this (rather ugly) version, or introduce some temporary locals
of 'double' type and eliminate the casts from this line.

> I did not exhaustively look at every change, only scanning a bit towards
> the end.  Except as noted, seemed generally sane.

Thanks for your review; all of these fixes have been run through the
newlib test suite on a rather large number of architectures without
introducing any changes.

> I see that Joseph Myers types faster than me and so some of these comments
> have already  been made, but since I've already typed it in I'm not going
> back to re-edit.

I'll make sure he hasn't caught anything additional; thanks to both of
you for fixing my mis-understanding of the types of the various math.h
constants!

New series coming shortly.

-- 
-keith

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-08-21  0:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-20 22:14 [PATCH 0/6] Fixes inspired by building with clang Keith Packard
2020-08-20 22:14 ` [PATCH 1/6] libm/stdlib: Recover from realloc failure when shrinking Keith Packard
2020-08-20 22:14 ` [PATCH 2/6] libc/iconv: Check ces handlers table value in euc_from_ucs_init Keith Packard
2020-08-20 22:14 ` [PATCH 3/6] Avoid implicit floating point conversions Keith Packard
2020-08-20 22:43   ` Joseph Myers
     [not found]   ` <SN5P110MB03830A3D8272D82A089605659A5A0@SN5P110MB0383.NAMP110.PROD.OUTLOOK.COM>
2020-08-20 23:03     ` Fw: " C Howland
2020-08-21  0:01       ` Keith Packard
2020-08-20 22:14 ` [PATCH 4/6] libc/stdlib: Undefined shift negative value in a64l Keith Packard
2020-08-20 22:14 ` [PATCH 5/6] libc/stdlib: Clean up clang warnings Keith Packard
2020-08-20 22:14 ` [PATCH 6/6] libc/stdio: Conditionally declare vars for _FSEEK_OPTIMIZATION Keith Packard

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).