Skip to content

Commit caba6d1

Browse files
[libc] Remove direct math.h includes from src (#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 8f9ee39 commit caba6d1

File tree

8 files changed

+22
-10
lines changed

8 files changed

+22
-10
lines changed

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/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:

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,17 @@ config_setting(
6262
flag_values = {":mpfr": "system"},
6363
)
6464

65-
############################## Support libraries #############################
65+
################################# Include Files ################################
66+
67+
libc_support_library(
68+
name = "internal_includes",
69+
hdrs = glob([
70+
"include/llvm-libc-macros/*.h",
71+
"include/llvm-libc/types/*",
72+
]),
73+
)
74+
75+
############################### Support libraries ##############################
6676

6777
libc_support_library(
6878
name = "__support_macros_properties_architectures",
@@ -670,6 +680,7 @@ libc_support_library(
670680
":__support_macros_properties_architectures",
671681
":__support_macros_sanitizer",
672682
":errno",
683+
":internal_includes",
673684
],
674685
)
675686

@@ -739,6 +750,7 @@ libc_support_library(
739750
":__support_fputil_normal_float",
740751
":__support_macros_optimization",
741752
":__support_uint128",
753+
":internal_includes",
742754
],
743755
)
744756

@@ -752,6 +764,7 @@ libc_support_library(
752764
":__support_fputil_fp_bits",
753765
":__support_fputil_rounding_mode",
754766
":__support_macros_attributes",
767+
":internal_includes",
755768
],
756769
)
757770

@@ -1173,6 +1186,7 @@ libc_support_library(
11731186
"__support_cpp_type_traits",
11741187
":__support_common",
11751188
":errno",
1189+
":internal_includes",
11761190
],
11771191
)
11781192

utils/bazel/llvm-project-overlay/libc/test/src/__support/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ libc_test(
6464
name = "integer_to_string_test",
6565
srcs = ["integer_to_string_test.cpp"],
6666
deps = [
67+
"//libc:__support_cpp_limits",
6768
"//libc:__support_cpp_span",
6869
"//libc:__support_cpp_limits",
6970
"//libc:__support_cpp_string_view",

utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ libc_support_library(
296296
"//libc:__support_cpp_limits",
297297
"//libc:__support_fputil_fp_bits",
298298
"//libc:__support_fputil_manipulation_functions",
299+
"//libc:internal_includes",
299300
"//libc/test/UnitTest:LibcUnitTest",
300301
],
301302
)

0 commit comments

Comments
 (0)