Skip to content

Commit 05502de

Browse files
authored
[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.
1 parent 1961bea commit 05502de

12 files changed

+27
-46
lines changed

libc/test/src/math/smoke/CMakeLists.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4652,7 +4652,7 @@ add_fp_unittest(
46524652
SRCS
46534653
asinhf_test.cpp
46544654
DEPENDS
4655-
libc.src.errno.errno
4655+
libc.hdr.errno_macros
46564656
libc.src.math.asinhf
46574657
libc.src.__support.FPUtil.fp_bits
46584658
)
@@ -4664,7 +4664,7 @@ add_fp_unittest(
46644664
SRCS
46654665
asinhf16_test.cpp
46664666
DEPENDS
4667-
libc.src.errno.errno
4667+
libc.hdr.errno_macros
46684668
libc.src.math.asinhf16
46694669
)
46704670

@@ -4676,8 +4676,8 @@ add_fp_unittest(
46764676
SRCS
46774677
asinpif16_test.cpp
46784678
DEPENDS
4679+
libc.hdr.errno_macros
46794680
libc.src.math.asinpif16
4680-
libc.src.errno.errno
46814681
)
46824682

46834683
add_fp_unittest(
@@ -4687,7 +4687,7 @@ add_fp_unittest(
46874687
SRCS
46884688
acoshf_test.cpp
46894689
DEPENDS
4690-
libc.src.errno.errno
4690+
libc.hdr.errno_macros
46914691
libc.src.math.acoshf
46924692
libc.src.__support.FPUtil.fp_bits
46934693
)
@@ -4699,7 +4699,7 @@ add_fp_unittest(
46994699
SRCS
47004700
acoshf16_test.cpp
47014701
DEPENDS
4702-
libc.src.errno.errno
4702+
libc.hdr.errno_macros
47034703
libc.src.math.acoshf16
47044704
libc.src.__support.FPUtil.cast
47054705
)
@@ -4711,7 +4711,7 @@ add_fp_unittest(
47114711
SRCS
47124712
asinf_test.cpp
47134713
DEPENDS
4714-
libc.src.errno.errno
4714+
libc.hdr.errno_macros
47154715
libc.src.math.asinf
47164716
libc.src.__support.FPUtil.fp_bits
47174717
)
@@ -4733,8 +4733,8 @@ add_fp_unittest(
47334733
SRCS
47344734
asinf16_test.cpp
47354735
DEPENDS
4736-
libc.src.errno.errno
4737-
libc.src.math.asinf16
4736+
libc.hdr.errno_macros
4737+
libc.src.math.asinf16
47384738
)
47394739

47404740
add_fp_unittest(
@@ -4744,7 +4744,7 @@ add_fp_unittest(
47444744
SRCS
47454745
acosf_test.cpp
47464746
DEPENDS
4747-
libc.src.errno.errno
4747+
libc.hdr.errno_macros
47484748
libc.src.math.acosf
47494749
libc.src.__support.FPUtil.fp_bits
47504750
)
@@ -4756,8 +4756,8 @@ add_fp_unittest(
47564756
SRCS
47574757
acos_test.cpp
47584758
DEPENDS
4759+
libc.hdr.errno_macros
47594760
libc.hdr.fenv_macros
4760-
libc.src.errno.errno
47614761
libc.src.math.acos
47624762
)
47634763

@@ -4768,8 +4768,8 @@ add_fp_unittest(
47684768
SRCS
47694769
acosf16_test.cpp
47704770
DEPENDS
4771-
libc.src.errno.errno
4772-
libc.src.math.acosf16
4771+
libc.hdr.errno_macros
4772+
libc.src.math.acosf16
47734773
)
47744774

47754775
add_fp_unittest(
@@ -4779,8 +4779,8 @@ add_fp_unittest(
47794779
SRCS
47804780
acospif16_test.cpp
47814781
DEPENDS
4782-
libc.src.errno.errno
4783-
libc.src.math.acospif16
4782+
libc.hdr.errno_macros
4783+
libc.src.math.acospif16
47844784
)
47854785

47864786
add_fp_unittest(

libc/test/src/math/smoke/acos_test.cpp

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

9+
#include "hdr/errno_macros.h"
910
#include "hdr/fenv_macros.h"
10-
#include "src/__support/libc_errno.h"
1111
#include "src/math/acos.h"
1212
#include "test/UnitTest/FPMatcher.h"
1313
#include "test/UnitTest/Test.h"
@@ -18,10 +18,10 @@ TEST_F(LlvmLibcAcosTest, SpecialNumbers) {
1818
EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acos(sNaN),
1919
FE_INVALID);
2020
EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acos(aNaN));
21+
EXPECT_MATH_ERRNO(0);
2122
EXPECT_FP_EQ(0x1.921fb54442d18p0, LIBC_NAMESPACE::acos(zero));
2223
EXPECT_FP_EQ(0x1.921fb54442d18p0, LIBC_NAMESPACE::acos(neg_zero));
2324

24-
libc_errno = 0;
2525
EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::acos(inf),
2626
FE_INVALID);
2727
EXPECT_MATH_ERRNO(EDOM);

libc/test/src/math/smoke/acosf16_test.cpp

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

10-
#include "src/__support/libc_errno.h"
10+
#include "hdr/errno_macros.h"
1111
#include "src/math/acosf16.h"
1212
#include "test/UnitTest/FPMatcher.h"
1313
#include "test/UnitTest/Test.h"
1414

1515
using LlvmLibcAcosf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
1616

1717
TEST_F(LlvmLibcAcosf16Test, SpecialNumbers) {
18-
libc_errno = 0;
1918
EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acosf16(aNaN));
2019
EXPECT_MATH_ERRNO(0);
2120

libc/test/src/math/smoke/acosf_test.cpp

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

9+
#include "hdr/errno_macros.h"
910
#include "hdr/math_macros.h"
1011
#include "src/__support/FPUtil/FPBits.h"
11-
#include "src/__support/libc_errno.h"
1212
#include "src/math/acosf.h"
1313
#include "test/UnitTest/FPMatcher.h"
1414
#include "test/UnitTest/Test.h"
@@ -18,8 +18,6 @@
1818
using LlvmLibcAcosfTest = LIBC_NAMESPACE::testing::FPTest<float>;
1919

2020
TEST_F(LlvmLibcAcosfTest, SpecialNumbers) {
21-
libc_errno = 0;
22-
2321
EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::acosf(sNaN), FE_INVALID);
2422
EXPECT_MATH_ERRNO(0);
2523

libc/test/src/math/smoke/acoshf16_test.cpp

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

9+
#include "hdr/errno_macros.h"
910
#include "src/__support/FPUtil/cast.h"
10-
#include "src/__support/libc_errno.h"
1111
#include "src/math/acoshf16.h"
1212
#include "test/UnitTest/FPMatcher.h"
1313
#include "test/UnitTest/Test.h"
1414

1515
using LlvmLibcAcoshf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
1616

1717
TEST_F(LlvmLibcAcoshf16Test, SpecialNumbers) {
18-
libc_errno = 0;
1918
EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acoshf16(aNaN));
2019
EXPECT_MATH_ERRNO(0);
2120

libc/test/src/math/smoke/acoshf_test.cpp

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

9+
#include "hdr/errno_macros.h"
910
#include "hdr/math_macros.h"
1011
#include "src/__support/FPUtil/FPBits.h"
11-
#include "src/__support/libc_errno.h"
1212
#include "src/math/acoshf.h"
1313
#include "test/UnitTest/FPMatcher.h"
1414
#include "test/UnitTest/Test.h"
@@ -18,8 +18,6 @@
1818
using LlvmLibcAcoshfTest = LIBC_NAMESPACE::testing::FPTest<float>;
1919

2020
TEST_F(LlvmLibcAcoshfTest, SpecialNumbers) {
21-
libc_errno = 0;
22-
2321
EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::acoshf(sNaN), FE_INVALID);
2422
EXPECT_MATH_ERRNO(0);
2523

libc/test/src/math/smoke/acospif16_test.cpp

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

9-
#include "src/__support/libc_errno.h"
9+
#include "hdr/errno_macros.h"
1010
#include "src/math/acospif16.h"
1111
#include "test/UnitTest/FPMatcher.h"
1212
#include "test/UnitTest/Test.h"
1313

1414
using LlvmLibcAcospif16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
1515
TEST_F(LlvmLibcAcospif16Test, SpecialNumbers) {
16-
libc_errno = 0;
1716
EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::acospif16(aNaN));
1817
EXPECT_MATH_ERRNO(0);
1918

libc/test/src/math/smoke/asinf16_test.cpp

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

10-
#include "src/__support/libc_errno.h"
10+
#include "hdr/errno_macros.h"
1111
#include "src/math/asinf16.h"
1212
#include "test/UnitTest/FPMatcher.h"
1313
#include "test/UnitTest/Test.h"
1414

1515
using LlvmLibcAsinf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
1616

1717
TEST_F(LlvmLibcAsinf16Test, SpecialNumbers) {
18-
libc_errno = 0;
1918
EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::asinf16(aNaN));
2019
EXPECT_MATH_ERRNO(0);
2120

libc/test/src/math/smoke/asinf_test.cpp

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

9+
#include "hdr/errno_macros.h"
910
#include "hdr/math_macros.h"
1011
#include "src/__support/FPUtil/FPBits.h"
11-
#include "src/__support/libc_errno.h"
1212
#include "src/math/asinf.h"
1313
#include "test/UnitTest/FPMatcher.h"
1414
#include "test/UnitTest/Test.h"
@@ -18,8 +18,6 @@
1818
using LlvmLibcAsinfTest = LIBC_NAMESPACE::testing::FPTest<float>;
1919

2020
TEST_F(LlvmLibcAsinfTest, SpecialNumbers) {
21-
libc_errno = 0;
22-
2321
EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::asinf(sNaN), FE_INVALID);
2422
EXPECT_MATH_ERRNO(0);
2523

libc/test/src/math/smoke/asinhf16_test.cpp

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

9-
#include "src/__support/libc_errno.h"
9+
#include "hdr/errno_macros.h"
1010
#include "src/math/asinhf16.h"
1111
#include "test/UnitTest/FPMatcher.h"
1212
#include "test/UnitTest/Test.h"
1313

1414
using LlvmLibcAsinhf16Test = LIBC_NAMESPACE::testing::FPTest<float16>;
1515

1616
TEST_F(LlvmLibcAsinhf16Test, SpecialNumbers) {
17-
libc_errno = 0;
1817
EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::asinhf16(aNaN));
1918
EXPECT_MATH_ERRNO(0);
2019

0 commit comments

Comments
 (0)