Skip to content

Commit ccc3403

Browse files
authored
[libc] Clean up errno header usage in math tests. (#157898)
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 0d40450 commit ccc3403

33 files changed

+27
-112
lines changed

libc/test/src/math/CMakeLists.txt

Lines changed: 14 additions & 27 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
)
@@ -2020,7 +2015,6 @@ add_fp_unittest(
20202015
SRCS
20212016
logf_test.cpp
20222017
DEPENDS
2023-
libc.src.errno.errno
20242018
libc.src.math.logf
20252019
libc.src.__support.FPUtil.fp_bits
20262020
)
@@ -2044,7 +2038,6 @@ log2_test
20442038
SRCS
20452039
log2_test.cpp
20462040
DEPENDS
2047-
libc.src.errno.errno
20482041
libc.src.math.log2
20492042
libc.src.__support.FPUtil.fp_bits
20502043
)
@@ -2081,7 +2074,6 @@ add_fp_unittest(
20812074
SRCS
20822075
log10_test.cpp
20832076
DEPENDS
2084-
libc.src.errno.errno
20852077
libc.src.math.log10
20862078
libc.src.__support.FPUtil.fp_bits
20872079
)
@@ -2094,7 +2086,6 @@ add_fp_unittest(
20942086
SRCS
20952087
log10f_test.cpp
20962088
DEPENDS
2097-
libc.src.errno.errno
20982089
libc.src.math.log10f
20992090
libc.src.__support.FPUtil.fp_bits
21002091
)
@@ -2118,7 +2109,6 @@ log1p_test
21182109
SRCS
21192110
log1p_test.cpp
21202111
DEPENDS
2121-
libc.src.errno.errno
21222112
libc.src.math.log1p
21232113
libc.src.__support.FPUtil.fp_bits
21242114
)
@@ -2131,7 +2121,6 @@ add_fp_unittest(
21312121
SRCS
21322122
log1pf_test.cpp
21332123
DEPENDS
2134-
libc.src.errno.errno
21352124
libc.src.math.log1pf
21362125
libc.src.__support.FPUtil.fp_bits
21372126
)
@@ -2145,7 +2134,7 @@ add_fp_unittest(
21452134
HDRS
21462135
FModTest.h
21472136
DEPENDS
2148-
libc.src.errno.errno
2137+
libc.hdr.errno_macros
21492138
libc.src.math.fmodf
21502139
libc.src.__support.FPUtil.basic_operations
21512140
libc.src.__support.FPUtil.nearest_integer_operations
@@ -2162,7 +2151,7 @@ add_fp_unittest(
21622151
HDRS
21632152
FModTest.h
21642153
DEPENDS
2165-
libc.src.errno.errno
2154+
libc.hdr.errno_macros
21662155
libc.src.math.fmod
21672156
libc.src.__support.FPUtil.basic_operations
21682157
libc.src.__support.FPUtil.nearest_integer_operations
@@ -2196,7 +2185,7 @@ add_fp_unittest(
21962185
HDRS
21972186
sdcomp26094.h
21982187
DEPENDS
2199-
libc.src.errno.errno
2188+
libc.hdr.errno_macros
22002189
libc.src.math.coshf
22012190
libc.src.__support.CPP.array
22022191
libc.src.__support.FPUtil.fp_bits
@@ -2223,7 +2212,7 @@ add_fp_unittest(
22232212
HDRS
22242213
sdcomp26094.h
22252214
DEPENDS
2226-
libc.src.errno.errno
2215+
libc.hdr.errno_macros
22272216
libc.src.math.sinhf
22282217
libc.src.__support.CPP.array
22292218
libc.src.__support.FPUtil.fp_bits
@@ -2271,7 +2260,7 @@ add_fp_unittest(
22712260
SRCS
22722261
atanhf_test.cpp
22732262
DEPENDS
2274-
libc.src.errno.errno
2263+
libc.hdr.errno_macros
22752264
libc.src.math.atanhf
22762265
libc.src.__support.FPUtil.fp_bits
22772266
)
@@ -2336,7 +2325,6 @@ add_fp_unittest(
23362325
SRCS
23372326
asinhf_test.cpp
23382327
DEPENDS
2339-
libc.src.errno.errno
23402328
libc.src.math.asinhf
23412329
libc.src.__support.FPUtil.fp_bits
23422330
)
@@ -2360,7 +2348,7 @@ add_fp_unittest(
23602348
SRCS
23612349
acoshf_test.cpp
23622350
DEPENDS
2363-
libc.src.errno.errno
2351+
libc.hdr.errno_macros
23642352
libc.src.math.acoshf
23652353
libc.src.__support.FPUtil.fp_bits
23662354
)
@@ -2384,7 +2372,7 @@ add_fp_unittest(
23842372
SRCS
23852373
asinf_test.cpp
23862374
DEPENDS
2387-
libc.src.errno.errno
2375+
libc.hdr.errno_macros
23882376
libc.src.math.asinf
23892377
libc.src.__support.FPUtil.fp_bits
23902378
)
@@ -2430,7 +2418,7 @@ add_fp_unittest(
24302418
SRCS
24312419
acosf_test.cpp
24322420
DEPENDS
2433-
libc.src.errno.errno
2421+
libc.hdr.errno_macros
24342422
libc.src.math.acosf
24352423
libc.src.__support.FPUtil.fp_bits
24362424
)
@@ -2476,7 +2464,6 @@ add_fp_unittest(
24762464
SRCS
24772465
atanf_test.cpp
24782466
DEPENDS
2479-
libc.src.errno.errno
24802467
libc.src.math.atanf
24812468
libc.src.__support.FPUtil.fp_bits
24822469
)

libc/test/src/math/FModTest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_LIBC_TEST_SRC_MATH_FMODTEST_H
1010
#define LLVM_LIBC_TEST_SRC_MATH_FMODTEST_H
1111

12+
#include "hdr/errno_macros.h"
1213
#include "src/__support/FPUtil/BasicOperations.h"
1314
#include "src/__support/FPUtil/NearestIntegerOperations.h"
1415
#include "test/UnitTest/FEnvSafeTest.h"

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: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "hdr/math_macros.h"
1010
#include "hdr/stdint_proxy.h"
1111
#include "src/__support/FPUtil/FPBits.h"
12-
#include "src/__support/libc_errno.h"
1312
#include "src/math/asinhf.h"
1413
#include "test/UnitTest/FPMatcher.h"
1514
#include "test/UnitTest/Test.h"
@@ -20,8 +19,6 @@ using LlvmLibcAsinhfTest = LIBC_NAMESPACE::testing::FPTest<float>;
2019
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
2120

2221
TEST_F(LlvmLibcAsinhfTest, SpecialNumbers) {
23-
libc_errno = 0;
24-
2522
EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::asinhf(aNaN));
2623
EXPECT_MATH_ERRNO(0);
2724

libc/test/src/math/atanf_test.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "hdr/math_macros.h"
1010
#include "hdr/stdint_proxy.h"
1111
#include "src/__support/FPUtil/FPBits.h"
12-
#include "src/__support/libc_errno.h"
1312
#include "src/math/atanf.h"
1413
#include "test/UnitTest/FPMatcher.h"
1514
#include "test/UnitTest/Test.h"
@@ -22,7 +21,6 @@ namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
2221
// TODO: This test needs to have its checks for exceptions, errno
2322
// tightened
2423
TEST_F(LlvmLibcAtanfTest, SpecialNumbers) {
25-
libc_errno = 0;
2624
LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
2725
EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::atanf(aNaN));
2826
// 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

0 commit comments

Comments
 (0)