Skip to content

Commit 5ff3ff3

Browse files
authored
[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (llvm#98597)
This is a part of llvm#97655.
1 parent dd86604 commit 5ff3ff3

File tree

2,328 files changed

+7576
-4679
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,328 files changed

+7576
-4679
lines changed

libc/benchmarks/LibcDefaultImplementations.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include "LibcFunctionPrototypes.h"
2+
#include "src/__support/macros/config.h"
23
#include "llvm/ADT/ArrayRef.h"
34
#include <cstddef>
45

5-
namespace LIBC_NAMESPACE {
6+
namespace LIBC_NAMESPACE_DECL {
67

78
extern void *memcpy(void *__restrict, const void *__restrict, size_t);
89
extern void *memmove(void *, const void *, size_t);
@@ -11,7 +12,7 @@ extern void bzero(void *, size_t);
1112
extern int memcmp(const void *, const void *, size_t);
1213
extern int bcmp(const void *, const void *, size_t);
1314

14-
} // namespace LIBC_NAMESPACE
15+
} // namespace LIBC_NAMESPACE_DECL
1516

1617
// List of implementations to test.
1718

libc/benchmarks/LibcMemoryBenchmarkMain.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "LibcBenchmark.h"
1111
#include "LibcMemoryBenchmark.h"
1212
#include "MemorySizeDistributions.h"
13+
#include "src/__support/macros/config.h"
1314
#include "llvm/Support/CommandLine.h"
1415
#include "llvm/Support/ErrorHandling.h"
1516
#include "llvm/Support/FileSystem.h"
@@ -21,7 +22,7 @@
2122
#include <cstring>
2223
#include <unistd.h>
2324

24-
namespace LIBC_NAMESPACE {
25+
namespace LIBC_NAMESPACE_DECL {
2526

2627
extern void *memcpy(void *__restrict, const void *__restrict, size_t);
2728
extern void *memmove(void *, const void *, size_t);
@@ -30,7 +31,7 @@ extern void bzero(void *, size_t);
3031
extern int memcmp(const void *, const void *, size_t);
3132
extern int bcmp(const void *, const void *, size_t);
3233

33-
} // namespace LIBC_NAMESPACE
34+
} // namespace LIBC_NAMESPACE_DECL
3435

3536
namespace llvm {
3637
namespace libc_benchmarks {

libc/benchmarks/automemcpy/lib/CodeGen.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
// function at the end of the file.
3737

3838
#include "automemcpy/CodeGen.h"
39+
#include "src/__support/macros/config.h"
3940
#include <cassert>
4041
#include <llvm/ADT/STLExtras.h>
4142
#include <llvm/ADT/StringSet.h>
@@ -542,11 +543,11 @@ static void Serialize(raw_ostream &Stream,
542543
Stream << "using llvm::libc_benchmarks::MemmoveConfiguration;\n";
543544
Stream << "using llvm::libc_benchmarks::MemsetConfiguration;\n";
544545
Stream << "\n";
545-
Stream << "namespace LIBC_NAMESPACE {\n";
546+
Stream << "namespace LIBC_NAMESPACE_DECL {\n";
546547
Stream << "\n";
547548
codegen::functions::Serialize(Stream, Descriptors);
548549
Stream << "\n";
549-
Stream << "} // namespace LIBC_NAMESPACE\n";
550+
Stream << "} // namespace LIBC_NAMESPACE_DECL\n";
550551
Stream << "\n";
551552
Stream << "namespace llvm {\n";
552553
Stream << "namespace automemcpy {\n";

libc/benchmarks/automemcpy/unittests/CodeGenTest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "automemcpy/CodeGen.h"
1010
#include "automemcpy/RandomFunctionGenerator.h"
11+
#include "src/__support/macros/config.h"
1112
#include "gmock/gmock.h"
1213
#include "gtest/gtest.h"
1314
#include <optional>
@@ -63,7 +64,7 @@ using llvm::libc_benchmarks::MemcpyConfiguration;
6364
using llvm::libc_benchmarks::MemmoveConfiguration;
6465
using llvm::libc_benchmarks::MemsetConfiguration;
6566
66-
namespace LIBC_NAMESPACE {
67+
namespace LIBC_NAMESPACE_DECL {
6768
6869
static void memcpy_0xE00E29EE73994E2B(char *__restrict dst, const char *__restrict src, size_t size) {
6970
using namespace LIBC_NAMESPACE::x86;
@@ -134,7 +135,7 @@ static void bzero_0x475977492C218AD4(char * dst, size_t size) {
134135
return splat_set<Align<_32,Arg::Dst>::Then<Loop<_32>>>(dst, 0, size);
135136
}
136137
137-
} // namespace LIBC_NAMESPACE
138+
} // namespace LIBC_NAMESPACE_DECL
138139
139140
namespace llvm {
140141
namespace automemcpy {

libc/benchmarks/gpu/BenchmarkLogger.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
#include "src/__support/CPP/string_view.h"
44
#include "src/__support/OSUtil/io.h" // write_to_stderr
55
#include "src/__support/big_int.h" // is_big_int
6+
#include "src/__support/macros/config.h"
67
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_INT128
78
#include "src/__support/uint128.h"
89

910
#include <stdint.h>
1011

11-
namespace LIBC_NAMESPACE {
12+
namespace LIBC_NAMESPACE_DECL {
1213
namespace benchmarks {
1314

1415
// cpp::string_view specialization
@@ -94,4 +95,4 @@ template BenchmarkLogger &BenchmarkLogger::operator<< <UInt<320>>(UInt<320>);
9495
BenchmarkLogger log;
9596

9697
} // namespace benchmarks
97-
} // namespace LIBC_NAMESPACE
98+
} // namespace LIBC_NAMESPACE_DECL

libc/benchmarks/gpu/BenchmarkLogger.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#ifndef LLVM_LIBC_BENCHMARKS_GPU_BENCHMARKLOGGER_H
1010
#define LLVM_LIBC_BENCHMARKS_GPU_BENCHMARKLOGGER_H
1111

12-
namespace LIBC_NAMESPACE {
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
1315
namespace benchmarks {
1416

1517
// A class to log to standard output in the context of hermetic tests.
@@ -22,6 +24,6 @@ struct BenchmarkLogger {
2224
extern BenchmarkLogger log;
2325

2426
} // namespace benchmarks
25-
} // namespace LIBC_NAMESPACE
27+
} // namespace LIBC_NAMESPACE_DECL
2628

2729
#endif /* LLVM_LIBC_BENCHMARKS_GPU_BENCHMARKLOGGER_H */

libc/benchmarks/gpu/LibcGpuBenchmark.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
#include "src/__support/FPUtil/sqrt.h"
66
#include "src/__support/GPU/utils.h"
77
#include "src/__support/fixedvector.h"
8+
#include "src/__support/macros/config.h"
89
#include "src/time/gpu/time_utils.h"
910

10-
namespace LIBC_NAMESPACE {
11+
namespace LIBC_NAMESPACE_DECL {
1112
namespace benchmarks {
1213

1314
FixedVector<Benchmark *, 64> benchmarks;
@@ -135,4 +136,4 @@ BenchmarkResult benchmark(const BenchmarkOptions &options,
135136
};
136137

137138
} // namespace benchmarks
138-
} // namespace LIBC_NAMESPACE
139+
} // namespace LIBC_NAMESPACE_DECL

libc/benchmarks/gpu/LibcGpuBenchmark.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
#include "src/__support/CPP/functional.h"
77
#include "src/__support/CPP/limits.h"
88
#include "src/__support/CPP/string_view.h"
9+
#include "src/__support/macros/config.h"
910
#include "src/time/clock.h"
1011

1112
#include <stdint.h>
1213

13-
namespace LIBC_NAMESPACE {
14+
namespace LIBC_NAMESPACE_DECL {
1415

1516
namespace benchmarks {
1617

@@ -99,7 +100,7 @@ class Benchmark {
99100
const cpp::string_view get_name() const { return name; }
100101
};
101102
} // namespace benchmarks
102-
} // namespace LIBC_NAMESPACE
103+
} // namespace LIBC_NAMESPACE_DECL
103104

104105
#define BENCHMARK(SuiteName, TestName, Func) \
105106
LIBC_NAMESPACE::benchmarks::Benchmark SuiteName##_##TestName##_Instance( \

libc/benchmarks/gpu/timing/amdgpu/timing.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
else \
2626
asm("" ::"v"(VARIABLE))
2727

28-
namespace LIBC_NAMESPACE {
28+
namespace LIBC_NAMESPACE_DECL {
2929

3030
// Returns the overhead associated with calling the profiling region. This
3131
// allows us to substract the constant-time overhead from the latency to
@@ -107,6 +107,6 @@ template <typename F, typename T1, typename T2>
107107
return stop - start;
108108
}
109109

110-
} // namespace LIBC_NAMESPACE
110+
} // namespace LIBC_NAMESPACE_DECL
111111

112112
#endif // LLVM_LIBC_UTILS_GPU_TIMING_AMDGPU

libc/benchmarks/gpu/timing/nvptx/timing.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include <stdint.h>
1818

19-
namespace LIBC_NAMESPACE {
19+
namespace LIBC_NAMESPACE_DECL {
2020

2121
// Returns the overhead associated with calling the profiling region. This
2222
// allows us to substract the constant-time overhead from the latency to
@@ -94,6 +94,6 @@ static LIBC_INLINE uint64_t latency(F f, T1 t1, T2 t2) {
9494

9595
return stop - start;
9696
}
97-
} // namespace LIBC_NAMESPACE
97+
} // namespace LIBC_NAMESPACE_DECL
9898

9999
#endif // LLVM_LIBC_UTILS_GPU_TIMING_NVPTX

libc/cmake/modules/LLVMLibCObjectRules.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ function(create_object_library fq_target_name)
9393
endif()
9494
endif()
9595

96-
if(fq_deps_list)
97-
add_dependencies(${fq_target_name} ${fq_deps_list})
98-
# Add deps as link libraries to inherit interface compile and link options.
99-
target_link_libraries(${fq_target_name} PUBLIC ${fq_deps_list})
100-
endif()
96+
list(APPEND fq_deps_list libc.src.__support.macros.config)
97+
list(REMOVE_DUPLICATES fq_deps_list)
98+
add_dependencies(${fq_target_name} ${fq_deps_list})
99+
# Add deps as link libraries to inherit interface compile and link options.
100+
target_link_libraries(${fq_target_name} PUBLIC ${fq_deps_list})
101101

102102
set_target_properties(
103103
${fq_target_name}

libc/config/linux/app.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
#ifndef LLVM_LIBC_CONFIG_LINUX_APP_H
1010
#define LLVM_LIBC_CONFIG_LINUX_APP_H
1111

12+
#include "src/__support/macros/config.h"
1213
#include "src/__support/macros/properties/architectures.h"
1314

1415
#include <stdint.h>
1516

16-
namespace LIBC_NAMESPACE {
17+
namespace LIBC_NAMESPACE_DECL {
1718

1819
// Data structure to capture properties of the linux/ELF TLS image.
1920
struct TLSImage {
@@ -104,6 +105,6 @@ void cleanup_tls(uintptr_t tls_addr, uintptr_t tls_size);
104105
// Set the thread pointer for the current thread.
105106
bool set_thread_ptr(uintptr_t val);
106107

107-
} // namespace LIBC_NAMESPACE
108+
} // namespace LIBC_NAMESPACE_DECL
108109

109110
#endif // LLVM_LIBC_CONFIG_LINUX_APP_H

libc/docs/dev/clang_tidy_checks.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ implementation-in-namespace
3636
---------------------------
3737

3838
It is part of our implementation standards that all implementation pieces live
39-
under the ``LIBC_NAMESPACE`` namespace. This prevents pollution of the global
40-
namespace. Without a formal check to ensure this, an implementation might
41-
compile and pass unit tests, but not produce a usable libc function.
39+
under the ``LIBC_NAMESPACE_DECL`` namespace. This prevents pollution of the
40+
global namespace. Without a formal check to ensure this, an implementation
41+
might compile and pass unit tests, but not produce a usable libc function.
4242

4343
This check that ensures any function call resolves to a function within the
44-
``LIBC_NAMESPACE`` namespace.
44+
``LIBC_NAMESPACE_DECL`` namespace.
4545

4646
.. code-block:: c++
4747

4848
// Correct: implementation inside the correct namespace.
49-
namespace LIBC_NAMESPACE {
49+
namespace LIBC_NAMESPACE_DECL {
5050
void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}
5151
// Namespaces within LIBC_NAMESPACE namespace are allowed.
5252
namespace inner{
@@ -87,7 +87,7 @@ are always external and can be intercepted.
8787

8888
.. code-block:: c++
8989

90-
namespace LIBC_NAMESPACE {
90+
namespace LIBC_NAMESPACE_DECL {
9191

9292
// Allow calls with the fully qualified name.
9393
LIBC_NAMESPACE::strlen("hello");
@@ -104,4 +104,4 @@ are always external and can be intercepted.
104104
// Allow calling into specific global functions (explained above)
105105
::malloc(10);
106106

107-
} // namespace LIBC_NAMESPACE
107+
} // namespace LIBC_NAMESPACE_DECL

libc/fuzzing/__support/hashtable_fuzz.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
#include "include/llvm-libc-types/ENTRY.h"
1313
#include "src/__support/CPP/string_view.h"
1414
#include "src/__support/HashTable/table.h"
15+
#include "src/__support/macros/config.h"
1516

16-
namespace LIBC_NAMESPACE {
17+
namespace LIBC_NAMESPACE_DECL {
1718

1819
// A fuzzing payload starts with
1920
// - uint16_t: initial capacity for table A
@@ -179,4 +180,4 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
179180
return 0;
180181
}
181182

182-
} // namespace LIBC_NAMESPACE
183+
} // namespace LIBC_NAMESPACE_DECL

libc/src/__support/CPP/algorithm.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
#define LLVM_LIBC_SRC___SUPPORT_CPP_ALGORITHM_H
1414

1515
#include "src/__support/macros/attributes.h" // LIBC_INLINE
16+
#include "src/__support/macros/config.h"
1617

17-
namespace LIBC_NAMESPACE {
18+
namespace LIBC_NAMESPACE_DECL {
1819
namespace cpp {
1920

2021
template <class T> LIBC_INLINE constexpr const T &max(const T &a, const T &b) {
@@ -41,6 +42,6 @@ LIBC_INLINE constexpr bool all_of(InputIt first, InputIt last, UnaryPred p) {
4142
}
4243

4344
} // namespace cpp
44-
} // namespace LIBC_NAMESPACE
45+
} // namespace LIBC_NAMESPACE_DECL
4546

4647
#endif // LLVM_LIBC_SRC___SUPPORT_CPP_ALGORITHM_H

libc/src/__support/CPP/array.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
#include "src/__support/CPP/iterator.h" // reverse_iterator
1313
#include "src/__support/macros/attributes.h"
14+
#include "src/__support/macros/config.h"
1415
#include <stddef.h> // For size_t.
1516

16-
namespace LIBC_NAMESPACE {
17+
namespace LIBC_NAMESPACE_DECL {
1718
namespace cpp {
1819

1920
template <class T, size_t N> struct array {
@@ -74,6 +75,6 @@ template <class T, size_t N> struct array {
7475
};
7576

7677
} // namespace cpp
77-
} // namespace LIBC_NAMESPACE
78+
} // namespace LIBC_NAMESPACE_DECL
7879

7980
#endif // LLVM_LIBC_SRC___SUPPORT_CPP_ARRAY_H

libc/src/__support/CPP/atomic.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
#define LLVM_LIBC_SRC___SUPPORT_CPP_ATOMIC_H
1111

1212
#include "src/__support/macros/attributes.h"
13+
#include "src/__support/macros/config.h"
1314
#include "src/__support/macros/properties/architectures.h"
1415

1516
#include "type_traits.h"
1617

17-
namespace LIBC_NAMESPACE {
18+
namespace LIBC_NAMESPACE_DECL {
1819
namespace cpp {
1920

2021
enum class MemoryOrder : int {
@@ -211,6 +212,6 @@ LIBC_INLINE void atomic_signal_fence([[maybe_unused]] MemoryOrder mem_ord) {
211212
}
212213

213214
} // namespace cpp
214-
} // namespace LIBC_NAMESPACE
215+
} // namespace LIBC_NAMESPACE_DECL
215216

216217
#endif // LLVM_LIBC_SRC___SUPPORT_CPP_ATOMIC_H

libc/src/__support/CPP/bit.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
#include "src/__support/CPP/limits.h" // numeric_limits
1515
#include "src/__support/CPP/type_traits.h"
1616
#include "src/__support/macros/attributes.h"
17+
#include "src/__support/macros/config.h"
1718
#include "src/__support/macros/sanitizer.h"
1819

1920
#include <stdint.h>
2021

21-
namespace LIBC_NAMESPACE::cpp {
22+
namespace LIBC_NAMESPACE_DECL {
23+
namespace cpp {
2224

2325
#if __has_builtin(__builtin_memcpy_inline)
2426
#define LLVM_LIBC_HAS_BUILTIN_MEMCPY_INLINE
@@ -290,6 +292,7 @@ ADD_SPECIALIZATION(unsigned long long, __builtin_popcountll)
290292
#endif // __builtin_popcountg
291293
#undef ADD_SPECIALIZATION
292294

293-
} // namespace LIBC_NAMESPACE::cpp
295+
} // namespace cpp
296+
} // namespace LIBC_NAMESPACE_DECL
294297

295298
#endif // LLVM_LIBC_SRC___SUPPORT_CPP_BIT_H

0 commit comments

Comments
 (0)