From: Guillaume Chatelet Date: Fri, 29 Jul 2022 13:40:08 +0000 (+0000) Subject: [libc][NFC] Use STL case for array X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7add0e5fdc5c7cb6f59f60cd436bf161cf9f9eb7;p=platform%2Fupstream%2Fllvm.git [libc][NFC] Use STL case for array Migrating all private STL code to the standard STL case but keeping it under the CPP namespace to avoid confusion. Differential Revision: https://reviews.llvm.org/D130773 --- diff --git a/libc/src/__support/CPP/ArrayRef.h b/libc/src/__support/CPP/ArrayRef.h index 1219963..157e315 100644 --- a/libc/src/__support/CPP/ArrayRef.h +++ b/libc/src/__support/CPP/ArrayRef.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_CPP_ARRAYREF_H #define LLVM_LIBC_SRC_SUPPORT_CPP_ARRAYREF_H -#include "Array.h" +#include "array.h" #include "type_traits.h" // RemoveCVType #include // For size_t. @@ -120,8 +120,8 @@ public: ArrayRef(const void *Data, size_t Length) : Impl(reinterpret_cast(Data), Length / sizeof(T)) {} - // From Array. - template ArrayRef(const Array &Arr) : Impl(Arr.Data, N) {} + // From array. + template ArrayRef(const array &Arr) : Impl(Arr.Data, N) {} }; template @@ -139,8 +139,8 @@ public: MutableArrayRef(void *Data, size_t Length) : Impl(reinterpret_cast(Data), Length / sizeof(T)) {} - // From Array. - template MutableArrayRef(Array &Arr) : Impl(Arr.Data, N) {} + // From array. + template MutableArrayRef(array &Arr) : Impl(Arr.Data, N) {} operator ArrayRef() const { return ArrayRef(this->data(), this->size()); diff --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt index 12cf729..d9126b1 100644 --- a/libc/src/__support/CPP/CMakeLists.txt +++ b/libc/src/__support/CPP/CMakeLists.txt @@ -1,7 +1,7 @@ add_header_library( array HDRS - Array.h + array.h ) add_header_library( diff --git a/libc/src/__support/CPP/UInt.h b/libc/src/__support/CPP/UInt.h index 045950b..dd15635 100644 --- a/libc/src/__support/CPP/UInt.h +++ b/libc/src/__support/CPP/UInt.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_UTILS_CPP_UINT_H #define LLVM_LIBC_UTILS_CPP_UINT_H -#include "Array.h" +#include "array.h" #include // For size_t #include @@ -44,7 +44,7 @@ public: val[i] = 0; } } - constexpr explicit UInt(const cpp::Array &words) { + constexpr explicit UInt(const cpp::array &words) { for (size_t i = 0; i < WordCount; ++i) val[i] = words[i]; } @@ -104,7 +104,7 @@ public: uint64_t x_lo = low(x); uint64_t x_hi = high(x); - cpp::Array row1; + cpp::array row1; uint64_t carry = 0; for (size_t i = 0; i < WordCount; ++i) { uint64_t l = low(val[i]); @@ -123,7 +123,7 @@ public: } row1[WordCount] = carry; - cpp::Array row2; + cpp::array row2; row2[0] = 0; carry = 0; for (size_t i = 0; i < WordCount; ++i) { diff --git a/libc/src/__support/CPP/Array.h b/libc/src/__support/CPP/array.h similarity index 93% rename from libc/src/__support/CPP/Array.h rename to libc/src/__support/CPP/array.h index e198943..97db026 100644 --- a/libc/src/__support/CPP/Array.h +++ b/libc/src/__support/CPP/array.h @@ -14,8 +14,8 @@ namespace __llvm_libc { namespace cpp { -template struct Array { - static_assert(N != 0, "Cannot create a __llvm_libc::cpp::Array of size 0."); +template struct array { + static_assert(N != 0, "Cannot create a __llvm_libc::cpp::array of size 0."); T Data[N]; diff --git a/libc/test/src/__support/CPP/arrayref_test.cpp b/libc/test/src/__support/CPP/arrayref_test.cpp index 7cdff32..edb545a 100644 --- a/libc/test/src/__support/CPP/arrayref_test.cpp +++ b/libc/test/src/__support/CPP/arrayref_test.cpp @@ -65,7 +65,7 @@ TYPED_TEST(LlvmLibcArrayRefTest, ConstructFromCArray, Types) { TYPED_TEST(LlvmLibcArrayRefTest, ConstructFromLibcArray, Types) { using value_type = typename ParamType::value_type; using const_pointer = typename ParamType::const_pointer; - Array values = {1, 2}; + array values = {1, 2}; ParamType arrayref(values); EXPECT_FALSE(arrayref.empty()); EXPECT_EQ(arrayref.size(), size_t(2)); diff --git a/libc/test/src/math/cosf_test.cpp b/libc/test/src/math/cosf_test.cpp index c7315e8..48b58b9 100644 --- a/libc/test/src/math/cosf_test.cpp +++ b/libc/test/src/math/cosf_test.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/CPP/Array.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/cosf.h" #include "test/src/math/sdcomp26094.h" diff --git a/libc/test/src/math/sdcomp26094.h b/libc/test/src/math/sdcomp26094.h index 3162884..284578b 100644 --- a/libc/test/src/math/sdcomp26094.h +++ b/libc/test/src/math/sdcomp26094.h @@ -9,14 +9,14 @@ #ifndef LLVM_LIBC_TEST_SRC_MATH_SDCOMP26094_H #define LLVM_LIBC_TEST_SRC_MATH_SDCOMP26094_H -#include "src/__support/CPP/Array.h" +#include "src/__support/CPP/array.h" #include namespace __llvm_libc { namespace testing { -static constexpr __llvm_libc::cpp::Array SDCOMP26094_VALUES{ +static constexpr __llvm_libc::cpp::array SDCOMP26094_VALUES{ 0x46427f1b, 0x4647e568, 0x46428bac, 0x4647f1f9, 0x4647fe8a, 0x45d8d7f1, 0x45d371a4, 0x45ce0b57, 0x45d35882, 0x45cdf235, }; diff --git a/libc/test/src/math/sincosf_test.cpp b/libc/test/src/math/sincosf_test.cpp index dfd86eb..f23d719 100644 --- a/libc/test/src/math/sincosf_test.cpp +++ b/libc/test/src/math/sincosf_test.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/CPP/Array.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/sincosf.h" #include "test/src/math/sdcomp26094.h" diff --git a/libc/test/src/math/sinf_test.cpp b/libc/test/src/math/sinf_test.cpp index 40dcc4d..7defafa 100644 --- a/libc/test/src/math/sinf_test.cpp +++ b/libc/test/src/math/sinf_test.cpp @@ -6,7 +6,6 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/CPP/Array.h" #include "src/__support/FPUtil/FPBits.h" #include "src/math/sinf.h" #include "test/src/math/sdcomp26094.h" diff --git a/libc/test/src/stdlib/atexit_test.cpp b/libc/test/src/stdlib/atexit_test.cpp index 877222f..11ab2fa 100644 --- a/libc/test/src/stdlib/atexit_test.cpp +++ b/libc/test/src/stdlib/atexit_test.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/CPP/Array.h" #include "src/__support/CPP/Utility.h" +#include "src/__support/CPP/array.h" #include "src/stdlib/atexit.h" #include "src/stdlib/exit.h" #include "utils/UnitTest/Test.h" @@ -40,7 +40,7 @@ TEST(LlvmLibcAtExit, AtExitCallsSysExit) { } static int size; -static __llvm_libc::cpp::Array arr; +static __llvm_libc::cpp::array arr; template void register_atexit_handlers(__llvm_libc::cpp::IntegerSequence) { diff --git a/libc/test/src/string/bzero_test.cpp b/libc/test/src/string/bzero_test.cpp index f8edfa5..beecf48 100644 --- a/libc/test/src/string/bzero_test.cpp +++ b/libc/test/src/string/bzero_test.cpp @@ -10,9 +10,9 @@ #include "src/string/bzero.h" #include "utils/UnitTest/Test.h" -using __llvm_libc::cpp::Array; +using __llvm_libc::cpp::array; using __llvm_libc::cpp::ArrayRef; -using Data = Array; +using Data = array; static const ArrayRef k_deadcode("DEADC0DE", 8); diff --git a/libc/test/src/string/memcpy_test.cpp b/libc/test/src/string/memcpy_test.cpp index ed4bbd4..875927b 100644 --- a/libc/test/src/string/memcpy_test.cpp +++ b/libc/test/src/string/memcpy_test.cpp @@ -10,9 +10,9 @@ #include "src/string/memcpy.h" #include "utils/UnitTest/Test.h" -using __llvm_libc::cpp::Array; +using __llvm_libc::cpp::array; using __llvm_libc::cpp::ArrayRef; -using Data = Array; +using Data = array; static const ArrayRef k_numbers("0123456789", 10); static const ArrayRef k_deadcode("DEADC0DE", 8); diff --git a/libc/test/src/string/memmove_test.cpp b/libc/test/src/string/memmove_test.cpp index cacd2bf..0b753cd 100644 --- a/libc/test/src/string/memmove_test.cpp +++ b/libc/test/src/string/memmove_test.cpp @@ -11,7 +11,7 @@ #include "utils/UnitTest/MemoryMatcher.h" #include "utils/UnitTest/Test.h" -using __llvm_libc::cpp::Array; +using __llvm_libc::cpp::array; using __llvm_libc::cpp::ArrayRef; using __llvm_libc::cpp::MutableArrayRef; @@ -92,7 +92,7 @@ void Randomize(MutableArrayRef Buffer) { } TEST(LlvmLibcMemmoveTest, Thorough) { - using LargeBuffer = Array; + using LargeBuffer = array; LargeBuffer GroundTruth; Randomize(GroundTruth); for (int Size = 0; Size < kMaxSize; ++Size) { diff --git a/libc/test/src/string/memory_utils/algorithm_test.cpp b/libc/test/src/string/memory_utils/algorithm_test.cpp index 3c6303a..d973fbc 100644 --- a/libc/test/src/string/memory_utils/algorithm_test.cpp +++ b/libc/test/src/string/memory_utils/algorithm_test.cpp @@ -2,7 +2,7 @@ #define LLVM_LIBC_USE_BUILTIN_MEMSET_INLINE 0 #include "utils/UnitTest/Test.h" -#include +#include #include #include @@ -10,7 +10,7 @@ namespace __llvm_libc { -struct alignas(64) Buffer : cpp::Array { +struct alignas(64) Buffer : cpp::array { bool contains(const char *ptr) const { return ptr >= data() && ptr < (data() + size()); } diff --git a/libc/test/src/string/memory_utils/backend_test.cpp b/libc/test/src/string/memory_utils/backend_test.cpp index f4ffe9c..2ce0d17 100644 --- a/libc/test/src/string/memory_utils/backend_test.cpp +++ b/libc/test/src/string/memory_utils/backend_test.cpp @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/CPP/Array.h" #include "src/__support/CPP/ArrayRef.h" #include "src/__support/CPP/Bit.h" +#include "src/__support/CPP/array.h" #include "src/__support/architectures.h" #include "src/string/memory_utils/backends.h" #include "utils/UnitTest/Test.h" @@ -16,7 +16,7 @@ namespace __llvm_libc { -template using Buffer = cpp::Array; +template using Buffer = cpp::array; static char GetRandomChar() { // Implementation of C++ minstd_rand seeded with 123456789. @@ -84,7 +84,7 @@ using FunctionTypes = testing::TypeList< // >; TYPED_TEST(LlvmLibcMemoryBackend, splat, FunctionTypes) { - for (auto value : cpp::Array{0u, 1u, 255u}) { + for (auto value : cpp::array{0u, 1u, 255u}) { alignas(64) const auto stored = ParamType::splat(bit_cast(value)); for (size_t i = 0; i < ParamType::SIZE; ++i) EXPECT_EQ(bit_cast(stored[i]), value); diff --git a/libc/test/src/string/memory_utils/elements_test.cpp b/libc/test/src/string/memory_utils/elements_test.cpp index ce9a67d..ef43475 100644 --- a/libc/test/src/string/memory_utils/elements_test.cpp +++ b/libc/test/src/string/memory_utils/elements_test.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/CPP/Array.h" #include "src/__support/CPP/ArrayRef.h" +#include "src/__support/CPP/array.h" #include "src/string/memory_utils/elements.h" #include "utils/UnitTest/Test.h" @@ -56,7 +56,7 @@ void Randomize(cpp::MutableArrayRef buffer) { current = GetRandomChar(); } -template using Buffer = cpp::Array; +template using Buffer = cpp::array; template Buffer GetRandomBuffer() { Buffer buffer; @@ -81,7 +81,7 @@ template T copy(const T &Input) { TYPED_TEST(LlvmLibcMemoryElements, Move, FixedSizeTypes) { constexpr size_t SIZE = ParamType::SIZE; - using LargeBuffer = cpp::Array; + using LargeBuffer = cpp::array; LargeBuffer GroundTruth; Randomize(GroundTruth); // Forward, we move the SIZE first bytes from offset 0 to SIZE. @@ -126,7 +126,7 @@ TYPED_TEST(LlvmLibcMemoryElements, three_way_compare, FixedSizeTypes) { TYPED_TEST(LlvmLibcMemoryElements, Splat, FixedSizeTypes) { Buffer Dst; - const cpp::Array values = {char(0x00), char(0x7F), char(0xFF)}; + const cpp::array values = {char(0x00), char(0x7F), char(0xFF)}; for (char value : values) { splat_set(Dst.data(), value); for (size_t i = 0; i < ParamType::SIZE; ++i) diff --git a/libc/test/src/string/memory_utils/memory_access_test.cpp b/libc/test/src/string/memory_utils/memory_access_test.cpp index e107d6f..fe257bd 100644 --- a/libc/test/src/string/memory_utils/memory_access_test.cpp +++ b/libc/test/src/string/memory_utils/memory_access_test.cpp @@ -8,8 +8,8 @@ #define LLVM_LIBC_UNITTEST_OBSERVE 1 -#include "src/__support/CPP/Array.h" #include "src/__support/CPP/ArrayRef.h" +#include "src/__support/CPP/array.h" #include "src/string/memory_utils/elements.h" #include "utils/UnitTest/Test.h" @@ -20,7 +20,7 @@ namespace __llvm_libc { static constexpr const size_t kMaxBuffer = 32; -struct BufferAccess : cpp::Array { +struct BufferAccess : cpp::array { BufferAccess() { Reset(); } void Reset() { for (auto &value : *this) @@ -45,7 +45,7 @@ struct Buffer { reads.Reset(); writes.Reset(); } - cpp::Array data; + cpp::array data; BufferAccess __attribute__((aligned(64))) reads; BufferAccess __attribute__((aligned(64))) writes; }; diff --git a/libc/test/src/string/memory_utils/utils_test.cpp b/libc/test/src/string/memory_utils/utils_test.cpp index 6b9ece4..f76d3a7 100644 --- a/libc/test/src/string/memory_utils/utils_test.cpp +++ b/libc/test/src/string/memory_utils/utils_test.cpp @@ -6,14 +6,14 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/CPP/Array.h" +#include "src/__support/CPP/array.h" #include "src/string/memory_utils/utils.h" #include "utils/UnitTest/Test.h" namespace __llvm_libc { TEST(LlvmLibcUtilsTest, IsPowerOfTwoOrZero) { - static const cpp::Array kExpectedValues{ + static const cpp::array kExpectedValues{ 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 0-15 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16-31 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 32-47 @@ -25,7 +25,7 @@ TEST(LlvmLibcUtilsTest, IsPowerOfTwoOrZero) { } TEST(LlvmLibcUtilsTest, IsPowerOfTwo) { - static const cpp::Array kExpectedValues{ + static const cpp::array kExpectedValues{ 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 0-15 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16-31 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 32-47 @@ -37,7 +37,7 @@ TEST(LlvmLibcUtilsTest, IsPowerOfTwo) { } TEST(LlvmLibcUtilsTest, Log2) { - static const cpp::Array kExpectedValues{ + static const cpp::array kExpectedValues{ 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, // 0-15 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // 16-31 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, // 32-47 @@ -49,7 +49,7 @@ TEST(LlvmLibcUtilsTest, Log2) { } TEST(LlvmLibcUtilsTest, LEPowerOf2) { - static const cpp::Array kExpectedValues{ + static const cpp::array kExpectedValues{ 0, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, // 0-15 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, // 16-31 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, // 32-47 @@ -61,7 +61,7 @@ TEST(LlvmLibcUtilsTest, LEPowerOf2) { } TEST(LlvmLibcUtilsTest, GEPowerOf2) { - static const cpp::Array kExpectedValues{ + static const cpp::array kExpectedValues{ 0, 1, 2, 4, 4, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, // 0-15 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, // 16-31 32, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, // 32-47 diff --git a/libc/test/src/string/memset_test.cpp b/libc/test/src/string/memset_test.cpp index 2d07e7b..b09a56a 100644 --- a/libc/test/src/string/memset_test.cpp +++ b/libc/test/src/string/memset_test.cpp @@ -10,9 +10,9 @@ #include "src/string/memset.h" #include "utils/UnitTest/Test.h" -using __llvm_libc::cpp::Array; +using __llvm_libc::cpp::array; using __llvm_libc::cpp::ArrayRef; -using Data = Array; +using Data = array; static const ArrayRef k_deadcode("DEADC0DE", 8); diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index b6f4a99..e4fec95 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -37,7 +37,7 @@ cc_library( cc_library( name = "__support_cpp_array", - hdrs = ["src/__support/CPP/Array.h"], + hdrs = ["src/__support/CPP/array.h"], deps = [":libc_root"], )