[libc-commits] [libc] [libc] fix unit tests in fullbuild (PR #78864)
Schrodinger ZHU Yifan via libc-commits
libc-commits at lists.llvm.org
Sun Jan 21 12:31:08 PST 2024
https://github.com/SchrodingerZhu updated https://github.com/llvm/llvm-project/pull/78864
>From d98e27a370c73f5d9e4de3efc1f2402f5305271e Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
Date: Sat, 20 Jan 2024 16:22:49 -0500
Subject: [PATCH 1/5] [libc] fix unit tests in fullbuild
---
libc/cmake/modules/LLVMLibCTestRules.cmake | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 24f543f6e4c132b..9b7e9180275414a 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -187,7 +187,7 @@ function(create_libc_unittest fq_target_name)
if(LLVM_LIBC_FULL_BUILD)
target_compile_options(
${fq_build_target_name}
- PRIVATE -ffreestanding
+ PRIVATE -ffreestanding -fno-exceptions -fno-rtti -fno-unwind-tables -fno-asynchronous-unwind-tables
)
endif()
if(LIBC_UNITTEST_COMPILE_OPTIONS)
>From bb1897f1ffc44cd719a3cf528773e7f6789e098b Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
Date: Sat, 20 Jan 2024 16:33:43 -0500
Subject: [PATCH 2/5] fix: add freestanding flags for MPFR
---
libc/utils/MPFRWrapper/CMakeLists.txt | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/libc/utils/MPFRWrapper/CMakeLists.txt b/libc/utils/MPFRWrapper/CMakeLists.txt
index d9fa0e31df0e507..0f935da183198cc 100644
--- a/libc/utils/MPFRWrapper/CMakeLists.txt
+++ b/libc/utils/MPFRWrapper/CMakeLists.txt
@@ -1,4 +1,13 @@
if(LIBC_TESTS_CAN_USE_MPFR)
+ if (LLVM_LIBC_FULL_BUILD)
+ add_compile_options(
+ -ffreestanding
+ -fno-exceptions
+ -fno-rtti
+ -fno-unwind-tables
+ -fno-asynchronous-unwind-tables
+ )
+ endif()
add_library(libcMPFRWrapper
MPFRUtils.cpp
MPFRUtils.h
>From d89d06bfad6057b7e5ae364a3370d638ae4be703 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
Date: Sat, 20 Jan 2024 22:59:08 -0500
Subject: [PATCH 3/5] fix: add in missing stdlibs
---
libc/utils/MPFRWrapper/CMakeLists.txt | 20 +++++++-------------
libc/utils/MPFRWrapper/MPFRUtils.cpp | 7 +++----
2 files changed, 10 insertions(+), 17 deletions(-)
diff --git a/libc/utils/MPFRWrapper/CMakeLists.txt b/libc/utils/MPFRWrapper/CMakeLists.txt
index 0f935da183198cc..18acf5b7c75327b 100644
--- a/libc/utils/MPFRWrapper/CMakeLists.txt
+++ b/libc/utils/MPFRWrapper/CMakeLists.txt
@@ -1,21 +1,15 @@
if(LIBC_TESTS_CAN_USE_MPFR)
- if (LLVM_LIBC_FULL_BUILD)
- add_compile_options(
- -ffreestanding
- -fno-exceptions
- -fno-rtti
- -fno-unwind-tables
- -fno-asynchronous-unwind-tables
- )
- endif()
add_library(libcMPFRWrapper
MPFRUtils.cpp
MPFRUtils.h
mpfr_inc.h
)
- add_compile_options(
- -O3
- )
+ target_compile_options(libcMPFRWrapper PRIVATE -O3)
+ if (LLVM_LIBC_FULL_BUILD)
+ # Target using this library will need to link against C++ and unwind libraries.
+ # Since we are using MPFR anyway, we directly specifies the GNU toolchain.
+ target_link_libraries(libcMPFRWrapper PUBLIC -lstdc++ -lgcc_s)
+ endif()
add_dependencies(
libcMPFRWrapper
libc.src.__support.CPP.string_view
@@ -28,7 +22,7 @@ if(LIBC_TESTS_CAN_USE_MPFR)
target_include_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
target_link_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
endif()
- target_link_libraries(libcMPFRWrapper LibcFPTestHelpers.unit LibcTest.unit mpfr gmp)
+ target_link_libraries(libcMPFRWrapper PUBLIC LibcFPTestHelpers.unit LibcTest.unit mpfr gmp)
elseif(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
message(WARNING "Math tests using MPFR will be skipped.")
endif()
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index b6ca525db6cf742..9b14c0d452d91f1 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -14,9 +14,8 @@
#include "src/__support/FPUtil/fpbits_str.h"
#include "test/UnitTest/FPMatcher.h"
-#include <cmath>
#include <fenv.h>
-#include <memory>
+#include <math.h>
#include <stdint.h>
#include "mpfr_inc.h"
@@ -474,8 +473,8 @@ class MPFRNumber {
// If the control reaches here, it means that this number and input are
// of the same sign but different exponent. In such a case, ULP error is
// calculated as sum of two parts.
- thisAsT = std::abs(thisAsT);
- input = std::abs(input);
+ thisAsT = ::abs(thisAsT);
+ input = ::abs(input);
T min = thisAsT > input ? input : thisAsT;
T max = thisAsT > input ? thisAsT : input;
int minExponent = FPBits<T>(min).get_exponent();
>From 4b38010baa23ed71e9fd3711b931eff3e47c5b40 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
Date: Sat, 20 Jan 2024 23:02:13 -0500
Subject: [PATCH 4/5] undo extra changes
---
libc/utils/MPFRWrapper/MPFRUtils.cpp | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index 9b14c0d452d91f1..b6ca525db6cf742 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -14,8 +14,9 @@
#include "src/__support/FPUtil/fpbits_str.h"
#include "test/UnitTest/FPMatcher.h"
+#include <cmath>
#include <fenv.h>
-#include <math.h>
+#include <memory>
#include <stdint.h>
#include "mpfr_inc.h"
@@ -473,8 +474,8 @@ class MPFRNumber {
// If the control reaches here, it means that this number and input are
// of the same sign but different exponent. In such a case, ULP error is
// calculated as sum of two parts.
- thisAsT = ::abs(thisAsT);
- input = ::abs(input);
+ thisAsT = std::abs(thisAsT);
+ input = std::abs(input);
T min = thisAsT > input ? input : thisAsT;
T max = thisAsT > input ? thisAsT : input;
int minExponent = FPBits<T>(min).get_exponent();
>From 1e82942f75b09909a07f1f7111fc3ed10332e612 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
Date: Sun, 21 Jan 2024 15:28:05 -0500
Subject: [PATCH 5/5] add more details about dependencies
---
libc/utils/MPFRWrapper/CMakeLists.txt | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/libc/utils/MPFRWrapper/CMakeLists.txt b/libc/utils/MPFRWrapper/CMakeLists.txt
index 18acf5b7c75327b..adc073c9a91f527 100644
--- a/libc/utils/MPFRWrapper/CMakeLists.txt
+++ b/libc/utils/MPFRWrapper/CMakeLists.txt
@@ -6,8 +6,9 @@ if(LIBC_TESTS_CAN_USE_MPFR)
)
target_compile_options(libcMPFRWrapper PRIVATE -O3)
if (LLVM_LIBC_FULL_BUILD)
- # Target using this library will need to link against C++ and unwind libraries.
- # Since we are using MPFR anyway, we directly specifies the GNU toolchain.
+ # It is not easy to make libcMPFRWrapper a standalone library because gmp.h may unconditionally
+ # pull in some STL headers. As a result, targets using this library will need to link against
+ # C++ and unwind libraries. Since we are using MPFR anyway, we directly specifies the GNU toolchain.
target_link_libraries(libcMPFRWrapper PUBLIC -lstdc++ -lgcc_s)
endif()
add_dependencies(
More information about the libc-commits
mailing list