[llvm-branch-commits] [clang] e763e03 - Support: Change InMemoryFileSystem::addFileNoOwn to take a MemoryBufferRef, NFC
Duncan P. N. Exon Smith via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Dec 3 18:14:36 PST 2020
Author: Duncan P. N. Exon Smith
Date: 2020-12-03T18:09:52-08:00
New Revision: e763e032f8bbf5a4da60d099b1df4cd16e44e139
URL: https://github.com/llvm/llvm-project/commit/e763e032f8bbf5a4da60d099b1df4cd16e44e139
DIFF: https://github.com/llvm/llvm-project/commit/e763e032f8bbf5a4da60d099b1df4cd16e44e139.diff
LOG: Support: Change InMemoryFileSystem::addFileNoOwn to take a MemoryBufferRef, NFC
Found this by chance when looking at the InMemoryFileSystem API, seems
like an easy cleanup.
Differential Revision: https://reviews.llvm.org/D90893
Added:
Modified:
clang/tools/clang-format/ClangFormat.cpp
llvm/include/llvm/Support/VirtualFileSystem.h
llvm/lib/Support/VirtualFileSystem.cpp
llvm/unittests/Support/VirtualFileSystemTest.cpp
Removed:
################################################################################
diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp
index 3a7247deab46..121c9626b261 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -174,7 +174,7 @@ static cl::list<std::string> FileNames(cl::Positional, cl::desc("[<file> ...]"),
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 @@ static bool fillRanges(MemoryBuffer *Code,
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),
new DiagnosticOptions);
SourceManager Sources(Diagnostics, Files);
- FileID ID = createInMemoryFile("<irrelevant>", Code, Sources, Files,
+ FileID ID = createInMemoryFile("<irrelevant>", *Code, Sources, Files,
InMemoryFileSystem.get());
if (!LineRanges.empty()) {
if (!Offsets.empty() || !Lengths.empty()) {
@@ -427,7 +427,7 @@ static bool format(StringRef FileName) {
IntrusiveRefCntPtr<DiagnosticIDs>(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);
diff --git a/llvm/include/llvm/Support/VirtualFileSystem.h b/llvm/include/llvm/Support/VirtualFileSystem.h
index 055c0e5dd86f..714bd7ed3050 100644
--- a/llvm/include/llvm/Support/VirtualFileSystem.h
+++ b/llvm/include/llvm/Support/VirtualFileSystem.h
@@ -37,6 +37,7 @@
namespace llvm {
class MemoryBuffer;
+class MemoryBufferRef;
class Twine;
namespace vfs {
@@ -463,7 +464,8 @@ class InMemoryFileSystem : public FileSystem {
/// false if the file or directory already exists in the file system with
///
diff erent contents.
bool addFileNoOwn(const Twine &Path, time_t ModificationTime,
- llvm::MemoryBuffer *Buffer, Optional<uint32_t> User = None,
+ const llvm::MemoryBufferRef &Buffer,
+ Optional<uint32_t> User = None,
Optional<uint32_t> Group = None,
Optional<llvm::sys::fs::file_type> Type = None,
Optional<llvm::sys::fs::perms> Perms = None);
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index bbde44c30caa..697383d55d88 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -792,14 +792,12 @@ bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime,
}
bool InMemoryFileSystem::addFileNoOwn(const Twine &P, time_t ModificationTime,
- llvm::MemoryBuffer *Buffer,
+ const llvm::MemoryBufferRef &Buffer,
Optional<uint32_t> User,
Optional<uint32_t> Group,
Optional<llvm::sys::fs::file_type> Type,
Optional<llvm::sys::fs::perms> 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));
}
diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp
index 64982b9e2160..4cc209de1a50 100644
--- a/llvm/unittests/Support/VirtualFileSystemTest.cpp
+++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp
@@ -939,7 +939,7 @@ TEST_F(InMemoryFileSystemTest, OverlayFile) {
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());
More information about the llvm-branch-commits
mailing list