diff --git a/llvm/lib/Support/SourceMgr.cpp b/llvm/lib/Support/SourceMgr.cpp index f2bbaab23ed7b..299615a6c8041 100644 --- a/llvm/lib/Support/SourceMgr.cpp +++ b/llvm/lib/Support/SourceMgr.cpp @@ -69,11 +69,11 @@ unsigned SourceMgr::AddIncludeFile(const std::string &Filename, ErrorOr> SourceMgr::OpenIncludeFile(const std::string &Filename, std::string &IncludedFile) { - if (!FS) - reportFatalInternalError("Opening include file from SourceMgr without VFS"); + auto GetFile = [this](StringRef Path) { + return FS ? FS->getBufferForFile(Path) : MemoryBuffer::getFile(Path); + }; - ErrorOr> NewBufOrErr = - FS->getBufferForFile(Filename); + ErrorOr> NewBufOrErr = GetFile(Filename); SmallString<64> Buffer(Filename); // If the file didn't exist directly, see if it's in an include path. @@ -81,7 +81,7 @@ SourceMgr::OpenIncludeFile(const std::string &Filename, ++i) { Buffer = IncludeDirectories[i]; sys::path::append(Buffer, Filename); - NewBufOrErr = FS->getBufferForFile(Buffer); + NewBufOrErr = GetFile(Buffer); } if (NewBufOrErr)