Skip to content

[libc] force GCC limits.h to not include_next limits.h #79211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions libc/src/__support/CPP/limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,25 @@
#include "src/__support/CPP/type_traits/is_signed.h"
#include "src/__support/macros/attributes.h" // LIBC_INLINE

// Coax GCC to NOT attempt to include_next limits.h from glibc. llvmlibc should
// include this file rather than <limits.h> directy for this reason.
#ifndef __clang__
#define _LIBC_LIMITS_H_
#endif
#include <limits.h> // CHAR_BIT

// GCC's limits.h only defines these for __STDC_VERSION__ >= 199901L, i.e. not
// C++.
#ifndef LLONG_MAX
#define LLONG_MAX __LONG_LONG_MAX__
#endif
#ifndef LLONG_MIN
#define LLONG_MIN (-LONG_MAX - 1LL)
#endif
#ifndef ULLONG_MAX
#define ULLONG_MAX (~0ULL)
#endif

namespace LIBC_NAMESPACE {
namespace cpp {

Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/ManipulationFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
#include "NormalFloat.h"

#include "src/__support/CPP/bit.h"
#include "src/__support/CPP/limits.h" // INT_MAX, INT_MIN
#include "src/__support/CPP/type_traits.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY

#include <limits.h>
#include <math.h>

namespace LIBC_NAMESPACE {
Expand Down
3 changes: 1 addition & 2 deletions libc/src/__support/math_extras.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_EXTRAS_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_EXTRAS_H

#include "src/__support/CPP/limits.h" // CHAR_BIT
#include "src/__support/CPP/type_traits.h" // is_unsigned_v
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN

#include <limits.h> // CHAR_BIT

namespace LIBC_NAMESPACE {

// Create a bitmask with the count right-most bits set to 1, and all other bits
Expand Down
1 change: 0 additions & 1 deletion libc/src/__support/str_to_integer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "src/__support/ctype_utils.h"
#include "src/__support/str_to_num_result.h"
#include "src/errno/libc_errno.h" // For ERANGE
#include <limits.h>

namespace LIBC_NAMESPACE {
namespace internal {
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/threads/linux/callonce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include "futex_word.h"

#include "src/__support/CPP/atomic.h"
#include "src/__support/CPP/limits.h" // For INT_MAX.
#include "src/__support/OSUtil/syscall.h" // For syscall functions.
#include "src/__support/threads/callonce.h"

#include <limits.h>
#include <linux/futex.h>
#include <sys/syscall.h> // For syscall numbers.

Expand Down
1 change: 1 addition & 0 deletions libc/src/threads/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_entrypoint_object(
call_once.h
DEPENDS
libc.include.threads
libc.src.__support.CPP.limits
libc.src.__support.threads.callonce
)

Expand Down
2 changes: 1 addition & 1 deletion libc/src/threads/linux/call_once.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#include "Futex.h"

#include "src/__support/CPP/atomic.h"
#include "src/__support/CPP/limits.h" // For INT_MAX.
#include "src/__support/OSUtil/syscall.h" // For syscall functions.
#include "src/__support/common.h"
#include "src/threads/call_once.h"
#include "src/threads/linux/Futex.h"

#include <limits.h>
#include <linux/futex.h>
#include <sys/syscall.h> // For syscall numbers.
#include <threads.h> // For call_once related type definition.
Expand Down
1 change: 1 addition & 0 deletions libc/src/time/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_object_library(
time_utils.h
DEPENDS
libc.include.time
libc.src.__support.CPP.limits
libc.src.errno.errno
)

Expand Down
2 changes: 0 additions & 2 deletions libc/src/time/mktime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include "src/__support/common.h"
#include "src/time/time_utils.h"

#include <limits.h>

namespace LIBC_NAMESPACE {

using LIBC_NAMESPACE::time_utils::TimeConstants;
Expand Down
3 changes: 1 addition & 2 deletions libc/src/time/time_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
//===----------------------------------------------------------------------===//

#include "src/time/time_utils.h"
#include "src/__support/CPP/limits.h" // INT_MAX, INT_MIN
#include "src/__support/common.h"

#include <limits.h>

namespace LIBC_NAMESPACE {
namespace time_utils {

Expand Down
3 changes: 1 addition & 2 deletions libc/test/src/math/ILogbTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H

#include "src/__support/CPP/limits.h" // INT_MAX
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/ManipulationFunctions.h"
#include "test/UnitTest/Test.h"
#include <math.h>

#include <limits.h>

class LlvmLibcILogbTest : public LIBC_NAMESPACE::testing::Test {
public:
template <typename T> struct ILogbFunc {
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/math/LdExpTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_LDEXPTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_LDEXPTEST_H

#include "src/__support/CPP/limits.h" // INT_MAX
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/NormalFloat.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"

#include <limits.h>
#include <math.h>
#include <stdint.h>

Expand Down
3 changes: 1 addition & 2 deletions libc/test/src/math/smoke/ILogbTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_ILOGBTEST_H

#include "src/__support/CPP/limits.h" // INT_MAX
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/ManipulationFunctions.h"
#include "test/UnitTest/Test.h"
#include <math.h>

#include <limits.h>

class LlvmLibcILogbTest : public LIBC_NAMESPACE::testing::Test {
public:
template <typename T> struct ILogbFunc {
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/math/smoke/LdExpTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#ifndef LLVM_LIBC_TEST_SRC_MATH_LDEXPTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_LDEXPTEST_H

#include "src/__support/CPP/limits.h" // INT_MAX
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/NormalFloat.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"

#include <limits.h>
#include <math.h>
#include <stdint.h>

Expand Down
3 changes: 1 addition & 2 deletions libc/test/src/stdlib/AtoiTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/CPP/limits.h" // INT_MAX, INT_MIN, LLONG_MAX, LLONG_MIN
#include "src/__support/CPP/type_traits.h"
#include "test/UnitTest/Test.h"

#include <limits.h>

using LIBC_NAMESPACE::cpp::is_same_v;

template <typename ReturnT>
Expand Down
6 changes: 3 additions & 3 deletions libc/test/src/stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
SRCS
strtod_test.cpp
DEPENDS
libc.src.__support.FPUtil.fenv_impl
libc.src.errno.errno
libc.src.stdlib.strtod
libc.src.__support.FPUtil.fenv_impl
)
endif()

Expand All @@ -75,9 +75,9 @@ add_fp_unittest(
SRCS
strtof_test.cpp
DEPENDS
libc.src.__support.FPUtil.fenv_impl
libc.src.errno.errno
libc.src.stdlib.strtof
libc.src.__support.FPUtil.fenv_impl
)

add_header_library(
Expand Down Expand Up @@ -134,8 +134,8 @@ if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
SRCS
strtold_test.cpp
DEPENDS
libc.src.errno.errno
libc.src.__support.uint128
libc.src.errno.errno
libc.src.stdlib.strtold
)
endif()
Expand Down
1 change: 0 additions & 1 deletion libc/test/src/stdlib/StrtolTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "src/errno/libc_errno.h"
#include "test/UnitTest/Test.h"

#include <limits.h>
#include <stddef.h>

using LIBC_NAMESPACE::cpp::is_signed_v;
Expand Down
1 change: 0 additions & 1 deletion libc/test/src/stdlib/atof_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"

#include <limits.h>
#include <stddef.h>

using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
Expand Down
1 change: 0 additions & 1 deletion libc/test/src/stdlib/strtod_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "test/UnitTest/RoundingModeUtils.h"
#include "test/UnitTest/Test.h"

#include <limits.h>
#include <stddef.h>

using LIBC_NAMESPACE::fputil::testing::ForceRoundingModeTest;
Expand Down
1 change: 0 additions & 1 deletion libc/test/src/stdlib/strtof_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "test/UnitTest/RoundingModeUtils.h"
#include "test/UnitTest/Test.h"

#include <limits.h>
#include <stddef.h>

using LIBC_NAMESPACE::fputil::testing::ForceRoundingModeTest;
Expand Down
1 change: 0 additions & 1 deletion libc/test/src/stdlib/strtold_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include "test/UnitTest/Test.h"

#include <limits.h>
#include <stddef.h>

#if defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
Expand Down
7 changes: 5 additions & 2 deletions libc/test/src/time/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ add_libc_unittest(
HDRS
TmMatcher.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.time.gmtime
)

Expand Down Expand Up @@ -97,6 +98,7 @@ add_libc_unittest(
CXX_STANDARD
20
DEPENDS
libc.src.__support.CPP.limits
libc.src.time.mktime
)

Expand Down Expand Up @@ -124,8 +126,9 @@ add_libc_unittest(
time_test.cpp
DEPENDS
libc.include.time
libc.src.time.time
libc.src.__support.CPP.limits
libc.src.errno.errno
libc.src.time.time
)

add_libc_test(
Expand All @@ -136,6 +139,6 @@ add_libc_test(
clock_test.cpp
DEPENDS
libc.include.time
libc.src.time.clock
libc.src.errno.errno
libc.src.time.clock
)
1 change: 0 additions & 1 deletion libc/test/src/time/clock_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "src/time/clock.h"
#include "test/UnitTest/Test.h"

#include <limits.h>
#include <time.h>

TEST(LlvmLibcClockTest, SmokeTest) {
Expand Down
3 changes: 1 addition & 2 deletions libc/test/src/time/gmtime_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/CPP/limits.h" // INT_MAX, INT_MIN
#include "src/errno/libc_errno.h"
#include "src/time/gmtime.h"
#include "src/time/time_utils.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
#include "test/src/time/TmMatcher.h"

#include <limits.h>

using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
using LIBC_NAMESPACE::time_utils::TimeConstants;
Expand Down
3 changes: 1 addition & 2 deletions libc/test/src/time/mktime_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/CPP/limits.h" // INT_MAX
#include "src/time/mktime.h"
#include "src/time/time_utils.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
#include "test/src/time/TmHelper.h"
#include "test/src/time/TmMatcher.h"

#include <limits.h>

using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
using LIBC_NAMESPACE::time_utils::Month;
Expand Down
1 change: 0 additions & 1 deletion libc/test/src/time/time_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "src/time/time_func.h"
#include "test/UnitTest/Test.h"

#include <limits.h>
#include <time.h>

TEST(LlvmLibcTimeTest, SmokeTest) {
Expand Down