Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions llvm/include/llvm/Support/YAMLTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>>
Expand Down
29 changes: 24 additions & 5 deletions llvm/unittests/Support/YAMLIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>::max();
}
std::array<int, 4> values;
};

namespace llvm {
namespace yaml {
template <> struct MappingTraits<FixedArray> {
Expand All @@ -3374,11 +3383,21 @@ template <> struct MappingTraits<FixedArray> {
io.mapRequired("Values", array);
}
};
template <> struct MappingTraits<StdArray> {
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<FixedArray, StdArray>;

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;

Expand All @@ -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;

Expand All @@ -3415,7 +3434,7 @@ TEST(YAMLIO, FixedSizeArrayMismatch) {
}

{
FixedArray faval;
TypeParam faval;
Input yin("---\nValues: [ 1, 2, 3, 4, 5 ]\n...\n");
yin >> faval;

Expand Down
Loading