Skip to content

Commit e2a37e5

Browse files
authored
[libc][NFC] Fix missing LIBC_INLINE + style (#73659)
1 parent 91e1b4a commit e2a37e5

File tree

11 files changed

+73
-52
lines changed

11 files changed

+73
-52
lines changed

libc/src/__support/CPP/limits.h

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H
1010
#define LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H
1111

12+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
13+
1214
#include <limits.h>
1315

1416
namespace LIBC_NAMESPACE {
@@ -24,74 +26,74 @@ constexpr unsigned long long ULLONG_MAX = ~0ULL;
2426

2527
template <class T> class numeric_limits {
2628
public:
27-
static constexpr T max();
28-
static constexpr T min();
29+
LIBC_INLINE static constexpr T max();
30+
LIBC_INLINE static constexpr T min();
2931
};
3032

3133
// TODO: Add numeric_limits specializations as needed for new types.
3234

3335
template <> class numeric_limits<int> {
3436
public:
35-
static constexpr int max() { return INT_MAX; }
36-
static constexpr int min() { return INT_MIN; }
37+
LIBC_INLINE static constexpr int max() { return INT_MAX; }
38+
LIBC_INLINE static constexpr int min() { return INT_MIN; }
3739
};
3840
template <> class numeric_limits<unsigned int> {
3941
public:
40-
static constexpr unsigned int max() { return UINT_MAX; }
41-
static constexpr unsigned int min() { return 0; }
42+
LIBC_INLINE static constexpr unsigned int max() { return UINT_MAX; }
43+
LIBC_INLINE static constexpr unsigned int min() { return 0; }
4244
};
4345
template <> class numeric_limits<long> {
4446
public:
45-
static constexpr long max() { return LONG_MAX; }
46-
static constexpr long min() { return LONG_MIN; }
47+
LIBC_INLINE static constexpr long max() { return LONG_MAX; }
48+
LIBC_INLINE static constexpr long min() { return LONG_MIN; }
4749
};
4850
template <> class numeric_limits<unsigned long> {
4951
public:
50-
static constexpr unsigned long max() { return ULONG_MAX; }
51-
static constexpr unsigned long min() { return 0; }
52+
LIBC_INLINE static constexpr unsigned long max() { return ULONG_MAX; }
53+
LIBC_INLINE static constexpr unsigned long min() { return 0; }
5254
};
5355
template <> class numeric_limits<long long> {
5456
public:
55-
static constexpr long long max() { return LLONG_MAX; }
56-
static constexpr long long min() { return LLONG_MIN; }
57+
LIBC_INLINE static constexpr long long max() { return LLONG_MAX; }
58+
LIBC_INLINE static constexpr long long min() { return LLONG_MIN; }
5759
};
5860
template <> class numeric_limits<unsigned long long> {
5961
public:
60-
static constexpr unsigned long long max() { return ULLONG_MAX; }
61-
static constexpr unsigned long long min() { return 0; }
62+
LIBC_INLINE static constexpr unsigned long long max() { return ULLONG_MAX; }
63+
LIBC_INLINE static constexpr unsigned long long min() { return 0; }
6264
};
6365
template <> class numeric_limits<short> {
6466
public:
65-
static constexpr short max() { return SHRT_MAX; }
66-
static constexpr short min() { return SHRT_MIN; }
67+
LIBC_INLINE static constexpr short max() { return SHRT_MAX; }
68+
LIBC_INLINE static constexpr short min() { return SHRT_MIN; }
6769
};
6870
template <> class numeric_limits<unsigned short> {
6971
public:
70-
static constexpr unsigned short max() { return USHRT_MAX; }
71-
static constexpr unsigned short min() { return 0; }
72+
LIBC_INLINE static constexpr unsigned short max() { return USHRT_MAX; }
73+
LIBC_INLINE static constexpr unsigned short min() { return 0; }
7274
};
7375
template <> class numeric_limits<char> {
7476
public:
75-
static constexpr char max() { return CHAR_MAX; }
76-
static constexpr char min() { return CHAR_MIN; }
77+
LIBC_INLINE static constexpr char max() { return CHAR_MAX; }
78+
LIBC_INLINE static constexpr char min() { return CHAR_MIN; }
7779
};
7880
template <> class numeric_limits<signed char> {
7981
public:
80-
static constexpr signed char max() { return SCHAR_MAX; }
81-
static constexpr signed char min() { return SCHAR_MIN; }
82+
LIBC_INLINE static constexpr signed char max() { return SCHAR_MAX; }
83+
LIBC_INLINE static constexpr signed char min() { return SCHAR_MIN; }
8284
};
8385
template <> class numeric_limits<unsigned char> {
8486
public:
85-
static constexpr unsigned char max() { return UCHAR_MAX; }
86-
static constexpr unsigned char min() { return 0; }
87+
LIBC_INLINE static constexpr unsigned char max() { return UCHAR_MAX; }
88+
LIBC_INLINE static constexpr unsigned char min() { return 0; }
8789
};
8890
#ifdef __SIZEOF_INT128__
8991
// On platform where UInt128 resolves to __uint128_t, this specialization
9092
// provides the limits of UInt128.
9193
template <> class numeric_limits<__uint128_t> {
9294
public:
93-
static constexpr __uint128_t max() { return ~__uint128_t(0); }
94-
static constexpr __uint128_t min() { return 0; }
95+
LIBC_INLINE static constexpr __uint128_t max() { return ~__uint128_t(0); }
96+
LIBC_INLINE static constexpr __uint128_t min() { return 0; }
9597
};
9698
#endif
9799

libc/src/__support/CPP/type_traits/invoke.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "src/__support/CPP/type_traits/is_pointer.h"
1717
#include "src/__support/CPP/type_traits/is_same.h"
1818
#include "src/__support/CPP/utility/forward.h"
19+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1920

2021
namespace LIBC_NAMESPACE::cpp {
2122

@@ -26,7 +27,7 @@ template <class FunctionPtrType> struct invoke_dispatcher {
2627
template <class T, class... Args,
2728
typename = cpp::enable_if_t<
2829
cpp::is_same_v<cpp::decay_t<T>, FunctionPtrType>>>
29-
static decltype(auto) call(T &&fun, Args &&...args) {
30+
LIBC_INLINE static decltype(auto) call(T &&fun, Args &&...args) {
3031
return cpp::forward<T>(fun)(cpp::forward<Args>(args)...);
3132
}
3233
};
@@ -37,7 +38,8 @@ struct invoke_dispatcher<FunctionReturnType Class::*> {
3738
using FunctionPtrType = FunctionReturnType Class::*;
3839

3940
template <class T, class... Args, class DecayT = cpp::decay_t<T>>
40-
static decltype(auto) call(FunctionPtrType fun, T &&t1, Args &&...args) {
41+
LIBC_INLINE static decltype(auto) call(FunctionPtrType fun, T &&t1,
42+
Args &&...args) {
4143
if constexpr (cpp::is_base_of_v<Class, DecayT>) {
4244
// T is a (possibly cv ref) type.
4345
return (cpp::forward<T>(t1).*fun)(cpp::forward<Args>(args)...);

libc/src/__support/CPP/utility/in_place.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_IN_PLACE_H
99
#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_IN_PLACE_H
1010

11-
#include "src/__support/macros/attributes.h"
11+
#include "src/__support/macros/attributes.h" // LIBC_INLINE, LIBC_INLINE_VAR
1212

1313
#include <stddef.h> // size_t
1414

1515
namespace LIBC_NAMESPACE::cpp {
1616

1717
// in_place
1818
struct in_place_t {
19-
explicit in_place_t() = default;
19+
LIBC_INLINE explicit in_place_t() = default;
2020
};
2121
LIBC_INLINE_VAR constexpr in_place_t in_place{};
2222

2323
template <class T> struct in_place_type_t {
24-
explicit in_place_type_t() = default;
24+
LIBC_INLINE explicit in_place_type_t() = default;
2525
};
2626
template <class T> LIBC_INLINE_VAR constexpr in_place_type_t<T> in_place_type{};
2727

2828
template <size_t I> struct in_place_index_t {
29-
explicit in_place_index_t() = default;
29+
LIBC_INLINE explicit in_place_index_t() = default;
3030
};
3131
template <size_t I>
3232
LIBC_INLINE_VAR constexpr in_place_index_t<I> in_place_index{};

libc/src/__support/CPP/utility/move.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
#define LLVM_LIBC_SRC___SUPPORT_CPP_UTILITY_MOVE_H
1010

1111
#include "src/__support/CPP/type_traits/remove_reference.h"
12+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1213

1314
namespace LIBC_NAMESPACE::cpp {
1415

1516
// move
16-
template <class T> constexpr cpp::remove_reference_t<T> &&move(T &&t) {
17+
template <class T>
18+
LIBC_INLINE constexpr cpp::remove_reference_t<T> &&move(T &&t) {
1719
return static_cast<typename cpp::remove_reference_t<T> &&>(t);
1820
}
1921

libc/src/__support/FPUtil/FPBits.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "src/__support/CPP/type_traits.h"
1414
#include "src/__support/bit.h"
1515
#include "src/__support/common.h"
16+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1617

1718
#include "FloatProperties.h"
1819
#include <stdint.h>
@@ -106,13 +107,14 @@ template <typename T> struct FPBits {
106107
// We don't want accidental type promotions/conversions, so we require exact
107108
// type match.
108109
template <typename XType, cpp::enable_if_t<cpp::is_same_v<T, XType>, int> = 0>
109-
constexpr explicit FPBits(XType x) : bits(cpp::bit_cast<UIntType>(x)) {}
110+
LIBC_INLINE constexpr explicit FPBits(XType x)
111+
: bits(cpp::bit_cast<UIntType>(x)) {}
110112

111113
template <typename XType,
112114
cpp::enable_if_t<cpp::is_same_v<XType, UIntType>, int> = 0>
113-
constexpr explicit FPBits(XType x) : bits(x) {}
115+
LIBC_INLINE constexpr explicit FPBits(XType x) : bits(x) {}
114116

115-
constexpr FPBits() : bits(0) {}
117+
LIBC_INLINE constexpr FPBits() : bits(0) {}
116118

117119
LIBC_INLINE constexpr T get_val() const { return cpp::bit_cast<T>(bits); }
118120

libc/src/__support/FPUtil/FloatProperties.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOATPROPERTIES_H
1111

1212
#include "src/__support/UInt128.h"
13+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1314
#include "src/__support/macros/properties/float.h" // LIBC_COMPILER_HAS_FLOAT128
1415

1516
#include <stdint.h>
@@ -139,7 +140,7 @@ template <> struct FPProperties<FPType::IEEE754_Binary128> {
139140
};
140141

141142
//-----------------------------------------------------------------------------
142-
template <typename FP> static constexpr FPType get_fp_type() {
143+
template <typename FP> LIBC_INLINE static constexpr FPType get_fp_type() {
143144
if constexpr (cpp::is_same_v<FP, float> && __FLT_MANT_DIG__ == 24)
144145
return FPType::IEEE754_Binary32;
145146
else if constexpr (cpp::is_same_v<FP, double> && __DBL_MANT_DIG__ == 53)

libc/src/__support/FPUtil/x86_64/LongDoubleBits.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "src/__support/CPP/bit.h"
1313
#include "src/__support/UInt128.h"
1414
#include "src/__support/common.h"
15+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1516
#include "src/__support/macros/properties/architectures.h"
1617

1718
#if !defined(LIBC_TARGET_ARCH_IS_X86)
@@ -103,19 +104,20 @@ template <> struct FPBits<long double> {
103104
return bool((bits & FloatProp::SIGN_MASK) >> (FloatProp::BIT_WIDTH - 1));
104105
}
105106

106-
constexpr FPBits() : bits(0) {}
107+
LIBC_INLINE constexpr FPBits() : bits(0) {}
107108

108109
template <typename XType,
109110
cpp::enable_if_t<cpp::is_same_v<long double, XType>, int> = 0>
110-
constexpr explicit FPBits(XType x) : bits(cpp::bit_cast<UIntType>(x)) {
111+
LIBC_INLINE constexpr explicit FPBits(XType x)
112+
: bits(cpp::bit_cast<UIntType>(x)) {
111113
// bits starts uninitialized, and setting it to a long double only
112114
// overwrites the first 80 bits. This clears those upper bits.
113115
bits = bits & ((UIntType(1) << 80) - 1);
114116
}
115117

116118
template <typename XType,
117119
cpp::enable_if_t<cpp::is_same_v<XType, UIntType>, int> = 0>
118-
constexpr explicit FPBits(XType x) : bits(x) {}
120+
LIBC_INLINE constexpr explicit FPBits(XType x) : bits(x) {}
119121

120122
LIBC_INLINE constexpr operator long double() {
121123
return cpp::bit_cast<long double>(bits);

libc/src/__support/UInt.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "src/__support/CPP/type_traits.h"
1616
#include "src/__support/bit.h" // unsafe_clz
1717
#include "src/__support/integer_utils.h"
18+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1819
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
1920
#include "src/__support/math_extras.h" // SumCarry, DiffBorrow
2021
#include "src/__support/number_pair.h"
@@ -28,13 +29,13 @@ template <size_t Bits, bool Signed> struct BigInt {
2829

2930
static_assert(Bits > 0 && Bits % 64 == 0,
3031
"Number of bits in BigInt should be a multiple of 64.");
31-
static LIBC_INLINE_VAR constexpr size_t WORDCOUNT = Bits / 64;
32+
LIBC_INLINE_VAR static constexpr size_t WORDCOUNT = Bits / 64;
3233
uint64_t val[WORDCOUNT]{};
3334

34-
static LIBC_INLINE_VAR constexpr uint64_t MASK32 = 0xFFFFFFFFu;
35+
LIBC_INLINE_VAR static constexpr uint64_t MASK32 = 0xFFFFFFFFu;
3536

36-
static LIBC_INLINE constexpr uint64_t low(uint64_t v) { return v & MASK32; }
37-
static LIBC_INLINE constexpr uint64_t high(uint64_t v) {
37+
LIBC_INLINE static constexpr uint64_t low(uint64_t v) { return v & MASK32; }
38+
LIBC_INLINE static constexpr uint64_t high(uint64_t v) {
3839
return (v >> 32) & MASK32;
3940
}
4041

@@ -126,7 +127,8 @@ template <size_t Bits, bool Signed> struct BigInt {
126127

127128
LIBC_INLINE constexpr explicit operator bool() const { return !is_zero(); }
128129

129-
BigInt<Bits, Signed> &operator=(const BigInt<Bits, Signed> &other) = default;
130+
LIBC_INLINE BigInt<Bits, Signed> &
131+
operator=(const BigInt<Bits, Signed> &other) = default;
130132

131133
LIBC_INLINE constexpr bool is_zero() const {
132134
for (size_t i = 0; i < WORDCOUNT; ++i) {
@@ -324,8 +326,8 @@ template <size_t Bits, bool Signed> struct BigInt {
324326
// 196 3 9 6 2
325327
// 256 4 16 10 3
326328
// 512 8 64 36 7
327-
constexpr BigInt<Bits, Signed>
328-
LIBC_INLINE quick_mul_hi(const BigInt<Bits, Signed> &other) const {
329+
LIBC_INLINE constexpr BigInt<Bits, Signed>
330+
quick_mul_hi(const BigInt<Bits, Signed> &other) const {
329331
BigInt<Bits, Signed> result(0);
330332
BigInt<128, Signed> partial_sum(0);
331333
uint64_t carry = 0;
@@ -893,7 +895,7 @@ template <> class numeric_limits<UInt<128>> {
893895
LIBC_INLINE static constexpr UInt<128> max() {
894896
return UInt<128>({0xffff'ffff'ffff'ffff, 0xffff'ffff'ffff'ffff});
895897
}
896-
static constexpr UInt<128> min() { return UInt<128>(0); }
898+
LIBC_INLINE static constexpr UInt<128> min() { return UInt<128>(0); }
897899
};
898900

899901
template <> class numeric_limits<Int<128>> {

libc/src/__support/integer_operations.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010
#define LLVM_LIBC_SRC___SUPPORT_INTEGER_OPERATIONS_H
1111

1212
#include "src/__support/CPP/type_traits.h"
13+
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1314

1415
namespace LIBC_NAMESPACE {
1516

1617
template <typename T>
17-
static constexpr cpp::enable_if_t<cpp::is_integral_v<T>, T> integer_abs(T n) {
18+
LIBC_INLINE static constexpr cpp::enable_if_t<cpp::is_integral_v<T>, T>
19+
integer_abs(T n) {
1820
return (n < 0) ? -n : n;
1921
}
2022

2123
template <typename T>
22-
static constexpr cpp::enable_if_t<cpp::is_integral_v<T>, void>
24+
LIBC_INLINE static constexpr cpp::enable_if_t<cpp::is_integral_v<T>, void>
2325
integer_rem_quo(T x, T y, T &quot, T &rem) {
2426
quot = x / y;
2527
rem = x % y;

libc/src/string/memmem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ namespace LIBC_NAMESPACE {
1515
LLVM_LIBC_FUNCTION(void *, memmem,
1616
(const void *haystack, size_t haystack_len,
1717
const void *needle, size_t needle_len)) {
18-
constexpr auto comp = [](unsigned char l, unsigned char r) -> int {
18+
constexpr auto COMP = [](unsigned char l, unsigned char r) -> int {
1919
return l - r;
2020
};
21-
return inline_memmem(haystack, haystack_len, needle, needle_len, comp);
21+
return inline_memmem(haystack, haystack_len, needle, needle_len, COMP);
2222
}
2323

2424
} // namespace LIBC_NAMESPACE

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ libc_support_library(
205205
libc_support_library(
206206
name = "__support_cpp_limits",
207207
hdrs = ["src/__support/CPP/limits.h"],
208+
deps = [
209+
"__support_macros_attributes",
210+
],
208211
)
209212

210213
libc_support_library(
@@ -672,6 +675,7 @@ libc_support_library(
672675
name = "__support_fputil_float_properties",
673676
hdrs = ["src/__support/FPUtil/FloatProperties.h"],
674677
deps = [
678+
":__support_macros_attributes",
675679
":__support_macros_properties_float",
676680
":__support_uint128",
677681
],
@@ -687,6 +691,7 @@ libc_support_library(
687691
":__support_cpp_bit",
688692
":__support_cpp_type_traits",
689693
":__support_fputil_float_properties",
694+
":__support_macros_attributes",
690695
":__support_uint128",
691696
],
692697
)
@@ -746,6 +751,7 @@ libc_support_library(
746751
":__support_fputil_fenv_impl",
747752
":__support_fputil_fp_bits",
748753
":__support_fputil_rounding_mode",
754+
":__support_macros_attributes",
749755
],
750756
)
751757

0 commit comments

Comments
 (0)