Skip to content

Commit 019a477

Browse files
committed
[libc] Clean up required LIBC_INLINE uses in src/string
This was generated using clang-tidy and clang-apply-replacements, on src/string/*.cpp for just the llvmlibc-inline-function-decl check, after applying https://reviews.llvm.org/D157164, and then some manual fixup. Reviewed By: abrachet Differential Revision: https://reviews.llvm.org/D157169
1 parent 9d4162f commit 019a477

File tree

14 files changed

+107
-76
lines changed

14 files changed

+107
-76
lines changed

libc/src/__support/CPP/array.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_ARRAY_H
1010
#define LLVM_LIBC_SRC_SUPPORT_CPP_ARRAY_H
1111

12+
#include "src/__support/macros/attributes.h"
1213
#include <stddef.h> // For size_t.
1314

1415
namespace __llvm_libc {
@@ -22,28 +23,30 @@ template <class T, size_t N> struct array {
2223
using iterator = T *;
2324
using const_iterator = const T *;
2425

25-
constexpr T *data() { return Data; }
26-
constexpr const T *data() const { return Data; }
26+
LIBC_INLINE constexpr T *data() { return Data; }
27+
LIBC_INLINE constexpr const T *data() const { return Data; }
2728

28-
constexpr T &front() { return Data[0]; }
29-
constexpr T &front() const { return Data[0]; }
29+
LIBC_INLINE constexpr T &front() { return Data[0]; }
30+
LIBC_INLINE constexpr T &front() const { return Data[0]; }
3031

31-
constexpr T &back() { return Data[N - 1]; }
32-
constexpr T &back() const { return Data[N - 1]; }
32+
LIBC_INLINE constexpr T &back() { return Data[N - 1]; }
33+
LIBC_INLINE constexpr T &back() const { return Data[N - 1]; }
3334

34-
constexpr T &operator[](size_t Index) { return Data[Index]; }
35+
LIBC_INLINE constexpr T &operator[](size_t Index) { return Data[Index]; }
3536

36-
constexpr const T &operator[](size_t Index) const { return Data[Index]; }
37+
LIBC_INLINE constexpr const T &operator[](size_t Index) const {
38+
return Data[Index];
39+
}
3740

38-
constexpr size_t size() const { return N; }
41+
LIBC_INLINE constexpr size_t size() const { return N; }
3942

40-
constexpr bool empty() const { return N == 0; }
43+
LIBC_INLINE constexpr bool empty() const { return N == 0; }
4144

42-
constexpr iterator begin() { return Data; }
43-
constexpr const_iterator begin() const { return Data; }
45+
LIBC_INLINE constexpr iterator begin() { return Data; }
46+
LIBC_INLINE constexpr const_iterator begin() const { return Data; }
4447

45-
constexpr iterator end() { return Data + N; }
46-
const_iterator end() const { return Data + N; }
48+
LIBC_INLINE constexpr iterator end() { return Data + N; }
49+
LIBC_INLINE const_iterator end() const { return Data + N; }
4750
};
4851

4952
} // namespace cpp

libc/src/__support/CPP/bit.h

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

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

1516
namespace __llvm_libc::cpp {
@@ -24,7 +25,8 @@ namespace __llvm_libc::cpp {
2425

2526
// This function guarantees the bitcast to be optimized away by the compiler for
2627
// GCC >= 8 and Clang >= 6.
27-
template <class To, class From> constexpr To bit_cast(const From &from) {
28+
template <class To, class From>
29+
LIBC_INLINE constexpr To bit_cast(const From &from) {
2830
static_assert(sizeof(To) == sizeof(From), "To and From must be of same size");
2931
static_assert(cpp::is_trivially_copyable<To>::value &&
3032
cpp::is_trivially_copyable<From>::value,

libc/src/__support/CPP/bitset.h

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

12+
#include "src/__support/macros/attributes.h"
1213
#include <stddef.h> // For size_t.
1314

1415
namespace __llvm_libc::cpp {
@@ -17,27 +18,27 @@ template <size_t NumberOfBits> struct bitset {
1718
static_assert(NumberOfBits != 0,
1819
"Cannot create a __llvm_libc::cpp::bitset of size 0.");
1920

20-
constexpr void set(size_t Index) {
21+
LIBC_INLINE constexpr void set(size_t Index) {
2122
Data[Index / BITS_PER_UNIT] |= mask(Index);
2223
}
2324

24-
constexpr void reset() {
25+
LIBC_INLINE constexpr void reset() {
2526
for (size_t i = 0; i < NUMBER_OF_UNITS; ++i)
2627
Data[i] = 0;
2728
}
2829

29-
constexpr bool test(size_t Index) const {
30+
LIBC_INLINE constexpr bool test(size_t Index) const {
3031
return Data[Index / BITS_PER_UNIT] & mask(Index);
3132
}
3233

33-
constexpr void flip() {
34+
LIBC_INLINE constexpr void flip() {
3435
for (size_t i = 0; i < NUMBER_OF_UNITS; ++i)
3536
Data[i] = ~Data[i];
3637
}
3738

3839
// This function sets all bits in the range from Start to End (inclusive) to
3940
// true. It assumes that Start <= End.
40-
constexpr void set_range(size_t Start, size_t End) {
41+
LIBC_INLINE constexpr void set_range(size_t Start, size_t End) {
4142
size_t start_index = Start / BITS_PER_UNIT;
4243
size_t end_index = End / BITS_PER_UNIT;
4344

@@ -64,7 +65,7 @@ template <size_t NumberOfBits> struct bitset {
6465
}
6566
}
6667

67-
constexpr bool operator==(const bitset<NumberOfBits> &other) {
68+
LIBC_INLINE constexpr bool operator==(const bitset<NumberOfBits> &other) {
6869
for (size_t i = 0; i < NUMBER_OF_UNITS; ++i) {
6970
if (Data[i] != other.Data[i])
7071
return false;
@@ -78,7 +79,7 @@ template <size_t NumberOfBits> struct bitset {
7879
static constexpr size_t NUMBER_OF_UNITS =
7980
(NumberOfBits + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
8081

81-
static constexpr size_t mask(size_t Index) {
82+
LIBC_INLINE static constexpr size_t mask(size_t Index) {
8283
return size_t{1} << (Index % BITS_PER_UNIT);
8384
}
8485
size_t Data[NUMBER_OF_UNITS] = {0};

libc/src/__support/CPP/cstddef.h

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,59 @@
99
#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_BYTE_H
1010
#define LLVM_LIBC_SRC_SUPPORT_CPP_BYTE_H
1111

12+
#include "src/__support/macros/attributes.h"
1213
#include "type_traits.h" // For enable_if_t, is_integral_v.
1314

1415
namespace __llvm_libc::cpp {
1516

1617
enum class byte : unsigned char {};
1718

1819
template <class IntegerType>
19-
constexpr enable_if_t<is_integral_v<IntegerType>, byte>
20+
LIBC_INLINE constexpr enable_if_t<is_integral_v<IntegerType>, byte>
2021
operator>>(byte b, IntegerType shift) noexcept {
2122
return static_cast<byte>(static_cast<unsigned char>(b) >> shift);
2223
}
2324
template <class IntegerType>
24-
constexpr enable_if_t<is_integral_v<IntegerType>, byte &>
25+
LIBC_INLINE constexpr enable_if_t<is_integral_v<IntegerType>, byte &>
2526
operator>>=(byte &b, IntegerType shift) noexcept {
2627
return b = b >> shift;
2728
}
2829
template <class IntegerType>
29-
constexpr enable_if_t<is_integral_v<IntegerType>, byte>
30+
LIBC_INLINE constexpr enable_if_t<is_integral_v<IntegerType>, byte>
3031
operator<<(byte b, IntegerType shift) noexcept {
3132
return static_cast<byte>(static_cast<unsigned char>(b) << shift);
3233
}
3334
template <class IntegerType>
34-
constexpr enable_if_t<is_integral_v<IntegerType>, byte &>
35+
LIBC_INLINE constexpr enable_if_t<is_integral_v<IntegerType>, byte &>
3536
operator<<=(byte &b, IntegerType shift) noexcept {
3637
return b = b << shift;
3738
}
38-
constexpr byte operator|(byte l, byte r) noexcept {
39+
LIBC_INLINE constexpr byte operator|(byte l, byte r) noexcept {
3940
return static_cast<byte>(static_cast<unsigned char>(l) |
4041
static_cast<unsigned char>(r));
4142
}
42-
constexpr byte &operator|=(byte &l, byte r) noexcept { return l = l | r; }
43-
constexpr byte operator&(byte l, byte r) noexcept {
43+
LIBC_INLINE constexpr byte &operator|=(byte &l, byte r) noexcept {
44+
return l = l | r;
45+
}
46+
LIBC_INLINE constexpr byte operator&(byte l, byte r) noexcept {
4447
return static_cast<byte>(static_cast<unsigned char>(l) &
4548
static_cast<unsigned char>(r));
4649
}
47-
constexpr byte &operator&=(byte &l, byte r) noexcept { return l = l & r; }
48-
constexpr byte operator^(byte l, byte r) noexcept {
50+
LIBC_INLINE constexpr byte &operator&=(byte &l, byte r) noexcept {
51+
return l = l & r;
52+
}
53+
LIBC_INLINE constexpr byte operator^(byte l, byte r) noexcept {
4954
return static_cast<byte>(static_cast<unsigned char>(l) ^
5055
static_cast<unsigned char>(r));
5156
}
52-
constexpr byte &operator^=(byte &l, byte r) noexcept { return l = l ^ r; }
53-
constexpr byte operator~(byte b) noexcept {
57+
LIBC_INLINE constexpr byte &operator^=(byte &l, byte r) noexcept {
58+
return l = l ^ r;
59+
}
60+
LIBC_INLINE constexpr byte operator~(byte b) noexcept {
5461
return static_cast<byte>(~static_cast<unsigned char>(b));
5562
}
5663
template <typename IntegerType>
57-
constexpr enable_if_t<is_integral_v<IntegerType>, IntegerType>
64+
LIBC_INLINE constexpr enable_if_t<is_integral_v<IntegerType>, IntegerType>
5865
to_integer(byte b) noexcept {
5966
return static_cast<IntegerType>(b);
6067
}

libc/src/__support/CPP/new.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ namespace __llvm_libc {
2727

2828
class AllocChecker {
2929
bool success = false;
30-
AllocChecker &operator=(bool status) {
30+
31+
LIBC_INLINE AllocChecker &operator=(bool status) {
3132
success = status;
3233
return *this;
3334
}
3435

3536
public:
36-
AllocChecker() = default;
37-
operator bool() const { return success; }
37+
LIBC_INLINE AllocChecker() = default;
38+
39+
LIBC_INLINE operator bool() const { return success; }
3840

3941
LIBC_INLINE static void *alloc(size_t s, AllocChecker &ac) {
4042
void *mem = ::malloc(s);

libc/src/__support/CPP/optional.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ namespace cpp {
1818

1919
// Trivial in_place_t struct.
2020
struct in_place_t {
21-
LIBC_INLINE_VAR explicit in_place_t() = default;
21+
LIBC_INLINE constexpr explicit in_place_t() = default;
2222
};
2323

2424
// Trivial nullopt_t struct.
2525
struct nullopt_t {
26-
LIBC_INLINE_VAR explicit nullopt_t() = default;
26+
LIBC_INLINE constexpr explicit nullopt_t() = default;
2727
};
2828

2929
// nullopt that can be used and returned.

libc/src/__support/CPP/span.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ template <typename T> class span {
4646
using const_reference = const T &;
4747
using iterator = T *;
4848

49-
static constexpr size_type dynamic_extent = -1;
49+
LIBC_INLINE_VAR static constexpr size_type dynamic_extent = -1;
5050

5151
LIBC_INLINE constexpr span() : span_data(nullptr), span_size(0) {}
5252

libc/src/__support/CPP/string_view.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class string_view {
2626
const char *Data;
2727
size_t Len;
2828

29-
static size_t min(size_t A, size_t B) { return A <= B ? A : B; }
29+
LIBC_INLINE static size_t min(size_t A, size_t B) { return A <= B ? A : B; }
3030

3131
LIBC_INLINE static int compareMemory(const char *Lhs, const char *Rhs,
3232
size_t Length) {

libc/src/__support/CPP/type_traits.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ template <typename T> struct remove_cvref {
6868
template <typename T> using remove_cvref_t = typename remove_cvref<T>::type;
6969

7070
namespace details {
71-
template <typename T, typename... Args> constexpr bool is_unqualified_any_of() {
71+
template <typename T, typename... Args>
72+
LIBC_INLINE constexpr bool is_unqualified_any_of() {
7273
return (... || is_same_v<remove_cv_t<T>, Args>);
7374
}
7475
} // namespace details

libc/src/__support/common.h

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

4040
namespace __llvm_libc {
4141
namespace internal {
42-
constexpr bool same_string(char const *lhs, char const *rhs) {
42+
LIBC_INLINE constexpr bool same_string(char const *lhs, char const *rhs) {
4343
for (; *lhs || *rhs; ++lhs, ++rhs)
4444
if (*lhs != *rhs)
4545
return false;

libc/src/__support/ctype_utils.h

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

12+
#include "src/__support/macros/attributes.h"
13+
1214
namespace __llvm_libc {
1315
namespace internal {
1416

@@ -18,25 +20,35 @@ namespace internal {
1820
// of a function call by inlining them.
1921
// ------------------------------------------------------
2022

21-
static constexpr bool isalpha(unsigned ch) { return (ch | 32) - 'a' < 26; }
23+
LIBC_INLINE static constexpr bool isalpha(unsigned ch) {
24+
return (ch | 32) - 'a' < 26;
25+
}
2226

23-
static constexpr bool isdigit(unsigned ch) { return (ch - '0') < 10; }
27+
LIBC_INLINE static constexpr bool isdigit(unsigned ch) {
28+
return (ch - '0') < 10;
29+
}
2430

25-
static constexpr bool isalnum(unsigned ch) {
31+
LIBC_INLINE static constexpr bool isalnum(unsigned ch) {
2632
return isalpha(ch) || isdigit(ch);
2733
}
2834

29-
static constexpr bool isgraph(unsigned ch) { return 0x20 < ch && ch < 0x7f; }
35+
LIBC_INLINE static constexpr bool isgraph(unsigned ch) {
36+
return 0x20 < ch && ch < 0x7f;
37+
}
3038

31-
static constexpr bool islower(unsigned ch) { return (ch - 'a') < 26; }
39+
LIBC_INLINE static constexpr bool islower(unsigned ch) {
40+
return (ch - 'a') < 26;
41+
}
3242

33-
static constexpr bool isupper(unsigned ch) { return (ch - 'A') < 26; }
43+
LIBC_INLINE static constexpr bool isupper(unsigned ch) {
44+
return (ch - 'A') < 26;
45+
}
3446

35-
static constexpr bool isspace(unsigned ch) {
47+
LIBC_INLINE static constexpr bool isspace(unsigned ch) {
3648
return ch == ' ' || (ch - '\t') < 5;
3749
}
3850

39-
static constexpr int tolower(int ch) {
51+
LIBC_INLINE static constexpr int tolower(int ch) {
4052
if (isupper(ch))
4153
return ch + ('a' - 'A');
4254
return ch;

libc/src/string/memory_utils/inline_memmem.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMMEM_H
1010
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMMEM_H
1111

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

1416
namespace __llvm_libc {
1517

1618
template <typename Comp>
17-
constexpr static void *inline_memmem(const void *haystack, size_t haystack_len,
18-
const void *needle, size_t needle_len,
19-
Comp &&comp) {
19+
LIBC_INLINE constexpr static void *
20+
inline_memmem(const void *haystack, size_t haystack_len, const void *needle,
21+
size_t needle_len, Comp &&comp) {
2022
// TODO: simple brute force implementation. This can be
2123
// improved upon using well known string matching algorithms.
2224
if (!needle_len)

0 commit comments

Comments
 (0)