Skip to content

Commit 5d56b34

Browse files
[libc] Remove direct math.h includes (#85324)
Reland of #84991 A downstream overlay mode user ran into issues with the isnan macro not working in our sources with a specific libc configuration. This patch replaces the last direct includes of math.h with our internal math_macros.h, along with the necessary build system changes.
1 parent d0d9839 commit 5d56b34

File tree

129 files changed

+166
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+166
-149
lines changed

libc/fuzzing/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer")
22
add_custom_target(libc-fuzzer)
33

4-
add_subdirectory(math)
4+
# TODO(#85680): Re-enable math fuzzing after headers are sorted out
5+
# add_subdirectory(math)
56
add_subdirectory(stdlib)
67
add_subdirectory(stdio)
78
add_subdirectory(string)

libc/fuzzing/math/RemQuoDiff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "src/__support/FPUtil/FPBits.h"
1313

14-
#include <math.h>
14+
#include "include/llvm-libc-macros/math-macros.h"
1515
#include <stddef.h>
1616
#include <stdint.h>
1717

libc/fuzzing/math/SingleInputSingleOutputDiff.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
#define LLVM_LIBC_FUZZING_MATH_SINGLE_INPUT_SINGLE_OUTPUT_DIFF_H
1111

1212
#include "fuzzing/math/Compare.h"
13-
#include "src/__support/FPUtil/FPBits.h"
1413

15-
#include <math.h>
1614
#include <stddef.h>
1715
#include <stdint.h>
1816

libc/fuzzing/math/TwoInputSingleOutputDiff.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
#define LLVM_LIBC_FUZZING_MATH_TWO_INPUT_SINGLE_OUTPUT_DIFF_H
1111

1212
#include "fuzzing/math/Compare.h"
13-
#include "src/__support/FPUtil/FPBits.h"
1413

15-
#include <math.h>
1614
#include <stddef.h>
1715
#include <stdint.h>
1816

libc/fuzzing/stdlib/strtofloat_fuzz.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "src/__support/FPUtil/FPBits.h"
1818

19-
#include <math.h>
19+
#include "include/llvm-libc-macros/math-macros.h"
2020
#include <stddef.h>
2121
#include <stdint.h>
2222

libc/src/__support/FPUtil/FEnvImpl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H
1010
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FENVIMPL_H
1111

12+
#include "include/llvm-libc-macros/math-macros.h"
1213
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1314
#include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN
1415
#include "src/__support/macros/properties/architectures.h"
1516
#include "src/errno/libc_errno.h"
16-
1717
#include <fenv.h>
18-
#include <math.h>
1918

2019
#if defined(LIBC_TARGET_ARCH_IS_AARCH64)
2120
#if defined(__APPLE__)

libc/src/__support/FPUtil/ManipulationFunctions.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
#include "dyadic_float.h"
1616
#include "rounding_mode.h"
1717

18+
#include "include/llvm-libc-macros/math-macros.h"
1819
#include "src/__support/CPP/bit.h"
1920
#include "src/__support/CPP/limits.h" // INT_MAX, INT_MIN
2021
#include "src/__support/CPP/type_traits.h"
2122
#include "src/__support/FPUtil/FEnvImpl.h"
2223
#include "src/__support/macros/attributes.h"
2324
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
2425

25-
#include <math.h>
26-
2726
namespace LIBC_NAMESPACE {
2827
namespace fputil {
2928

libc/src/__support/FPUtil/NearestIntegerOperations.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
#include "FPBits.h"
1414
#include "rounding_mode.h"
1515

16+
#include "include/llvm-libc-macros/math-macros.h"
1617
#include "src/__support/CPP/type_traits.h"
1718
#include "src/__support/common.h"
1819

19-
#include <math.h>
20-
2120
namespace LIBC_NAMESPACE {
2221
namespace fputil {
2322

libc/src/math/generic/math_utils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
#ifndef LLVM_LIBC_SRC_MATH_GENERIC_MATH_UTILS_H
1010
#define LLVM_LIBC_SRC_MATH_GENERIC_MATH_UTILS_H
1111

12+
#include "include/llvm-libc-macros/math-macros.h"
1213
#include "src/__support/CPP/bit.h"
1314
#include "src/__support/CPP/type_traits.h"
1415
#include "src/__support/common.h"
1516
#include "src/errno/libc_errno.h"
1617

17-
#include <math.h>
18-
1918
#include <stdint.h>
2019

2120
// TODO: evaluate which functions from this file are actually used.

libc/test/UnitTest/FPMatcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "test/UnitTest/StringUtils.h"
1818
#include "test/UnitTest/Test.h"
1919

20-
#include <math.h>
20+
#include "include/llvm-libc-macros/math-macros.h"
2121

2222
namespace LIBC_NAMESPACE {
2323
namespace testing {

libc/test/src/__support/uint_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "src/__support/UInt.h"
1111
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
1212

13+
#include "include/llvm-libc-macros/math-macros.h" // HUGE_VALF, HUGE_VALF
1314
#include "test/UnitTest/Test.h"
14-
#include <math.h> // HUGE_VALF, HUGE_VALF
1515

1616
namespace LIBC_NAMESPACE {
1717

libc/test/src/math/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,8 @@ add_fp_unittest(
15181518
DEPENDS
15191519
libc.include.math
15201520
libc.src.math.generic.explogxf
1521+
libc.src.math.fabs
1522+
libc.src.math.fabsf
15211523
libc.src.__support.FPUtil.fp_bits
15221524
)
15231525

libc/test/src/math/CeilTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "test/UnitTest/Test.h"
1111
#include "utils/MPFRWrapper/MPFRUtils.h"
1212

13-
#include <math.h>
13+
#include "include/llvm-libc-macros/math-macros.h"
1414

1515
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
1616

libc/test/src/math/CopySignTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "test/UnitTest/Test.h"
1111
#include "utils/MPFRWrapper/MPFRUtils.h"
1212

13-
#include <math.h>
13+
#include "include/llvm-libc-macros/math-macros.h"
1414

1515
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
1616

libc/test/src/math/FAbsTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "test/UnitTest/Test.h"
1414
#include "utils/MPFRWrapper/MPFRUtils.h"
1515

16-
#include <math.h>
16+
#include "include/llvm-libc-macros/math-macros.h"
1717

1818
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
1919

libc/test/src/math/FDimTest.h

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

9+
#include "include/llvm-libc-macros/math-macros.h"
910
#include "src/__support/FPUtil/BasicOperations.h"
1011
#include "src/__support/FPUtil/FPBits.h"
1112
#include "test/UnitTest/FPMatcher.h"
1213
#include "test/UnitTest/Test.h"
13-
#include <math.h>
1414

1515
template <typename T>
1616
class FDimTestTemplate : public LIBC_NAMESPACE::testing::Test {

libc/test/src/math/FMaxTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "test/UnitTest/Test.h"
1414
#include "utils/MPFRWrapper/MPFRUtils.h"
1515

16-
#include <math.h>
16+
#include "include/llvm-libc-macros/math-macros.h"
1717

1818
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
1919

libc/test/src/math/FMinTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "test/UnitTest/Test.h"
1414
#include "utils/MPFRWrapper/MPFRUtils.h"
1515

16-
#include <math.h>
16+
#include "include/llvm-libc-macros/math-macros.h"
1717

1818
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
1919

libc/test/src/math/FModTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "test/UnitTest/FPMatcher.h"
1515
#include "test/UnitTest/Test.h"
1616

17-
#include <math.h>
17+
#include "include/llvm-libc-macros/math-macros.h"
1818

1919
#define TEST_SPECIAL(x, y, expected, dom_err, expected_exception) \
2020
EXPECT_FP_EQ(expected, f(x, y)); \

libc/test/src/math/FloorTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "test/UnitTest/Test.h"
1414
#include "utils/MPFRWrapper/MPFRUtils.h"
1515

16-
#include <math.h>
16+
#include "include/llvm-libc-macros/math-macros.h"
1717

1818
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
1919

libc/test/src/math/FrexpTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "test/UnitTest/Test.h"
1212
#include "utils/MPFRWrapper/MPFRUtils.h"
1313

14-
#include <math.h>
14+
#include "include/llvm-libc-macros/math-macros.h"
1515

1616
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
1717

libc/test/src/math/HypotTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "test/UnitTest/Test.h"
1515
#include "utils/MPFRWrapper/MPFRUtils.h"
1616

17-
#include <math.h>
17+
#include "include/llvm-libc-macros/math-macros.h"
1818

1919
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
2020

libc/test/src/math/ILogbTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
#ifndef LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H
1010
#define LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H
1111

12+
#include "include/llvm-libc-macros/math-macros.h"
1213
#include "src/__support/CPP/limits.h" // INT_MAX
1314
#include "src/__support/FPUtil/FPBits.h"
1415
#include "src/__support/FPUtil/ManipulationFunctions.h"
1516
#include "test/UnitTest/Test.h"
16-
#include <math.h>
1717

1818
class LlvmLibcILogbTest : public LIBC_NAMESPACE::testing::Test {
1919
public:

libc/test/src/math/LdExpTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "test/UnitTest/FPMatcher.h"
1616
#include "test/UnitTest/Test.h"
1717

18-
#include <math.h>
18+
#include "include/llvm-libc-macros/math-macros.h"
1919
#include <stdint.h>
2020

2121
template <typename T>

libc/test/src/math/LogbTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "test/UnitTest/Test.h"
1212
#include "utils/MPFRWrapper/MPFRUtils.h"
1313

14-
#include <math.h>
14+
#include "include/llvm-libc-macros/math-macros.h"
1515

1616
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
1717

libc/test/src/math/ModfTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "test/UnitTest/Test.h"
1313
#include "utils/MPFRWrapper/MPFRUtils.h"
1414

15-
#include <math.h>
15+
#include "include/llvm-libc-macros/math-macros.h"
1616

1717
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
1818

libc/test/src/math/NextAfterTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
#ifndef LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H
1010
#define LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H
1111

12+
#include "include/llvm-libc-macros/math-macros.h"
1213
#include "src/__support/CPP/bit.h"
1314
#include "src/__support/CPP/type_traits.h"
1415
#include "src/__support/FPUtil/BasicOperations.h"
1516
#include "src/__support/FPUtil/FPBits.h"
1617
#include "test/UnitTest/FPMatcher.h"
1718
#include "test/UnitTest/Test.h"
18-
#include <math.h>
1919

2020
template <typename T>
2121
class NextAfterTestTemplate : public LIBC_NAMESPACE::testing::Test {

libc/test/src/math/RIntTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include "test/UnitTest/Test.h"
1616
#include "utils/MPFRWrapper/MPFRUtils.h"
1717

18+
#include "include/llvm-libc-macros/math-macros.h"
1819
#include <fenv.h>
19-
#include <math.h>
2020
#include <stdio.h>
2121

2222
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;

libc/test/src/math/RemQuoTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
#ifndef LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H
1010
#define LLVM_LIBC_TEST_SRC_MATH_REMQUOTEST_H
1111

12+
#include "include/llvm-libc-macros/math-macros.h"
1213
#include "src/__support/FPUtil/BasicOperations.h"
1314
#include "src/__support/FPUtil/FPBits.h"
1415
#include "test/UnitTest/FPMatcher.h"
1516
#include "test/UnitTest/Test.h"
1617
#include "utils/MPFRWrapper/MPFRUtils.h"
17-
#include <math.h>
1818

1919
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
2020

libc/test/src/math/RoundTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "test/UnitTest/Test.h"
1414
#include "utils/MPFRWrapper/MPFRUtils.h"
1515

16-
#include <math.h>
16+
#include "include/llvm-libc-macros/math-macros.h"
1717

1818
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
1919

libc/test/src/math/RoundToIntegerTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include "test/UnitTest/Test.h"
1616
#include "utils/MPFRWrapper/MPFRUtils.h"
1717

18+
#include "include/llvm-libc-macros/math-macros.h"
1819
#include <errno.h>
19-
#include <math.h>
2020

2121
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
2222

libc/test/src/math/SqrtTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "test/UnitTest/Test.h"
1212
#include "utils/MPFRWrapper/MPFRUtils.h"
1313

14-
#include <math.h>
14+
#include "include/llvm-libc-macros/math-macros.h"
1515

1616
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
1717

libc/test/src/math/TruncTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "test/UnitTest/Test.h"
1414
#include "utils/MPFRWrapper/MPFRUtils.h"
1515

16-
#include <math.h>
16+
#include "include/llvm-libc-macros/math-macros.h"
1717

1818
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
1919

libc/test/src/math/acosf_test.cpp

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

9+
#include "include/llvm-libc-macros/math-macros.h"
910
#include "src/__support/FPUtil/FPBits.h"
1011
#include "src/errno/libc_errno.h"
1112
#include "src/math/acosf.h"
1213
#include "test/UnitTest/FPMatcher.h"
1314
#include "test/UnitTest/Test.h"
1415
#include "utils/MPFRWrapper/MPFRUtils.h"
15-
#include <math.h>
1616

1717
#include <errno.h>
1818
#include <stdint.h>

libc/test/src/math/acoshf_test.cpp

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

9+
#include "include/llvm-libc-macros/math-macros.h"
910
#include "src/__support/FPUtil/FPBits.h"
1011
#include "src/errno/libc_errno.h"
1112
#include "src/math/acoshf.h"
1213
#include "test/UnitTest/FPMatcher.h"
1314
#include "test/UnitTest/Test.h"
1415
#include "utils/MPFRWrapper/MPFRUtils.h"
15-
#include <math.h>
1616

1717
#include <errno.h>
1818
#include <stdint.h>

libc/test/src/math/asinf_test.cpp

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

10+
#include "include/llvm-libc-macros/math-macros.h"
1011
#include "src/__support/FPUtil/FPBits.h"
1112
#include "src/errno/libc_errno.h"
1213
#include "src/math/asinf.h"
1314
#include "test/UnitTest/FPMatcher.h"
1415
#include "test/UnitTest/Test.h"
1516
#include "utils/MPFRWrapper/MPFRUtils.h"
16-
#include <math.h>
1717

1818
#include <errno.h>
1919
#include <stdint.h>

0 commit comments

Comments
 (0)