Index: lib/ObjectYAML/ObjectYAML.cpp =================================================================== --- lib/ObjectYAML/ObjectYAML.cpp +++ lib/ObjectYAML/ObjectYAML.cpp @@ -51,7 +51,9 @@ MappingTraits::mapping(IO, *ObjectFile.Wasm); } else { Input &In = (Input &)IO; - std::string Tag = In.getCurrentNode()->getRawTag(); + std::string Tag; + if (In.getCurrentNode()) + Tag = In.getCurrentNode()->getRawTag(); if (Tag.empty()) IO.setError("YAML Object File missing document type tag!"); else Index: lib/Support/YAMLParser.cpp =================================================================== --- lib/Support/YAMLParser.cpp +++ lib/Support/YAMLParser.cpp @@ -1769,10 +1769,8 @@ bool Stream::failed() { return scanner->failed(); } void Stream::printError(Node *N, const Twine &Msg) { - scanner->printError( N->getSourceRange().Start - , SourceMgr::DK_Error - , Msg - , N->getSourceRange()); + scanner->printError(N ? N->getSourceRange().Start : SMLoc(), + SourceMgr::DK_Error, Msg, N ? N->getSourceRange() : None); } document_iterator Stream::begin() { Index: lib/Support/YAMLTraits.cpp =================================================================== --- lib/Support/YAMLTraits.cpp +++ lib/Support/YAMLTraits.cpp @@ -113,6 +113,8 @@ } bool Input::mapTag(StringRef Tag, bool Default) { + if (!CurrentNode) + return false; std::string foundTag = CurrentNode->_node->getVerbatimTag(); if (foundTag.empty()) { // If no tag found and 'Tag' is the default, say it was found. @@ -340,8 +342,7 @@ void Input::blockScalarString(StringRef &S) { scalarString(S, false); } void Input::setError(HNode *hnode, const Twine &message) { - assert(hnode && "HNode must not be NULL"); - this->setError(hnode->_node, message); + this->setError(hnode ? hnode->_node : (Node *)nullptr, message); } void Input::setError(Node *node, const Twine &message) { Index: test/Object/yaml2obj-invalid2.yaml =================================================================== --- test/Object/yaml2obj-invalid2.yaml +++ test/Object/yaml2obj-invalid2.yaml @@ -0,0 +1,2 @@ +# RUN: not yaml2obj %s 2>&1 | FileCheck %s +# CHECK: :0: error: YAML Object File missing document type tag!