[libc-commits] [libc] adff2b2 - [libc][NFC] Switch all uses of errno in math and math tests to libc_errno.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Mon Mar 13 15:22:42 PDT 2023


Author: Siva Chandra Reddy
Date: 2023-03-13T22:22:00Z
New Revision: adff2b291ca872ec585d4aaeed2aaca563c72795

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

LOG: [libc][NFC] Switch all uses of errno in math and math tests to libc_errno.

Added: 
    

Modified: 
    libc/src/math/generic/math_utils.h
    libc/test/src/math/CMakeLists.txt
    libc/test/src/math/exp10f_test.cpp
    libc/test/src/math/exp2f_test.cpp
    libc/test/src/math/expf_test.cpp
    libc/test/src/math/expm1f_test.cpp
    libc/test/src/math/log2f_test.cpp
    libc/test/src/math/logf_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/math/generic/math_utils.h b/libc/src/math/generic/math_utils.h
index 7a43e58806329..0399f7d0adfff 100644
--- a/libc/src/math/generic/math_utils.h
+++ b/libc/src/math/generic/math_utils.h
@@ -12,7 +12,8 @@
 #include "src/__support/CPP/bit.h"
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/common.h"
-#include <errno.h>
+#include "src/errno/libc_errno.h"
+
 #include <math.h>
 
 #include <stdint.h>
@@ -52,7 +53,7 @@ template <> struct XFlowValues<double> {
 
 template <typename T> LIBC_INLINE T with_errno(T x, int err) {
   if (math_errhandling & MATH_ERRNO)
-    errno = err;
+    libc_errno = err;
   return x;
 }
 

diff  --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 0a929ff56d292..37e6183593b68 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -1355,6 +1355,7 @@ add_fp_unittest(
     FModTest.h
   DEPENDS
     libc.include.math
+    libc.src.errno.errno
     libc.src.math.fmodf
     libc.src.__support.FPUtil.basic_operations
     libc.src.__support.FPUtil.nearest_integer_operations
@@ -1370,6 +1371,7 @@ add_fp_unittest(
     FModTest.h
   DEPENDS
     libc.include.math
+    libc.src.errno.errno
     libc.src.math.fmod
     libc.src.__support.FPUtil.basic_operations
     libc.src.__support.FPUtil.nearest_integer_operations

diff  --git a/libc/test/src/math/exp10f_test.cpp b/libc/test/src/math/exp10f_test.cpp
index 684aa017479c1..2feb064cf565b 100644
--- a/libc/test/src/math/exp10f_test.cpp
+++ b/libc/test/src/math/exp10f_test.cpp
@@ -14,7 +14,6 @@
 #include "utils/MPFRWrapper/MPFRUtils.h"
 #include <math.h>
 
-#include <errno.h>
 #include <stdint.h>
 
 namespace mpfr = __llvm_libc::testing::mpfr;
@@ -120,7 +119,7 @@ TEST(LlvmLibcExp10fTest, InFloatRange) {
     // in the single-precision floating point range, then ignore comparing with
     // MPFR result as MPFR can still produce valid results because of its
     // wider precision.
-    if (isnan(result) || isinf(result) || errno != 0)
+    if (isnan(result) || isinf(result) || libc_errno != 0)
       continue;
     ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp10, x,
                                    __llvm_libc::exp10f(x), 0.5);

diff  --git a/libc/test/src/math/exp2f_test.cpp b/libc/test/src/math/exp2f_test.cpp
index 22abd23d8155e..e442a7c57a5e1 100644
--- a/libc/test/src/math/exp2f_test.cpp
+++ b/libc/test/src/math/exp2f_test.cpp
@@ -15,7 +15,6 @@
 #include "utils/MPFRWrapper/MPFRUtils.h"
 #include <math.h>
 
-#include <errno.h>
 #include <stdint.h>
 
 namespace mpfr = __llvm_libc::testing::mpfr;
@@ -117,7 +116,7 @@ TEST(LlvmLibcExp2fTest, InFloatRange) {
     // in the single-precision floating point range, then ignore comparing with
     // MPFR result as MPFR can still produce valid results because of its
     // wider precision.
-    if (isnan(result) || isinf(result) || errno != 0)
+    if (isnan(result) || isinf(result) || libc_errno != 0)
       continue;
     ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp2, x,
                                    __llvm_libc::exp2f(x), 0.5);

diff  --git a/libc/test/src/math/expf_test.cpp b/libc/test/src/math/expf_test.cpp
index a38bcbd01dd56..1926c9c03da0c 100644
--- a/libc/test/src/math/expf_test.cpp
+++ b/libc/test/src/math/expf_test.cpp
@@ -14,7 +14,6 @@
 #include "utils/MPFRWrapper/MPFRUtils.h"
 #include <math.h>
 
-#include <errno.h>
 #include <stdint.h>
 
 namespace mpfr = __llvm_libc::testing::mpfr;
@@ -118,7 +117,7 @@ TEST(LlvmLibcExpfTest, InFloatRange) {
     // in the single-precision floating point range, then ignore comparing with
     // MPFR result as MPFR can still produce valid results because of its
     // wider precision.
-    if (isnan(result) || isinf(result) || errno != 0)
+    if (isnan(result) || isinf(result) || libc_errno != 0)
       continue;
     EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Exp, x,
                                    __llvm_libc::expf(x), 0.5);

diff  --git a/libc/test/src/math/expm1f_test.cpp b/libc/test/src/math/expm1f_test.cpp
index 8ea85f7915c5b..81bc18a18dccc 100644
--- a/libc/test/src/math/expm1f_test.cpp
+++ b/libc/test/src/math/expm1f_test.cpp
@@ -14,7 +14,6 @@
 #include "utils/MPFRWrapper/MPFRUtils.h"
 #include <math.h>
 
-#include <errno.h>
 #include <stdint.h>
 
 namespace mpfr = __llvm_libc::testing::mpfr;
@@ -127,7 +126,7 @@ TEST(LlvmLibcExpm1fTest, InFloatRange) {
     // in the single-precision floating point range, then ignore comparing with
     // MPFR result as MPFR can still produce valid results because of its
     // wider precision.
-    if (isnan(result) || isinf(result) || errno != 0)
+    if (isnan(result) || isinf(result) || libc_errno != 0)
       continue;
     ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Expm1, x,
                                    __llvm_libc::expm1f(x), 0.5);

diff  --git a/libc/test/src/math/log2f_test.cpp b/libc/test/src/math/log2f_test.cpp
index bef2ffdada7e7..73bc2b02c5dcb 100644
--- a/libc/test/src/math/log2f_test.cpp
+++ b/libc/test/src/math/log2f_test.cpp
@@ -14,7 +14,6 @@
 #include "utils/MPFRWrapper/MPFRUtils.h"
 #include <math.h>
 
-#include <errno.h>
 #include <stdint.h>
 
 namespace mpfr = __llvm_libc::testing::mpfr;
@@ -57,7 +56,7 @@ TEST(LlvmLibcLog2fTest, InFloatRange) {
     // in the single-precision floating point range, then ignore comparing with
     // MPFR result as MPFR can still produce valid results because of its
     // wider precision.
-    if (isnan(result) || isinf(result) || errno != 0)
+    if (isnan(result) || isinf(result) || libc_errno != 0)
       continue;
     ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Log2, x,
                                    __llvm_libc::log2f(x), 0.5);

diff  --git a/libc/test/src/math/logf_test.cpp b/libc/test/src/math/logf_test.cpp
index 4feb1ad99bfca..bf3aad7893992 100644
--- a/libc/test/src/math/logf_test.cpp
+++ b/libc/test/src/math/logf_test.cpp
@@ -13,7 +13,6 @@
 #include "utils/MPFRWrapper/MPFRUtils.h"
 #include <math.h>
 
-#include <errno.h>
 #include <stdint.h>
 
 namespace mpfr = __llvm_libc::testing::mpfr;


        


More information about the libc-commits mailing list