[libc-commits] [libc] dba1481 - [libc][NFC] Make few maths functions buildable outside of LLVM libc build.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Tue Feb 16 09:15:31 PST 2021


Author: Siva Chandra Reddy
Date: 2021-02-16T09:14:29-08:00
New Revision: dba14814a69143a8763ed4276a38fa9509b5973d

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

LOG: [libc][NFC] Make few maths functions buildable outside of LLVM libc build.

Few math functions manipulate errno. They assumed that LLVM libc's errno
is available. However, that might not be the case when these functions
are used in a libc which does not use LLVM libc's errno. This change
switches such uses of LLVM libc's errno to the normal public errno macro.
This does not affect LLVM libc's build because the include order ensures
we get LLVM libc's errno. Also, the header check rule ensures we are only
including LLVM libc's errno.h.

Added: 
    

Modified: 
    libc/test/src/math/RoundToIntegerTest.h
    libc/utils/FPUtil/CMakeLists.txt
    libc/utils/FPUtil/NearestIntegerOperations.h

Removed: 
    


################################################################################
diff  --git a/libc/test/src/math/RoundToIntegerTest.h b/libc/test/src/math/RoundToIntegerTest.h
index 4b28039dbbb3..63b04845f8fc 100644
--- a/libc/test/src/math/RoundToIntegerTest.h
+++ b/libc/test/src/math/RoundToIntegerTest.h
@@ -9,7 +9,6 @@
 #ifndef LLVM_LIBC_TEST_SRC_MATH_ROUNDTOINTEGERTEST_H
 #define LLVM_LIBC_TEST_SRC_MATH_ROUNDTOINTEGERTEST_H
 
-#include "src/errno/llvmlibc_errno.h"
 #include "utils/FPUtil/FPBits.h"
 #include "utils/MPFRWrapper/MPFRUtils.h"
 #include "utils/UnitTest/Test.h"
@@ -47,7 +46,7 @@ class RoundToIntegerTestTemplate : public __llvm_libc::testing::Test {
   void testOneInput(RoundToIntegerFunc func, F input, I expected,
                     bool expectError) {
 #if math_errhandling & MATH_ERRNO
-    llvmlibc_errno = 0;
+    errno = 0;
 #endif
 #if math_errhandling & MATH_ERREXCEPT
     __llvm_libc::fputil::clearExcept(FE_ALL_EXCEPT);
@@ -60,14 +59,14 @@ class RoundToIntegerTestTemplate : public __llvm_libc::testing::Test {
       ASSERT_EQ(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT), FE_INVALID);
 #endif
 #if math_errhandling & MATH_ERRNO
-      ASSERT_EQ(llvmlibc_errno, EDOM);
+      ASSERT_EQ(errno, EDOM);
 #endif
     } else {
 #if math_errhandling & MATH_ERREXCEPT
       ASSERT_EQ(__llvm_libc::fputil::testExcept(FE_ALL_EXCEPT), 0);
 #endif
 #if math_errhandling & MATH_ERRNO
-      ASSERT_EQ(llvmlibc_errno, 0);
+      ASSERT_EQ(errno, 0);
 #endif
     }
   }

diff  --git a/libc/utils/FPUtil/CMakeLists.txt b/libc/utils/FPUtil/CMakeLists.txt
index c54184ec775f..2c1c1661a578 100644
--- a/libc/utils/FPUtil/CMakeLists.txt
+++ b/libc/utils/FPUtil/CMakeLists.txt
@@ -31,7 +31,6 @@ add_header_library(
     libc.include.math
     libc.include.errno
     libc.include.fenv
-    libc.src.errno.__errno_location
     libc.utils.CPP.standalone_cpp
 )
 

diff  --git a/libc/utils/FPUtil/NearestIntegerOperations.h b/libc/utils/FPUtil/NearestIntegerOperations.h
index 6af4c4ccf913..004f269009d4 100644
--- a/libc/utils/FPUtil/NearestIntegerOperations.h
+++ b/libc/utils/FPUtil/NearestIntegerOperations.h
@@ -16,7 +16,6 @@
 
 #include <math.h>
 #if math_errhandling & MATH_ERRNO
-#include "src/errno/llvmlibc_errno.h"
 #include <errno.h>
 #endif
 
@@ -247,7 +246,7 @@ static inline I roundedFloatToSignedInteger(F x) {
   FPBits<F> bits(x);
   auto setDomainErrorAndRaiseInvalid = []() {
 #if math_errhandling & MATH_ERRNO
-    llvmlibc_errno = EDOM;
+    errno = EDOM; // NOLINT
 #endif
 #if math_errhandling & MATH_ERREXCEPT
     raiseExcept(FE_INVALID);


        


More information about the libc-commits mailing list