diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h index 403584e52fed3..510f76a66cee5 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::flow>::value>> : SequenceTraitsImpl, SequenceElementTraits::flow> {}; template +struct SequenceTraits< + std::array, + std::enable_if_t::flow>::value>> + : SequenceTraitsImpl, SequenceElementTraits::flow> {}; +template struct SequenceTraits< SmallVector, std::enable_if_t::flow>::value>> diff --git a/llvm/unittests/Support/YAMLIOTest.cpp b/llvm/unittests/Support/YAMLIOTest.cpp index 2d76b1509840f..a7d1b338719f3 100644 --- a/llvm/unittests/Support/YAMLIOTest.cpp +++ b/llvm/unittests/Support/YAMLIOTest.cpp @@ -3366,6 +3366,15 @@ struct FixedArray { int values[4]; }; +struct StdArray { + StdArray() { + // Initialize to int max as a sentinel value. + for (auto &v : values) + v = std::numeric_limits::max(); + } + std::array values; +}; + namespace llvm { namespace yaml { template <> struct MappingTraits { @@ -3374,11 +3383,21 @@ template <> struct MappingTraits { io.mapRequired("Values", array); } }; +template <> struct MappingTraits { + static void mapping(IO &io, StdArray &st) { + io.mapRequired("Values", st.values); + } +}; } // namespace yaml } // namespace llvm -TEST(YAMLIO, FixedSizeArray) { - FixedArray faval; +using TestTypes = ::testing::Types; + +template 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; @@ -3400,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; @@ -3415,7 +3434,7 @@ TEST(YAMLIO, FixedSizeArrayMismatch) { } { - FixedArray faval; + TypeParam faval; Input yin("---\nValues: [ 1, 2, 3, 4, 5 ]\n...\n"); yin >> faval;