Index: clang/tools/clang-format/ClangFormat.cpp =================================================================== --- clang/tools/clang-format/ClangFormat.cpp +++ clang/tools/clang-format/ClangFormat.cpp @@ -174,7 +174,7 @@ namespace clang { namespace format { -static FileID createInMemoryFile(StringRef FileName, MemoryBuffer *Source, +static FileID createInMemoryFile(StringRef FileName, MemoryBufferRef Source, SourceManager &Sources, FileManager &Files, llvm::vfs::InMemoryFileSystem *MemFS) { MemFS->addFileNoOwn(FileName, 0, Source); @@ -201,7 +201,7 @@ IntrusiveRefCntPtr(new DiagnosticIDs), new DiagnosticOptions); SourceManager Sources(Diagnostics, Files); - FileID ID = createInMemoryFile("", Code, Sources, Files, + FileID ID = createInMemoryFile("", *Code, Sources, Files, InMemoryFileSystem.get()); if (!LineRanges.empty()) { if (!Offsets.empty() || !Lengths.empty()) { @@ -427,7 +427,7 @@ IntrusiveRefCntPtr(new DiagnosticIDs), new DiagnosticOptions); SourceManager Sources(Diagnostics, Files); - FileID ID = createInMemoryFile(AssumedFileName, Code.get(), Sources, Files, + FileID ID = createInMemoryFile(AssumedFileName, *Code, Sources, Files, InMemoryFileSystem.get()); Rewriter Rewrite(Sources, LangOptions()); tooling::applyAllReplacements(Replaces, Rewrite); Index: llvm/include/llvm/Support/VirtualFileSystem.h =================================================================== --- llvm/include/llvm/Support/VirtualFileSystem.h +++ llvm/include/llvm/Support/VirtualFileSystem.h @@ -37,6 +37,7 @@ namespace llvm { class MemoryBuffer; +class MemoryBufferRef; class Twine; namespace vfs { @@ -463,7 +464,8 @@ /// false if the file or directory already exists in the file system with /// different contents. bool addFileNoOwn(const Twine &Path, time_t ModificationTime, - llvm::MemoryBuffer *Buffer, Optional User = None, + const llvm::MemoryBufferRef &Buffer, + Optional User = None, Optional Group = None, Optional Type = None, Optional Perms = None); Index: llvm/lib/Support/VirtualFileSystem.cpp =================================================================== --- llvm/lib/Support/VirtualFileSystem.cpp +++ llvm/lib/Support/VirtualFileSystem.cpp @@ -792,14 +792,12 @@ } bool InMemoryFileSystem::addFileNoOwn(const Twine &P, time_t ModificationTime, - llvm::MemoryBuffer *Buffer, + const llvm::MemoryBufferRef &Buffer, Optional User, Optional Group, Optional Type, Optional Perms) { - return addFile(P, ModificationTime, - llvm::MemoryBuffer::getMemBuffer( - Buffer->getBuffer(), Buffer->getBufferIdentifier()), + return addFile(P, ModificationTime, llvm::MemoryBuffer::getMemBuffer(Buffer), std::move(User), std::move(Group), std::move(Type), std::move(Perms)); } Index: llvm/unittests/Support/VirtualFileSystemTest.cpp =================================================================== --- llvm/unittests/Support/VirtualFileSystemTest.cpp +++ llvm/unittests/Support/VirtualFileSystemTest.cpp @@ -939,7 +939,7 @@ TEST_F(InMemoryFileSystemTest, OverlayFileNoOwn) { auto Buf = MemoryBuffer::getMemBuffer("a"); - FS.addFileNoOwn("/a", 0, Buf.get()); + FS.addFileNoOwn("/a", 0, *Buf); auto Stat = FS.status("/a"); ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString(); ASSERT_EQ("/a", Stat->getName());