Skip to content

Commit 3f0e2f3

Browse files
committed
[libc] Clean up errno header usage in math tests.
This is one more follow-up to PR #157517 that cleans up the usage of libc_errno in math unit-tests (non-smoke). It follows the same rule: * 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 Several tests for exp/log still retain the direct libc_errno usage, since in some cases they skip doing any validation if the error was raised. But the direct usage of libc_errno is removed from all other cases.
1 parent 6e5d008 commit 3f0e2f3

32 files changed

+28
-108
lines changed

libc/test/src/math/CMakeLists.txt

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ add_fp_unittest(
1010
HDRS
1111
sdcomp26094.h
1212
DEPENDS
13-
libc.src.errno.errno
13+
libc.hdr.errno_macros
1414
libc.src.math.cosf
1515
libc.src.__support.CPP.array
1616
libc.src.__support.FPUtil.fp_bits
@@ -49,7 +49,7 @@ add_fp_unittest(
4949
HDRS
5050
sdcomp26094.h
5151
DEPENDS
52-
libc.src.errno.errno
52+
libc.hdr.errno_macros
5353
libc.src.math.cospif
5454
libc.src.__support.CPP.array
5555
libc.src.__support.FPUtil.fp_bits
@@ -90,7 +90,7 @@ add_fp_unittest(
9090
HDRS
9191
sdcomp26094.h
9292
DEPENDS
93-
libc.src.errno.errno
93+
libc.hdr.errno_macros
9494
libc.src.math.sinf
9595
libc.src.__support.CPP.array
9696
libc.src.__support.FPUtil.fp_bits
@@ -117,7 +117,7 @@ add_fp_unittest(
117117
HDRS
118118
sdcomp26094.h
119119
DEPENDS
120-
libc.src.errno.errno
120+
libc.hdr.errno_macros
121121
libc.src.math.sinpif
122122
libc.src.__support.CPP.array
123123
libc.src.__support.FPUtil.fp_bits
@@ -156,7 +156,7 @@ add_fp_unittest(
156156
HDRS
157157
sdcomp26094.h
158158
DEPENDS
159-
libc.src.errno.errno
159+
libc.hdr.errno_macros
160160
libc.src.math.sincosf
161161
libc.src.__support.CPP.array
162162
libc.src.__support.FPUtil.fp_bits
@@ -184,7 +184,7 @@ add_fp_unittest(
184184
HDRS
185185
sdcomp26094.h
186186
DEPENDS
187-
libc.src.errno.errno
187+
libc.hdr.errno_macros
188188
libc.src.math.tanf
189189
libc.src.__support.CPP.array
190190
libc.src.__support.FPUtil.fp_bits
@@ -1110,7 +1110,6 @@ add_fp_unittest(
11101110
SRCS
11111111
exp_test.cpp
11121112
DEPENDS
1113-
libc.src.errno.errno
11141113
libc.src.math.exp
11151114
libc.src.__support.FPUtil.fp_bits
11161115
)
@@ -1147,7 +1146,6 @@ add_fp_unittest(
11471146
SRCS
11481147
exp2_test.cpp
11491148
DEPENDS
1150-
libc.src.errno.errno
11511149
libc.src.math.exp2
11521150
libc.src.__support.FPUtil.fp_bits
11531151
)
@@ -1209,7 +1207,6 @@ add_fp_unittest(
12091207
SRCS
12101208
exp10_test.cpp
12111209
DEPENDS
1212-
libc.src.errno.errno
12131210
libc.src.math.exp10
12141211
libc.src.__support.FPUtil.fp_bits
12151212
)
@@ -1970,7 +1967,6 @@ add_fp_unittest(
19701967
SRCS
19711968
expm1_test.cpp
19721969
DEPENDS
1973-
libc.src.errno.errno
19741970
libc.src.math.expm1
19751971
libc.src.__support.FPUtil.fp_bits
19761972
)
@@ -2007,7 +2003,6 @@ add_fp_unittest(
20072003
SRCS
20082004
log_test.cpp
20092005
DEPENDS
2010-
libc.src.errno.errno
20112006
libc.src.math.log
20122007
libc.src.__support.FPUtil.fp_bits
20132008
)
@@ -2044,7 +2039,6 @@ log2_test
20442039
SRCS
20452040
log2_test.cpp
20462041
DEPENDS
2047-
libc.src.errno.errno
20482042
libc.src.math.log2
20492043
libc.src.__support.FPUtil.fp_bits
20502044
)
@@ -2081,7 +2075,6 @@ add_fp_unittest(
20812075
SRCS
20822076
log10_test.cpp
20832077
DEPENDS
2084-
libc.src.errno.errno
20852078
libc.src.math.log10
20862079
libc.src.__support.FPUtil.fp_bits
20872080
)
@@ -2118,7 +2111,6 @@ log1p_test
21182111
SRCS
21192112
log1p_test.cpp
21202113
DEPENDS
2121-
libc.src.errno.errno
21222114
libc.src.math.log1p
21232115
libc.src.__support.FPUtil.fp_bits
21242116
)
@@ -2131,7 +2123,6 @@ add_fp_unittest(
21312123
SRCS
21322124
log1pf_test.cpp
21332125
DEPENDS
2134-
libc.src.errno.errno
21352126
libc.src.math.log1pf
21362127
libc.src.__support.FPUtil.fp_bits
21372128
)
@@ -2196,7 +2187,7 @@ add_fp_unittest(
21962187
HDRS
21972188
sdcomp26094.h
21982189
DEPENDS
2199-
libc.src.errno.errno
2190+
libc.hdr.errno_macros
22002191
libc.src.math.coshf
22012192
libc.src.__support.CPP.array
22022193
libc.src.__support.FPUtil.fp_bits
@@ -2223,7 +2214,7 @@ add_fp_unittest(
22232214
HDRS
22242215
sdcomp26094.h
22252216
DEPENDS
2226-
libc.src.errno.errno
2217+
libc.hdr.errno_macros
22272218
libc.src.math.sinhf
22282219
libc.src.__support.CPP.array
22292220
libc.src.__support.FPUtil.fp_bits
@@ -2271,7 +2262,7 @@ add_fp_unittest(
22712262
SRCS
22722263
atanhf_test.cpp
22732264
DEPENDS
2274-
libc.src.errno.errno
2265+
libc.hdr.errno_macros
22752266
libc.src.math.atanhf
22762267
libc.src.__support.FPUtil.fp_bits
22772268
)
@@ -2336,7 +2327,7 @@ add_fp_unittest(
23362327
SRCS
23372328
asinhf_test.cpp
23382329
DEPENDS
2339-
libc.src.errno.errno
2330+
libc.hdr.errno_macros
23402331
libc.src.math.asinhf
23412332
libc.src.__support.FPUtil.fp_bits
23422333
)
@@ -2360,7 +2351,7 @@ add_fp_unittest(
23602351
SRCS
23612352
acoshf_test.cpp
23622353
DEPENDS
2363-
libc.src.errno.errno
2354+
libc.hdr.errno_macros
23642355
libc.src.math.acoshf
23652356
libc.src.__support.FPUtil.fp_bits
23662357
)
@@ -2384,7 +2375,7 @@ add_fp_unittest(
23842375
SRCS
23852376
asinf_test.cpp
23862377
DEPENDS
2387-
libc.src.errno.errno
2378+
libc.hdr.errno_macros
23882379
libc.src.math.asinf
23892380
libc.src.__support.FPUtil.fp_bits
23902381
)
@@ -2430,7 +2421,7 @@ add_fp_unittest(
24302421
SRCS
24312422
acosf_test.cpp
24322423
DEPENDS
2433-
libc.src.errno.errno
2424+
libc.hdr.errno_macros
24342425
libc.src.math.acosf
24352426
libc.src.__support.FPUtil.fp_bits
24362427
)
@@ -2476,7 +2467,7 @@ add_fp_unittest(
24762467
SRCS
24772468
atanf_test.cpp
24782469
DEPENDS
2479-
libc.src.errno.errno
2470+
libc.hdr.errno_macros
24802471
libc.src.math.atanf
24812472
libc.src.__support.FPUtil.fp_bits
24822473
)

libc/test/src/math/acosf_test.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "hdr/errno_macros.h"
910
#include "hdr/math_macros.h"
1011
#include "hdr/stdint_proxy.h"
1112
#include "src/__support/FPUtil/FPBits.h"
12-
#include "src/__support/libc_errno.h"
1313
#include "src/math/acosf.h"
1414
#include "test/UnitTest/FPMatcher.h"
1515
#include "test/UnitTest/Test.h"
@@ -20,8 +20,6 @@ namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
2020
using LlvmLibcAcosfTest = LIBC_NAMESPACE::testing::FPTest<float>;
2121

2222
TEST_F(LlvmLibcAcosfTest, SpecialNumbers) {
23-
libc_errno = 0;
24-
2523
EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acosf(aNaN));
2624
EXPECT_MATH_ERRNO(0);
2725

libc/test/src/math/acoshf16_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "hdr/stdint_proxy.h"
10-
#include "src/__support/libc_errno.h"
1110
#include "src/math/acoshf16.h"
1211
#include "test/UnitTest/FPMatcher.h"
1312
#include "test/UnitTest/Test.h"

libc/test/src/math/acoshf_test.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "hdr/errno_macros.h"
910
#include "hdr/math_macros.h"
1011
#include "hdr/stdint_proxy.h"
1112
#include "src/__support/FPUtil/FPBits.h"
12-
#include "src/__support/libc_errno.h"
1313
#include "src/math/acoshf.h"
1414
#include "test/UnitTest/FPMatcher.h"
1515
#include "test/UnitTest/Test.h"
@@ -20,8 +20,6 @@ using LlvmLibcAcoshfTest = LIBC_NAMESPACE::testing::FPTest<float>;
2020
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
2121

2222
TEST_F(LlvmLibcAcoshfTest, SpecialNumbers) {
23-
libc_errno = 0;
24-
2523
EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acoshf(aNaN));
2624
EXPECT_MATH_ERRNO(0);
2725

libc/test/src/math/asinf_test.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10+
#include "hdr/errno_macros.h"
1011
#include "hdr/math_macros.h"
1112
#include "hdr/stdint_proxy.h"
1213
#include "src/__support/FPUtil/FPBits.h"
13-
#include "src/__support/libc_errno.h"
1414
#include "src/math/asinf.h"
1515
#include "test/UnitTest/FPMatcher.h"
1616
#include "test/UnitTest/Test.h"
@@ -21,8 +21,6 @@ using LlvmLibcAsinfTest = LIBC_NAMESPACE::testing::FPTest<float>;
2121
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
2222

2323
TEST_F(LlvmLibcAsinfTest, SpecialNumbers) {
24-
libc_errno = 0;
25-
2624
EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::asinf(aNaN));
2725
EXPECT_MATH_ERRNO(0);
2826

libc/test/src/math/asinhf_test.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "hdr/errno_macros.h"
910
#include "hdr/math_macros.h"
1011
#include "hdr/stdint_proxy.h"
1112
#include "src/__support/FPUtil/FPBits.h"
12-
#include "src/__support/libc_errno.h"
1313
#include "src/math/asinhf.h"
1414
#include "test/UnitTest/FPMatcher.h"
1515
#include "test/UnitTest/Test.h"
@@ -20,8 +20,6 @@ using LlvmLibcAsinhfTest = LIBC_NAMESPACE::testing::FPTest<float>;
2020
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
2121

2222
TEST_F(LlvmLibcAsinhfTest, SpecialNumbers) {
23-
libc_errno = 0;
24-
2523
EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::asinhf(aNaN));
2624
EXPECT_MATH_ERRNO(0);
2725

libc/test/src/math/atanf_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "hdr/errno_macros.h"
910
#include "hdr/math_macros.h"
1011
#include "hdr/stdint_proxy.h"
1112
#include "src/__support/FPUtil/FPBits.h"
12-
#include "src/__support/libc_errno.h"
1313
#include "src/math/atanf.h"
1414
#include "test/UnitTest/FPMatcher.h"
1515
#include "test/UnitTest/Test.h"
@@ -22,7 +22,6 @@ namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
2222
// TODO: This test needs to have its checks for exceptions, errno
2323
// tightened
2424
TEST_F(LlvmLibcAtanfTest, SpecialNumbers) {
25-
libc_errno = 0;
2625
LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
2726
EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::atanf(aNaN));
2827
// TODO: Uncomment these checks later, RoundingMode affects running

libc/test/src/math/atanhf_test.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "hdr/errno_macros.h"
910
#include "hdr/math_macros.h"
1011
#include "hdr/stdint_proxy.h"
1112
#include "src/__support/FPUtil/FPBits.h"
12-
#include "src/__support/libc_errno.h"
1313
#include "src/math/atanhf.h"
1414
#include "test/UnitTest/FPMatcher.h"
1515
#include "test/UnitTest/Test.h"
@@ -23,8 +23,6 @@ namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
2323
// TODO: This test needs to have its checks for exceptions, errno
2424
// tightened https://github.com/llvm/llvm-project/issues/88819.
2525
TEST_F(LlvmLibcAtanhfTest, SpecialNumbers) {
26-
27-
libc_errno = 0;
2826
LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
2927
EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::atanhf(aNaN));
3028
// TODO: Uncomment these checks later, RoundingMode affects running

libc/test/src/math/cosf_test.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "hdr/errno_macros.h"
910
#include "hdr/math_macros.h"
1011
#include "hdr/stdint_proxy.h"
1112
#include "src/__support/FPUtil/FPBits.h"
12-
#include "src/__support/libc_errno.h"
1313
#include "src/math/cosf.h"
1414
#include "test/UnitTest/FPMatcher.h"
1515
#include "test/UnitTest/Test.h"
@@ -22,8 +22,6 @@ using LlvmLibcCosfTest = LIBC_NAMESPACE::testing::FPTest<float>;
2222
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
2323

2424
TEST_F(LlvmLibcCosfTest, SpecialNumbers) {
25-
libc_errno = 0;
26-
2725
EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::cosf(aNaN));
2826
EXPECT_MATH_ERRNO(0);
2927

libc/test/src/math/coshf_test.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "hdr/errno_macros.h"
910
#include "hdr/math_macros.h"
1011
#include "hdr/stdint_proxy.h"
1112
#include "src/__support/CPP/array.h"
1213
#include "src/__support/FPUtil/FPBits.h"
13-
#include "src/__support/libc_errno.h"
1414
#include "src/math/coshf.h"
1515
#include "test/UnitTest/FPMatcher.h"
1616
#include "test/UnitTest/Test.h"
@@ -21,8 +21,6 @@ using LlvmLibcCoshfTest = LIBC_NAMESPACE::testing::FPTest<float>;
2121
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
2222

2323
TEST_F(LlvmLibcCoshfTest, SpecialNumbers) {
24-
libc_errno = 0;
25-
2624
EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::coshf(aNaN));
2725
EXPECT_MATH_ERRNO(0);
2826

@@ -40,7 +38,6 @@ TEST_F(LlvmLibcCoshfTest, SpecialNumbers) {
4038
}
4139

4240
TEST_F(LlvmLibcCoshfTest, Overflow) {
43-
libc_errno = 0;
4441
EXPECT_FP_EQ_WITH_EXCEPTION(
4542
inf, LIBC_NAMESPACE::coshf(FPBits(0x7f7fffffU).get_val()), FE_OVERFLOW);
4643
EXPECT_MATH_ERRNO(ERANGE);

0 commit comments

Comments
 (0)