[libc-commits] [libc] e328d19 - [libc] Fix final conversion warnings

Michael Jones via libc-commits libc-commits at lists.llvm.org
Wed Aug 9 10:24:07 PDT 2023


Author: Michael Jones
Date: 2023-08-09T10:24:03-07:00
New Revision: e328d193024e727d7294cd8bed4c549c25c62246

URL: https://github.com/llvm/llvm-project/commit/e328d193024e727d7294cd8bed4c549c25c62246
DIFF: https://github.com/llvm/llvm-project/commit/e328d193024e727d7294cd8bed4c549c25c62246.diff

LOG: [libc] Fix final conversion warnings

This patch fixes the floating point conversion warnings found with
`-Wconversion` and `-Wno-sign-conversion`. These were the last warnings
I found, meaning that once this lands https://reviews.llvm.org/D156630
should be unblocked.

Reviewed By: mcgrathr, lntue

Differential Revision: https://reviews.llvm.org/D157449

Added: 
    

Modified: 
    libc/src/math/generic/exp2f.cpp
    libc/src/math/generic/tanhf.cpp
    libc/src/time/difftime.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/math/generic/exp2f.cpp b/libc/src/math/generic/exp2f.cpp
index b967a4bb453713..2a5776ad6ca712 100644
--- a/libc/src/math/generic/exp2f.cpp
+++ b/libc/src/math/generic/exp2f.cpp
@@ -65,7 +65,7 @@ LLVM_LIBC_FUNCTION(float, exp2f, (float x)) {
       double c2 = fputil::multiply_add(xd, COEFFS[5], COEFFS[4]);
       double p = fputil::polyeval(xsq, c0, c1, c2);
       double r = fputil::multiply_add(p, xd, 1.0);
-      return r;
+      return static_cast<float>(r);
     }
 
     // x >= 128

diff  --git a/libc/src/math/generic/tanhf.cpp b/libc/src/math/generic/tanhf.cpp
index 21c3ed8c8c3333..1620e370402167 100644
--- a/libc/src/math/generic/tanhf.cpp
+++ b/libc/src/math/generic/tanhf.cpp
@@ -56,7 +56,7 @@ LLVM_LIBC_FUNCTION(float, tanhf, (float x)) {
     if (LIBC_UNLIKELY(xbits.is_nan()))
       return x + 1.0f; // sNaN to qNaN + signal
 
-    const double SIGNS[2][2] = {{1.0f, -0x1.0p-25f}, {-1.0f, 0x1.0p-25f}};
+    constexpr float SIGNS[2][2] = {{1.0f, -0x1.0p-25f}, {-1.0f, 0x1.0p-25f}};
 
     bool sign = xbits.get_sign();
     int idx = static_cast<int>(sign);

diff  --git a/libc/src/time/
diff time.cpp b/libc/src/time/
diff time.cpp
index b42b1f4fd13008..7b4526783f7070 100644
--- a/libc/src/time/
diff time.cpp
+++ b/libc/src/time/
diff time.cpp
@@ -12,7 +12,7 @@
 namespace __llvm_libc {
 
 LLVM_LIBC_FUNCTION(double, 
diff time, (time_t end, time_t beginning)) {
-  return end - beginning;
+  return static_cast<double>(end - beginning);
 }
 
 } // namespace __llvm_libc


        


More information about the libc-commits mailing list