From 926a507ee587f1455010dca59ffd0253d2bf70ff Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Wed, 27 Aug 2014 20:54:45 +0000 Subject: Overload SourceManager::overrideFileContents so that unconditionally passing ownership is explicitly done using unique_ptr. Only those callers who are dynamically passing ownership should need the 3 argument form. Those accepting the default ("do pass ownership") should do so explicitly with a unique_ptr now. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216614 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/SourceManager.h | 6 +++++- lib/Format/Format.cpp | 2 +- lib/Frontend/CompilerInstance.cpp | 6 +++--- lib/Index/SimpleFormatContext.h | 2 +- lib/Lex/Preprocessor.cpp | 2 +- lib/Serialization/ASTReader.cpp | 2 +- lib/Tooling/Refactoring.cpp | 2 +- unittests/Basic/SourceManagerTest.cpp | 4 ++-- unittests/Tooling/RewriterTestContext.h | 2 +- 9 files changed, 16 insertions(+), 12 deletions(-) diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index fb65c4b28d..8addde9d15 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -832,7 +832,11 @@ public: /// \param DoNotFree If true, then the buffer will not be freed when the /// source manager is destroyed. void overrideFileContents(const FileEntry *SourceFile, - llvm::MemoryBuffer *Buffer, bool DoNotFree = false); + llvm::MemoryBuffer *Buffer, bool DoNotFree); + void overrideFileContents(const FileEntry *SourceFile, + std::unique_ptr Buffer) { + overrideFileContents(SourceFile, Buffer.release(), /*DoNotFree*/ false); + } /// \brief Override the given source file with another one. /// diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 32808b519a..432da61d85 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1996,7 +1996,7 @@ tooling::Replacements reformat(const FormatStyle &Style, StringRef Code, llvm::MemoryBuffer::getMemBuffer(Code, FileName); const clang::FileEntry *Entry = Files.getVirtualFile(FileName, Buf->getBufferSize(), 0); - SourceMgr.overrideFileContents(Entry, Buf.release()); + SourceMgr.overrideFileContents(Entry, std::move(Buf)); FileID ID = SourceMgr.createFileID(Entry, SourceLocation(), clang::SrcMgr::C_User); Lexer Lex(ID, SourceMgr.getBuffer(ID), SourceMgr, diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index a535afdc05..4cba26cc63 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -727,7 +727,7 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input, FileMgr.getBufferForFile(File, &ErrorStr, /*isVolatile=*/true)) { // Create a new virtual file that will have the correct size. File = FileMgr.getVirtualFile(InputFile, MB->getBufferSize(), 0); - SourceMgr.overrideFileContents(File, MB.release()); + SourceMgr.overrideFileContents(File, std::move(MB)); } else { Diags.Report(diag::err_cannot_open_file) << InputFile << ErrorStr; return false; @@ -749,7 +749,7 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input, SB->getBufferSize(), 0); SourceMgr.setMainFileID( SourceMgr.createFileID(File, SourceLocation(), Kind)); - SourceMgr.overrideFileContents(File, SB.release()); + SourceMgr.overrideFileContents(File, std::move(SB)); } assert(!SourceMgr.getMainFileID().isInvalid() && @@ -951,7 +951,7 @@ static bool compileModuleImpl(CompilerInstance &ImportingInstance, llvm::MemoryBuffer::getMemBuffer(InferredModuleMapContent); ModuleMapFile = Instance.getFileManager().getVirtualFile( "__inferred_module.map", InferredModuleMapContent.size(), 0); - SourceMgr.overrideFileContents(ModuleMapFile, ModuleMapBuffer.release()); + SourceMgr.overrideFileContents(ModuleMapFile, std::move(ModuleMapBuffer)); } // Construct a module-generating action. Passing through the module map is diff --git a/lib/Index/SimpleFormatContext.h b/lib/Index/SimpleFormatContext.h index faf865786a..080a4ad04d 100644 --- a/lib/Index/SimpleFormatContext.h +++ b/lib/Index/SimpleFormatContext.h @@ -51,7 +51,7 @@ public: llvm::MemoryBuffer::getMemBuffer(Content); const FileEntry *Entry = Files.getVirtualFile(Name, Source->getBufferSize(), 0); - Sources.overrideFileContents(Entry, Source.release()); + Sources.overrideFileContents(Entry, std::move(Source)); assert(Entry != nullptr); return Sources.createFileID(Entry, SourceLocation(), SrcMgr::C_User); } diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 29956c9f58..1dd46b0de9 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -406,7 +406,7 @@ bool Preprocessor::SetCodeCompletionPoint(const FileEntry *File, char *NewPos = std::copy(Buffer->getBufferStart(), Position, NewBuf); *NewPos = '\0'; std::copy(Position, Buffer->getBufferEnd(), NewPos+1); - SourceMgr.overrideFileContents(File, NewBuffer.release()); + SourceMgr.overrideFileContents(File, std::move(NewBuffer)); } return false; diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 1bee2a026b..68faeed6a2 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -1226,7 +1226,7 @@ bool ASTReader::ReadSLocEntry(int ID) { std::unique_ptr Buffer = llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), File->getName()); - SourceMgr.overrideFileContents(File, Buffer.release()); + SourceMgr.overrideFileContents(File, std::move(Buffer)); } break; diff --git a/lib/Tooling/Refactoring.cpp b/lib/Tooling/Refactoring.cpp index ab16dfd35f..b2a02cb096 100644 --- a/lib/Tooling/Refactoring.cpp +++ b/lib/Tooling/Refactoring.cpp @@ -186,7 +186,7 @@ std::string applyAllReplacements(StringRef Code, const Replacements &Replaces) { llvm::MemoryBuffer::getMemBuffer(Code, ""); const clang::FileEntry *Entry = Files.getVirtualFile("", Buf->getBufferSize(), 0); - SourceMgr.overrideFileContents(Entry, Buf.release()); + SourceMgr.overrideFileContents(Entry, std::move(Buf)); FileID ID = SourceMgr.createFileID(Entry, SourceLocation(), clang::SrcMgr::C_User); for (Replacements::const_iterator I = Replaces.begin(), E = Replaces.end(); diff --git a/unittests/Basic/SourceManagerTest.cpp b/unittests/Basic/SourceManagerTest.cpp index dc27560b3a..540a8051e6 100644 --- a/unittests/Basic/SourceManagerTest.cpp +++ b/unittests/Basic/SourceManagerTest.cpp @@ -193,7 +193,7 @@ TEST_F(SourceManagerTest, getMacroArgExpandedLocation) { const FileEntry *headerFile = FileMgr.getVirtualFile("/test-header.h", HeaderBuf->getBufferSize(), 0); - SourceMgr.overrideFileContents(headerFile, HeaderBuf.release()); + SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf)); VoidModuleLoader ModLoader; HeaderSearch HeaderInfo(new HeaderSearchOptions, SourceMgr, Diags, LangOpts, @@ -291,7 +291,7 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnitWithMacroInInclude) { const FileEntry *headerFile = FileMgr.getVirtualFile("/test-header.h", HeaderBuf->getBufferSize(), 0); - SourceMgr.overrideFileContents(headerFile, HeaderBuf.release()); + SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf)); VoidModuleLoader ModLoader; HeaderSearch HeaderInfo(new HeaderSearchOptions, SourceMgr, Diags, LangOpts, diff --git a/unittests/Tooling/RewriterTestContext.h b/unittests/Tooling/RewriterTestContext.h index bf25f8c998..82c00582f1 100644 --- a/unittests/Tooling/RewriterTestContext.h +++ b/unittests/Tooling/RewriterTestContext.h @@ -52,7 +52,7 @@ class RewriterTestContext { llvm::MemoryBuffer::getMemBuffer(Content); const FileEntry *Entry = Files.getVirtualFile(Name, Source->getBufferSize(), 0); - Sources.overrideFileContents(Entry, Source.release()); + Sources.overrideFileContents(Entry, std::move(Source)); assert(Entry != nullptr); return Sources.createFileID(Entry, SourceLocation(), SrcMgr::C_User); } -- cgit v1.2.3