[libc-commits] [libc] 05502de - [libc] Clean up errno header usage in a few math/smoke tests. (#157517)
via libc-commits
libc-commits at lists.llvm.org
Mon Sep 8 11:09:38 PDT 2025
Author: Alexey Samsonov
Date: 2025-09-08T11:09:34-07:00
New Revision: 05502de64ccf1793a49e2f7c80ca1afe5d1e0f43
URL: https://github.com/llvm/llvm-project/commit/05502de64ccf1793a49e2f7c80ca1afe5d1e0f43
DIFF: https://github.com/llvm/llvm-project/commit/05502de64ccf1793a49e2f7c80ca1afe5d1e0f43.diff
LOG: [libc] Clean up errno header usage in a few math/smoke tests. (#157517)
Most of the unit tests don't (or don't need to) read/write libc_errno
code directly - it's cleared by the ErrnoCheckingTest harness, and is
verified by framework-provided scripts such as EXPECT_MATH_ERRNO.
Use the following rule of thumb for header inclusion:
* if you use libc_errno in code literally, include
src/__support/libc_errno.h
* if you only rely on errno constants, include hdr/errno_macros.h
This PR only updates a few tests for acos/asin variants, as a
proof-of-concept. If it goes in, a follow-up PR would update the rest.
Added:
Modified:
libc/test/src/math/smoke/CMakeLists.txt
libc/test/src/math/smoke/acos_test.cpp
libc/test/src/math/smoke/acosf16_test.cpp
libc/test/src/math/smoke/acosf_test.cpp
libc/test/src/math/smoke/acoshf16_test.cpp
libc/test/src/math/smoke/acoshf_test.cpp
libc/test/src/math/smoke/acospif16_test.cpp
libc/test/src/math/smoke/asinf16_test.cpp
libc/test/src/math/smoke/asinf_test.cpp
libc/test/src/math/smoke/asinhf16_test.cpp
libc/test/src/math/smoke/asinhf_test.cpp
libc/test/src/math/smoke/asinpif16_test.cpp
Removed:
################################################################################
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index c9cbd8b413967..9c99b8a2401b0 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4652,7 +4652,7 @@ add_fp_unittest(
SRCS
asinhf_test.cpp
DEPENDS
- libc.src.errno.errno
+ libc.hdr.errno_macros
libc.src.math.asinhf
libc.src.__support.FPUtil.fp_bits
)
@@ -4664,7 +4664,7 @@ add_fp_unittest(
SRCS
asinhf16_test.cpp
DEPENDS
- libc.src.errno.errno
+ libc.hdr.errno_macros
libc.src.math.asinhf16
)
@@ -4676,8 +4676,8 @@ add_fp_unittest(
SRCS
asinpif16_test.cpp
DEPENDS
+ libc.hdr.errno_macros
libc.src.math.asinpif16
- libc.src.errno.errno
)
add_fp_unittest(
@@ -4687,7 +4687,7 @@ add_fp_unittest(
SRCS
acoshf_test.cpp
DEPENDS
- libc.src.errno.errno
+ libc.hdr.errno_macros
libc.src.math.acoshf
libc.src.__support.FPUtil.fp_bits
)
@@ -4699,7 +4699,7 @@ add_fp_unittest(
SRCS
acoshf16_test.cpp
DEPENDS
- libc.src.errno.errno
+ libc.hdr.errno_macros
libc.src.math.acoshf16
libc.src.__support.FPUtil.cast
)
@@ -4711,7 +4711,7 @@ add_fp_unittest(
SRCS
asinf_test.cpp
DEPENDS
- libc.src.errno.errno
+ libc.hdr.errno_macros
libc.src.math.asinf
libc.src.__support.FPUtil.fp_bits
)
@@ -4733,8 +4733,8 @@ add_fp_unittest(
SRCS
asinf16_test.cpp
DEPENDS
- libc.src.errno.errno
- libc.src.math.asinf16
+ libc.hdr.errno_macros
+ libc.src.math.asinf16
)
add_fp_unittest(
@@ -4744,7 +4744,7 @@ add_fp_unittest(
SRCS
acosf_test.cpp
DEPENDS
- libc.src.errno.errno
+ libc.hdr.errno_macros
libc.src.math.acosf
libc.src.__support.FPUtil.fp_bits
)
@@ -4756,8 +4756,8 @@ add_fp_unittest(
SRCS
acos_test.cpp
DEPENDS
+ libc.hdr.errno_macros
libc.hdr.fenv_macros
- libc.src.errno.errno
libc.src.math.acos
)
@@ -4768,8 +4768,8 @@ add_fp_unittest(
SRCS
acosf16_test.cpp
DEPENDS
- libc.src.errno.errno
- libc.src.math.acosf16
+ libc.hdr.errno_macros
+ libc.src.math.acosf16
)
add_fp_unittest(
@@ -4779,8 +4779,8 @@ add_fp_unittest(
SRCS
acospif16_test.cpp
DEPENDS
- libc.src.errno.errno
- libc.src.math.acospif16
+ libc.hdr.errno_macros
+ libc.src.math.acospif16
)
add_fp_unittest(
diff --git a/libc/test/src/math/smoke/acos_test.cpp b/libc/test/src/math/smoke/acos_test.cpp
index fe2caefb52ab8..2b2fa75b0d7ca 100644
--- a/libc/test/src/math/smoke/acos_test.cpp
+++ b/libc/test/src/math/smoke/acos_test.cpp
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/errno_macros.h"
#include "hdr/fenv_macros.h"
-#include "src/__support/libc_errno.h"
#include "src/math/acos.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
@@ -18,10 +18,10 @@ TEST_F(LlvmLibcAcosTest, SpecialNumbers) {
EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acos(sNaN),
FE_INVALID);
EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acos(aNaN));
+ EXPECT_MATH_ERRNO(0);
EXPECT_FP_EQ(0x1.921fb54442d18p0, LIBC_NAMESPACE::acos(zero));
EXPECT_FP_EQ(0x1.921fb54442d18p0, LIBC_NAMESPACE::acos(neg_zero));
- libc_errno = 0;
EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acos(inf),
FE_INVALID);
EXPECT_MATH_ERRNO(EDOM);
diff --git a/libc/test/src/math/smoke/acosf16_test.cpp b/libc/test/src/math/smoke/acosf16_test.cpp
index 7103dc33fec3a..6cc170d3fd357 100644
--- a/libc/test/src/math/smoke/acosf16_test.cpp
+++ b/libc/test/src/math/smoke/acosf16_test.cpp
@@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/libc_errno.h"
+#include "hdr/errno_macros.h"
#include "src/math/acosf16.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
@@ -15,7 +15,6 @@
using LlvmLibcAcosf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
TEST_F(LlvmLibcAcosf16Test, SpecialNumbers) {
- libc_errno = 0;
EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acosf16(aNaN));
EXPECT_MATH_ERRNO(0);
diff --git a/libc/test/src/math/smoke/acosf_test.cpp b/libc/test/src/math/smoke/acosf_test.cpp
index 733610a03937b..e9a90a1d4a7c3 100644
--- a/libc/test/src/math/smoke/acosf_test.cpp
+++ b/libc/test/src/math/smoke/acosf_test.cpp
@@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/errno_macros.h"
#include "hdr/math_macros.h"
#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/libc_errno.h"
#include "src/math/acosf.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
@@ -18,8 +18,6 @@
using LlvmLibcAcosfTest = LIBC_NAMESPACE::testing::FPTest<float>;
TEST_F(LlvmLibcAcosfTest, SpecialNumbers) {
- libc_errno = 0;
-
EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::acosf(sNaN), FE_INVALID);
EXPECT_MATH_ERRNO(0);
diff --git a/libc/test/src/math/smoke/acoshf16_test.cpp b/libc/test/src/math/smoke/acoshf16_test.cpp
index 6b9c995cf9921..b020de40b51ed 100644
--- a/libc/test/src/math/smoke/acoshf16_test.cpp
+++ b/libc/test/src/math/smoke/acoshf16_test.cpp
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/errno_macros.h"
#include "src/__support/FPUtil/cast.h"
-#include "src/__support/libc_errno.h"
#include "src/math/acoshf16.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
@@ -15,7 +15,6 @@
using LlvmLibcAcoshf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
TEST_F(LlvmLibcAcoshf16Test, SpecialNumbers) {
- libc_errno = 0;
EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acoshf16(aNaN));
EXPECT_MATH_ERRNO(0);
diff --git a/libc/test/src/math/smoke/acoshf_test.cpp b/libc/test/src/math/smoke/acoshf_test.cpp
index 19556b27e5422..6918980da20e8 100644
--- a/libc/test/src/math/smoke/acoshf_test.cpp
+++ b/libc/test/src/math/smoke/acoshf_test.cpp
@@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/errno_macros.h"
#include "hdr/math_macros.h"
#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/libc_errno.h"
#include "src/math/acoshf.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
@@ -18,8 +18,6 @@
using LlvmLibcAcoshfTest = LIBC_NAMESPACE::testing::FPTest<float>;
TEST_F(LlvmLibcAcoshfTest, SpecialNumbers) {
- libc_errno = 0;
-
EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::acoshf(sNaN), FE_INVALID);
EXPECT_MATH_ERRNO(0);
diff --git a/libc/test/src/math/smoke/acospif16_test.cpp b/libc/test/src/math/smoke/acospif16_test.cpp
index 4b2f6de3f7e37..0669d21a8d99c 100644
--- a/libc/test/src/math/smoke/acospif16_test.cpp
+++ b/libc/test/src/math/smoke/acospif16_test.cpp
@@ -6,14 +6,13 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/libc_errno.h"
+#include "hdr/errno_macros.h"
#include "src/math/acospif16.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
using LlvmLibcAcospif16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
TEST_F(LlvmLibcAcospif16Test, SpecialNumbers) {
- libc_errno = 0;
EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(aNaN));
EXPECT_MATH_ERRNO(0);
diff --git a/libc/test/src/math/smoke/asinf16_test.cpp b/libc/test/src/math/smoke/asinf16_test.cpp
index b03f0a420a499..fa118bb497a6e 100644
--- a/libc/test/src/math/smoke/asinf16_test.cpp
+++ b/libc/test/src/math/smoke/asinf16_test.cpp
@@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/libc_errno.h"
+#include "hdr/errno_macros.h"
#include "src/math/asinf16.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
@@ -15,7 +15,6 @@
using LlvmLibcAsinf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
TEST_F(LlvmLibcAsinf16Test, SpecialNumbers) {
- libc_errno = 0;
EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::asinf16(aNaN));
EXPECT_MATH_ERRNO(0);
diff --git a/libc/test/src/math/smoke/asinf_test.cpp b/libc/test/src/math/smoke/asinf_test.cpp
index 6195a11266942..2135ed33edfad 100644
--- a/libc/test/src/math/smoke/asinf_test.cpp
+++ b/libc/test/src/math/smoke/asinf_test.cpp
@@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/errno_macros.h"
#include "hdr/math_macros.h"
#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/libc_errno.h"
#include "src/math/asinf.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
@@ -18,8 +18,6 @@
using LlvmLibcAsinfTest = LIBC_NAMESPACE::testing::FPTest<float>;
TEST_F(LlvmLibcAsinfTest, SpecialNumbers) {
- libc_errno = 0;
-
EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::asinf(sNaN), FE_INVALID);
EXPECT_MATH_ERRNO(0);
diff --git a/libc/test/src/math/smoke/asinhf16_test.cpp b/libc/test/src/math/smoke/asinhf16_test.cpp
index 7f612ce3c4674..f17300cf980e2 100644
--- a/libc/test/src/math/smoke/asinhf16_test.cpp
+++ b/libc/test/src/math/smoke/asinhf16_test.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/libc_errno.h"
+#include "hdr/errno_macros.h"
#include "src/math/asinhf16.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
@@ -14,7 +14,6 @@
using LlvmLibcAsinhf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
TEST_F(LlvmLibcAsinhf16Test, SpecialNumbers) {
- libc_errno = 0;
EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::asinhf16(aNaN));
EXPECT_MATH_ERRNO(0);
diff --git a/libc/test/src/math/smoke/asinhf_test.cpp b/libc/test/src/math/smoke/asinhf_test.cpp
index e6326c116023e..d053a50079786 100644
--- a/libc/test/src/math/smoke/asinhf_test.cpp
+++ b/libc/test/src/math/smoke/asinhf_test.cpp
@@ -6,9 +6,9 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/errno_macros.h"
#include "hdr/math_macros.h"
#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/libc_errno.h"
#include "src/math/asinhf.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
@@ -18,8 +18,6 @@
using LlvmLibcAsinhfTest = LIBC_NAMESPACE::testing::FPTest<float>;
TEST_F(LlvmLibcAsinhfTest, SpecialNumbers) {
- libc_errno = 0;
-
EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::asinhf(sNaN), FE_INVALID);
EXPECT_MATH_ERRNO(0);
diff --git a/libc/test/src/math/smoke/asinpif16_test.cpp b/libc/test/src/math/smoke/asinpif16_test.cpp
index 5303eed8f5dae..328da7fb0606f 100644
--- a/libc/test/src/math/smoke/asinpif16_test.cpp
+++ b/libc/test/src/math/smoke/asinpif16_test.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/libc_errno.h"
+#include "hdr/errno_macros.h"
#include "src/math/asinpif16.h"
#include "test/UnitTest/FPMatcher.h"
@@ -26,13 +26,12 @@ TEST_F(LlvmLibcAsinpif16Test, SpecialNumbers) {
EXPECT_FP_EQ(FPBits::quiet_nan().get_val(),
LIBC_NAMESPACE::asinpif16(FPBits::signaling_nan().get_val()));
+ EXPECT_MATH_ERRNO(0);
// infinity inputs -> should return NaN
- libc_errno = 0;
EXPECT_FP_EQ(FPBits::quiet_nan().get_val(), LIBC_NAMESPACE::asinpif16(inf));
EXPECT_MATH_ERRNO(EDOM);
- libc_errno = 0;
EXPECT_FP_EQ(FPBits::quiet_nan().get_val(),
LIBC_NAMESPACE::asinpif16(neg_inf));
EXPECT_MATH_ERRNO(EDOM);
@@ -40,29 +39,24 @@ TEST_F(LlvmLibcAsinpif16Test, SpecialNumbers) {
TEST_F(LlvmLibcAsinpif16Test, OutOfRange) {
// Test values > 1
- libc_errno = 0;
EXPECT_FP_EQ(FPBits::quiet_nan().get_val(),
LIBC_NAMESPACE::asinpif16(1.5f16));
EXPECT_MATH_ERRNO(EDOM);
- libc_errno = 0;
EXPECT_FP_EQ(FPBits::quiet_nan().get_val(),
LIBC_NAMESPACE::asinpif16(2.0f16));
EXPECT_MATH_ERRNO(EDOM);
// Test values < -1
- libc_errno = 0;
EXPECT_FP_EQ(FPBits::quiet_nan().get_val(),
LIBC_NAMESPACE::asinpif16(-1.5f16));
EXPECT_MATH_ERRNO(EDOM);
- libc_errno = 0;
EXPECT_FP_EQ(FPBits::quiet_nan().get_val(),
LIBC_NAMESPACE::asinpif16(-2.0f16));
EXPECT_MATH_ERRNO(EDOM);
// Test maximum normal value (should be > 1 for float16)
- libc_errno = 0;
EXPECT_FP_EQ(FPBits::quiet_nan().get_val(),
LIBC_NAMESPACE::asinpif16(FPBits::max_normal().get_val()));
EXPECT_MATH_ERRNO(EDOM);
More information about the libc-commits
mailing list