Index: llvm/lib/Support/YAMLParser.cpp =================================================================== --- llvm/lib/Support/YAMLParser.cpp +++ llvm/lib/Support/YAMLParser.cpp @@ -2269,8 +2269,8 @@ bool Document::skip() { if (stream.scanner->failed()) return false; - if (!Root) - getRoot(); + if (!Root && !getRoot()) + return false; Root->skip(); Token &T = peekNext(); if (T.Kind == Token::TK_StreamEnd) @@ -2395,8 +2395,12 @@ // !!null null. return new (NodeAllocator) NullNode(stream.CurrentDoc); case Token::TK_Error: + case Token::TK_FlowEntry: + case Token::TK_FlowMappingEnd: + case Token::TK_FlowSequenceEnd: { return nullptr; } + } llvm_unreachable("Control flow shouldn't reach here."); return nullptr; } Index: llvm/unittests/Support/YAMLParserTest.cpp =================================================================== --- llvm/unittests/Support/YAMLParserTest.cpp +++ llvm/unittests/Support/YAMLParserTest.cpp @@ -331,4 +331,15 @@ EXPECT_TRUE(End == AnotherEnd); } +TEST(YAMLParser, FlowSequenceTokensOutsideFlowSequence) { + auto FlowSequenceStrs = {",", "]", "}"}; + SourceMgr SM; + + for (auto &Str : FlowSequenceStrs) { + yaml::Stream Stream(Str, SM); + yaml::Document &Doc = *Stream.begin(); + EXPECT_FALSE(Doc.skip()); + } +} + } // end namespace llvm