-
Notifications
You must be signed in to change notification settings - Fork 12k
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
[YAML] Make std::array
available
#116059
[YAML] Make std::array
available
#116059
Conversation
@llvm/pr-subscribers-llvm-support Author: NAKAMURA Takumi (chapuni) Changes
Not like;
Full diff: https://github.com/llvm/llvm-project/pull/116059.diff 2 Files Affected:
diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h
index 1d04783753d5cd..45d82f3ebefa9c 100644
--- a/llvm/include/llvm/Support/YAMLTraits.h
+++ b/llvm/include/llvm/Support/YAMLTraits.h
@@ -2006,6 +2006,11 @@ struct SequenceTraits<
std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
: SequenceTraitsImpl<std::vector<T>, SequenceElementTraits<T>::flow> {};
template <typename T, unsigned N>
+struct SequenceTraits<
+ std::array<T, N>,
+ std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
+ : SequenceTraitsImpl<std::array<T, N>, SequenceElementTraits<T>::flow> {};
+template <typename T, unsigned N>
struct SequenceTraits<
SmallVector<T, N>,
std::enable_if_t<CheckIsBool<SequenceElementTraits<T>::flow>::value>>
diff --git a/llvm/unittests/Support/YAMLIOTest.cpp b/llvm/unittests/Support/YAMLIOTest.cpp
index e10fe099a30adb..a7d1b338719f3b 100644
--- a/llvm/unittests/Support/YAMLIOTest.cpp
+++ b/llvm/unittests/Support/YAMLIOTest.cpp
@@ -3366,20 +3366,38 @@ struct FixedArray {
int values[4];
};
+struct StdArray {
+ StdArray() {
+ // Initialize to int max as a sentinel value.
+ for (auto &v : values)
+ v = std::numeric_limits<int>::max();
+ }
+ std::array<int, 4> values;
+};
+
namespace llvm {
namespace yaml {
- template <>
- struct MappingTraits<FixedArray> {
- static void mapping(IO &io, FixedArray& st) {
- MutableArrayRef<int> array = st.values;
- io.mapRequired("Values", array);
- }
- };
-}
-}
+template <> struct MappingTraits<FixedArray> {
+ static void mapping(IO &io, FixedArray &st) {
+ MutableArrayRef<int> array = st.values;
+ io.mapRequired("Values", array);
+ }
+};
+template <> struct MappingTraits<StdArray> {
+ static void mapping(IO &io, StdArray &st) {
+ io.mapRequired("Values", st.values);
+ }
+};
+} // namespace yaml
+} // namespace llvm
+
+using TestTypes = ::testing::Types<FixedArray, StdArray>;
-TEST(YAMLIO, FixedSizeArray) {
- FixedArray faval;
+template <typename T> class YAMLIO : public testing::Test {};
+TYPED_TEST_SUITE(YAMLIO, TestTypes, );
+
+TYPED_TEST(YAMLIO, FixedSizeArray) {
+ TypeParam faval;
Input yin("---\nValues: [ 1, 2, 3, 4 ]\n...\n");
yin >> faval;
@@ -3401,9 +3419,9 @@ TEST(YAMLIO, FixedSizeArray) {
ASSERT_EQ(serialized, expected);
}
-TEST(YAMLIO, FixedSizeArrayMismatch) {
+TYPED_TEST(YAMLIO, FixedSizeArrayMismatch) {
{
- FixedArray faval;
+ TypeParam faval;
Input yin("---\nValues: [ 1, 2, 3 ]\n...\n");
yin >> faval;
@@ -3416,12 +3434,11 @@ TEST(YAMLIO, FixedSizeArrayMismatch) {
}
{
- FixedArray faval;
+ TypeParam faval;
Input yin("---\nValues: [ 1, 2, 3, 4, 5 ]\n...\n");
yin >> faval;
// Error for too many elements.
EXPECT_TRUE(!!yin.error());
}
-
}
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/137/builds/8583 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/175/builds/8477 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/185/builds/8471 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/160/builds/8353 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/11562 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/140/builds/10841 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/180/builds/8351 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/8407 Here is the relevant piece of the build log for the reference
|
Compilation failed on gcc hosts. This reverts commit 941f704. (llvmorg-20-init-12117-g941f704f0892)
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/133/builds/6779 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/33/builds/6429 Here is the relevant piece of the build log for the reference
|
`std::array` will be handled like `MutableArrayRef`; - Extending elements is not acceptable. - For applying fewer sequence, trailing elements will be initialized by default. Not like; - `std::array` is not the reference but holds values. Supposing to hold small count of elements. Changes since llvmorg-20-init-12117-g941f704f0892: - Use `size_t` for `N`, instead of `unsigned`. - include <array>
`std::array` will be handled like `MutableArrayRef`; - Extending elements is not acceptable. - For applying fewer sequence, trailing elements will be initialized by default. Not like; - `std::array` is not the reference but holds values. Supposing to hold small count of elements. Changes since llvmorg-20-init-12117-g941f704f0892: - Use `size_t` for `N`, instead of `unsigned`. - include <array>
`std::array` will be handled like `MutableArrayRef`; - Extending elements is not acceptable. - For applying fewer sequence, trailing elements will be initialized by default. Not like; - `std::array` is not the reference but holds values. Supposing to hold small count of elements.
Compilation failed on gcc hosts. This reverts commit 941f704. (llvmorg-20-init-12117-g941f704f0892)
`std::array` will be handled like `MutableArrayRef`; - Extending elements is not acceptable. - For applying fewer sequence, trailing elements will be initialized by default. Not like; - `std::array` is not the reference but holds values. Supposing to hold small count of elements. Changes since llvmorg-20-init-12117-g941f704f0892: - Use `size_t` for `N`, instead of `unsigned`. - include <array>
std::array
will be handled likeMutableArrayRef
;Not like;
std::array
is not the reference but holds values. Supposing to hold small count of elements.