Index: include/llvm/Support/YAMLTraits.h =================================================================== --- include/llvm/Support/YAMLTraits.h +++ include/llvm/Support/YAMLTraits.h @@ -976,6 +976,10 @@ void *Ctxt = nullptr, SourceMgr::DiagHandlerTy DiagHandler = nullptr, void *DiagHandlerCtxt = nullptr); + Input(MemoryBuffer &Input, + void *Ctxt = nullptr, + SourceMgr::DiagHandlerTy DiagHandler = nullptr, + void *DiagHandlerCtxt = nullptr); ~Input() override; // Check if there was an syntax or semantic error during parsing. Index: lib/Support/YAMLTraits.cpp =================================================================== --- lib/Support/YAMLTraits.cpp +++ lib/Support/YAMLTraits.cpp @@ -56,6 +56,19 @@ DocIterator = Strm->begin(); } +Input::Input(MemoryBuffer &Input, + void *Ctxt, + SourceMgr::DiagHandlerTy DiagHandler, + void *DiagHandlerCtxt) + : IO(Ctxt), + Strm(new Stream( + MemoryBufferRef(Input.getBuffer(), Input.getBufferIdentifier()), SrcMgr)), + CurrentNode(nullptr) { + if (DiagHandler) + SrcMgr.setDiagHandler(DiagHandler, DiagHandlerCtxt); + DocIterator = Strm->begin(); +} + Input::~Input() { } Index: unittests/Support/YAMLIOTest.cpp =================================================================== --- unittests/Support/YAMLIOTest.cpp +++ unittests/Support/YAMLIOTest.cpp @@ -233,6 +233,15 @@ } } +// +// Test YAML filename handling. +// +TEST(YAMLIO, TestGivenFilename) { + // NOTE: Input doesn't expose enough information to retrieve the filename. + auto Buffer = llvm::MemoryBuffer::getMemBuffer("{ x: 42 }", "foo.yaml"); + Input yin(*Buffer); +} + //===----------------------------------------------------------------------===// // Test built-in types