-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Provide LIBC_TYPES_HAS_INT64
#83441
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
Conversation
@llvm/pr-subscribers-libc Author: Guillaume Chatelet (gchatelet) ChangesUmbrella bug #83182 Full diff: https://github.com/llvm/llvm-project/pull/83441.diff 5 Files Affected:
diff --git a/libc/src/__support/UInt.h b/libc/src/__support/UInt.h
index 5973e6fab1d7d5..057d0a7a50f1c1 100644
--- a/libc/src/__support/UInt.h
+++ b/libc/src/__support/UInt.h
@@ -15,9 +15,10 @@
#include "src/__support/CPP/optional.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/integer_utils.h"
-#include "src/__support/macros/attributes.h" // LIBC_INLINE
-#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
-#include "src/__support/math_extras.h" // SumCarry, DiffBorrow
+#include "src/__support/macros/attributes.h" // LIBC_INLINE
+#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT64
+#include "src/__support/math_extras.h" // SumCarry, DiffBorrow
#include "src/__support/number_pair.h"
#include <stddef.h> // For size_t
@@ -872,11 +873,11 @@ namespace internal {
// availability.
template <size_t Bits>
struct WordTypeSelector : cpp::type_identity<
-#if defined(UINT64_MAX)
+#ifdef LIBC_TYPES_HAS_INT64
uint64_t
#else
uint32_t
-#endif
+#endif // LIBC_TYPES_HAS_INT64
> {
};
// Except if we request 32 bits explicitly.
diff --git a/libc/src/__support/macros/properties/CMakeLists.txt b/libc/src/__support/macros/properties/CMakeLists.txt
index bbc45650f3fca3..62436a8ebf2da1 100644
--- a/libc/src/__support/macros/properties/CMakeLists.txt
+++ b/libc/src/__support/macros/properties/CMakeLists.txt
@@ -34,5 +34,6 @@ add_header_library(
.cpu_features
.os
libc.include.llvm-libc-macros.float_macros
+ libc.include.llvm-libc-macros.stdint_macros
libc.include.llvm-libc-types.float128
)
diff --git a/libc/src/__support/macros/properties/types.h b/libc/src/__support/macros/properties/types.h
index 8760f78875c417..94b0829b6bdc2a 100644
--- a/libc/src/__support/macros/properties/types.h
+++ b/libc/src/__support/macros/properties/types.h
@@ -17,6 +17,8 @@
#include "src/__support/macros/properties/cpu_features.h"
#include "src/__support/macros/properties/os.h"
+#include <stdint.h> // UINT64_MAX
+
// 'long double' properties.
#if (LDBL_MANT_DIG == 53)
#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64
@@ -26,6 +28,11 @@
#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128
#endif
+// int64 / uint64 support
+#if defined(UINT64_MAX)
+#define LIBC_TYPES_HAS_INT64
+#endif // UINT64_MAX
+
// -- float16 support ---------------------------------------------------------
// TODO: move this logic to "llvm-libc-types/float16.h"
#if defined(LIBC_TARGET_ARCH_IS_X86_64) && defined(LIBC_TARGET_CPU_HAS_SSE2)
diff --git a/libc/src/string/memory_utils/op_generic.h b/libc/src/string/memory_utils/op_generic.h
index 41fc1fa0f1ff01..efaff80b7e4da0 100644
--- a/libc/src/string/memory_utils/op_generic.h
+++ b/libc/src/string/memory_utils/op_generic.h
@@ -28,6 +28,7 @@
#include "src/__support/common.h"
#include "src/__support/endian.h"
#include "src/__support/macros/optimization.h"
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT64
#include "src/string/memory_utils/op_builtin.h"
#include "src/string/memory_utils/utils.h"
@@ -37,10 +38,6 @@ static_assert((UINTPTR_MAX == 4294967295U) ||
(UINTPTR_MAX == 18446744073709551615UL),
"We currently only support 32- or 64-bit platforms");
-#if defined(UINT64_MAX)
-#define LLVM_LIBC_HAS_UINT64
-#endif
-
namespace LIBC_NAMESPACE {
// Compiler types using the vector attributes.
using generic_v128 = uint8_t __attribute__((__vector_size__(16)));
@@ -60,9 +57,9 @@ template <typename T> struct is_scalar : cpp::false_type {};
template <> struct is_scalar<uint8_t> : cpp::true_type {};
template <> struct is_scalar<uint16_t> : cpp::true_type {};
template <> struct is_scalar<uint32_t> : cpp::true_type {};
-#ifdef LLVM_LIBC_HAS_UINT64
+#ifdef LIBC_TYPES_HAS_INT64
template <> struct is_scalar<uint64_t> : cpp::true_type {};
-#endif // LLVM_LIBC_HAS_UINT64
+#endif // LIBC_TYPES_HAS_INT64
// Meant to match std::numeric_limits interface.
// NOLINTNEXTLINE(readability-identifier-naming)
template <typename T> constexpr bool is_scalar_v = is_scalar<T>::value;
diff --git a/libc/test/src/string/memory_utils/op_tests.cpp b/libc/test/src/string/memory_utils/op_tests.cpp
index 15ac9607bf3e3d..95a04755eb4dbe 100644
--- a/libc/test/src/string/memory_utils/op_tests.cpp
+++ b/libc/test/src/string/memory_utils/op_tests.cpp
@@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//
#include "memory_check_utils.h"
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT64
#include "src/string/memory_utils/op_aarch64.h"
#include "src/string/memory_utils/op_builtin.h"
-#include "src/string/memory_utils/op_generic.h" // LLVM_LIBC_HAS_UINT64
#include "src/string/memory_utils/op_riscv.h"
#include "src/string/memory_utils/op_x86.h"
#include "test/UnitTest/Test.h"
@@ -124,9 +124,9 @@ using MemsetImplementations = testing::TypeList<
builtin::Memset<32>, //
builtin::Memset<64>,
#endif
-#ifdef LLVM_LIBC_HAS_UINT64
+#ifdef LIBC_TYPES_HAS_INT64
generic::Memset<uint64_t>, generic::Memset<cpp::array<uint64_t, 2>>,
-#endif
+#endif // LIBC_TYPES_HAS_INT64
#ifdef __AVX512F__
generic::Memset<generic_v512>, generic::Memset<cpp::array<generic_v512, 2>>,
#endif
@@ -210,9 +210,9 @@ using BcmpImplementations = testing::TypeList<
#ifndef LIBC_TARGET_ARCH_IS_ARM // Removing non uint8_t types for ARM
generic::Bcmp<uint16_t>,
generic::Bcmp<uint32_t>, //
-#ifdef LLVM_LIBC_HAS_UINT64
+#ifdef LIBC_TYPES_HAS_INT64
generic::Bcmp<uint64_t>,
-#endif // LLVM_LIBC_HAS_UINT64
+#endif // LIBC_TYPES_HAS_INT64
generic::BcmpSequence<uint16_t, uint8_t>,
generic::BcmpSequence<uint32_t, uint8_t>, //
generic::BcmpSequence<uint32_t, uint16_t>, //
@@ -292,9 +292,9 @@ using MemcmpImplementations = testing::TypeList<
#ifndef LIBC_TARGET_ARCH_IS_ARM // Removing non uint8_t types for ARM
generic::Memcmp<uint16_t>,
generic::Memcmp<uint32_t>, //
-#ifdef LLVM_LIBC_HAS_UINT64
+#ifdef LIBC_TYPES_HAS_INT64
generic::Memcmp<uint64_t>,
-#endif // LLVM_LIBC_HAS_UINT64
+#endif // LIBC_TYPES_HAS_INT64
generic::MemcmpSequence<uint16_t, uint8_t>,
generic::MemcmpSequence<uint32_t, uint16_t, uint8_t>, //
#endif // LIBC_TARGET_ARCH_IS_ARM
|
#include "src/__support/macros/properties/architectures.h" | ||
#include "src/__support/macros/properties/compiler.h" | ||
#include "src/__support/macros/properties/cpu_features.h" | ||
#include "src/__support/macros/properties/os.h" | ||
|
||
#include <stdint.h> // UINT64_MAX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you switch to <stdint.h>
instead of stdint-macros.h
? I think using our provided header would make it more hermetic and consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This triggers a lot of errors like the following
/redacted/git/llvm-project/libc/include/llvm-libc-macros/stdint-macros.h:832:9: error: 'INTMAX_MIN' macro redefined [-Werror,-Wmacro-redefined]
#define INTMAX_MIN (-__INTMAX_MAX__ - 1)
^
/usr/lib/llvm-16/lib/clang/16/include/stdint.h:927:10: note: previous definition is here
#define INTMAX_MIN (-__INTMAX_MAX__-1)
I believe this is because types.h
is quite up in the include hierarchy. We probably need to replace all #include <stdint.h>
with #include "include/llvm-libc-macros/stdint-macros.h"
in one shot and I'm reluctant to do this in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably need to replace all #include <stdint.h> with #include "include/llvm-libc-macros/stdint-macros.h"
Especially because the use of <>
includes is most of the remaining lint warnings.
Heads up, this broke the 32b arm build bot: https://lab.llvm.org/buildbot/#/builders/229/builds/23820 |
I'm on it. |
Introduced by llvm#83441.
Umbrella bug #83182