r216476 - Return a std::unique_ptr from getBufferForFile. NFC.
Rafael Espindola
rafael.espindola at gmail.com
Tue Aug 26 12:54:41 PDT 2014
Author: rafael
Date: Tue Aug 26 14:54:40 2014
New Revision: 216476
URL: http://llvm.org/viewvc/llvm-project?rev=216476&view=rev
Log:
Return a std::unique_ptr from getBufferForFile. NFC.
Modified:
cfe/trunk/include/clang/Basic/FileManager.h
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/lib/Basic/SourceManager.cpp
cfe/trunk/lib/CodeGen/CodeGenAction.cpp
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp
cfe/trunk/lib/Serialization/ModuleManager.cpp
cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp
Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=216476&r1=216475&r2=216476&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Tue Aug 26 14:54:40 2014
@@ -241,12 +241,11 @@ public:
/// \brief Open the specified file as a MemoryBuffer, returning a new
/// MemoryBuffer if successful, otherwise returning null.
- llvm::MemoryBuffer *getBufferForFile(const FileEntry *Entry,
- std::string *ErrorStr = nullptr,
- bool isVolatile = false,
- bool ShouldCloseOpenFile = true);
- llvm::MemoryBuffer *getBufferForFile(StringRef Filename,
- std::string *ErrorStr = nullptr);
+ std::unique_ptr<llvm::MemoryBuffer>
+ getBufferForFile(const FileEntry *Entry, std::string *ErrorStr = nullptr,
+ bool isVolatile = false, bool ShouldCloseOpenFile = true);
+ std::unique_ptr<llvm::MemoryBuffer>
+ getBufferForFile(StringRef Filename, std::string *ErrorStr = nullptr);
/// \brief Get the 'stat' information for the given \p Path.
///
Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=216476&r1=216475&r2=216476&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Tue Aug 26 14:54:40 2014
@@ -386,9 +386,9 @@ void FileManager::FixupRelativePath(Smal
path = NewPath;
}
-llvm::MemoryBuffer *FileManager::
-getBufferForFile(const FileEntry *Entry, std::string *ErrorStr,
- bool isVolatile, bool ShouldCloseOpenFile) {
+std::unique_ptr<llvm::MemoryBuffer>
+FileManager::getBufferForFile(const FileEntry *Entry, std::string *ErrorStr,
+ bool isVolatile, bool ShouldCloseOpenFile) {
std::unique_ptr<llvm::MemoryBuffer> Result;
std::error_code ec;
@@ -409,7 +409,7 @@ getBufferForFile(const FileEntry *Entry,
// FileEntry is open or not.
if (ShouldCloseOpenFile)
Entry->closeFile();
- return Result.release();
+ return Result;
}
// Otherwise, open the file.
@@ -419,7 +419,7 @@ getBufferForFile(const FileEntry *Entry,
/*RequiresNullTerminator=*/true, isVolatile);
if (ec && ErrorStr)
*ErrorStr = ec.message();
- return Result.release();
+ return Result;
}
SmallString<128> FilePath(Entry->getName());
@@ -428,18 +428,18 @@ getBufferForFile(const FileEntry *Entry,
/*RequiresNullTerminator=*/true, isVolatile);
if (ec && ErrorStr)
*ErrorStr = ec.message();
- return Result.release();
+ return Result;
}
-llvm::MemoryBuffer *FileManager::
-getBufferForFile(StringRef Filename, std::string *ErrorStr) {
+std::unique_ptr<llvm::MemoryBuffer>
+FileManager::getBufferForFile(StringRef Filename, std::string *ErrorStr) {
std::unique_ptr<llvm::MemoryBuffer> Result;
std::error_code ec;
if (FileSystemOpts.WorkingDir.empty()) {
ec = FS->getBufferForFile(Filename, Result);
if (ec && ErrorStr)
*ErrorStr = ec.message();
- return Result.release();
+ return Result;
}
SmallString<128> FilePath(Filename);
@@ -447,7 +447,7 @@ getBufferForFile(StringRef Filename, std
ec = FS->getBufferForFile(FilePath.c_str(), Result);
if (ec && ErrorStr)
*ErrorStr = ec.message();
- return Result.release();
+ return Result;
}
/// getStatValue - Get the 'stat' information for the specified path,
Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=216476&r1=216475&r2=216476&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue Aug 26 14:54:40 2014
@@ -96,9 +96,9 @@ llvm::MemoryBuffer *ContentCache::getBuf
std::string ErrorStr;
bool isVolatile = SM.userFilesAreVolatile() && !IsSystemFile;
- Buffer.setPointer(SM.getFileManager().getBufferForFile(ContentsEntry,
- &ErrorStr,
- isVolatile));
+ Buffer.setPointer(SM.getFileManager()
+ .getBufferForFile(ContentsEntry, &ErrorStr, isVolatile)
+ .release());
// If we were unable to open the file, then we are in an inconsistent
// situation where the content cache referenced a file which no longer
Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=216476&r1=216475&r2=216476&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Tue Aug 26 14:54:40 2014
@@ -624,7 +624,7 @@ CodeGenAction::CreateASTConsumer(Compile
if (!LinkModuleToUse && !LinkBCFile.empty()) {
std::string ErrorStr;
- llvm::MemoryBuffer *BCBuf =
+ std::unique_ptr<llvm::MemoryBuffer> BCBuf =
CI.getFileManager().getBufferForFile(LinkBCFile, &ErrorStr);
if (!BCBuf) {
CI.getDiagnostics().Report(diag::err_cannot_open_file)
@@ -633,12 +633,13 @@ CodeGenAction::CreateASTConsumer(Compile
}
ErrorOr<llvm::Module *> ModuleOrErr =
- getLazyBitcodeModule(BCBuf, *VMContext);
+ getLazyBitcodeModule(BCBuf.get(), *VMContext);
if (std::error_code EC = ModuleOrErr.getError()) {
CI.getDiagnostics().Report(diag::err_cannot_open_file)
<< LinkBCFile << EC.message();
return nullptr;
}
+ BCBuf.release(); // Owned by the module now.
LinkModuleToUse = ModuleOrErr.get();
}
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=216476&r1=216475&r2=216476&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Tue Aug 26 14:54:40 2014
@@ -638,7 +638,7 @@ ASTDeserializationListener *ASTUnit::get
llvm::MemoryBuffer *ASTUnit::getBufferForFile(StringRef Filename,
std::string *ErrorStr) {
assert(FileMgr);
- return FileMgr->getBufferForFile(Filename, ErrorStr);
+ return FileMgr->getBufferForFile(Filename, ErrorStr).release();
}
/// \brief Configure the diagnostics object for use with ASTUnit.
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=216476&r1=216475&r2=216476&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Tue Aug 26 14:54:40 2014
@@ -723,11 +723,11 @@ bool CompilerInstance::InitializeSourceM
// STDIN.
if (File->isNamedPipe()) {
std::string ErrorStr;
- if (llvm::MemoryBuffer *MB =
+ if (std::unique_ptr<llvm::MemoryBuffer> MB =
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);
+ SourceMgr.overrideFileContents(File, MB.release());
} else {
Diags.Report(diag::err_cannot_open_file) << InputFile << ErrorStr;
return false;
Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=216476&r1=216475&r2=216476&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Tue Aug 26 14:54:40 2014
@@ -681,14 +681,13 @@ void PrintPreambleAction::ExecuteAction(
// We can't do anything with these.
return;
}
-
+
CompilerInstance &CI = getCompilerInstance();
- llvm::MemoryBuffer *Buffer
+ std::unique_ptr<llvm::MemoryBuffer> Buffer
= CI.getFileManager().getBufferForFile(getCurrentFile());
if (Buffer) {
unsigned Preamble =
Lexer::ComputePreamble(Buffer->getBuffer(), CI.getLangOpts()).first;
llvm::outs().write(Buffer->getBufferStart(), Preamble);
- delete Buffer;
}
}
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=216476&r1=216475&r2=216476&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Aug 26 14:54:40 2014
@@ -4030,8 +4030,8 @@ std::string ASTReader::getOriginalSource
DiagnosticsEngine &Diags) {
// Open the AST file.
std::string ErrStr;
- std::unique_ptr<llvm::MemoryBuffer> Buffer;
- Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr));
+ std::unique_ptr<llvm::MemoryBuffer> Buffer =
+ FileMgr.getBufferForFile(ASTFileName, &ErrStr);
if (!Buffer) {
Diags.Report(diag::err_fe_unable_to_read_pch_file) << ASTFileName << ErrStr;
return std::string();
@@ -4119,8 +4119,8 @@ bool ASTReader::readASTFileControlBlock(
ASTReaderListener &Listener) {
// Open the AST file.
std::string ErrStr;
- std::unique_ptr<llvm::MemoryBuffer> Buffer;
- Buffer.reset(FileMgr.getBufferForFile(Filename, &ErrStr));
+ std::unique_ptr<llvm::MemoryBuffer> Buffer =
+ FileMgr.getBufferForFile(Filename, &ErrStr);
if (!Buffer) {
return true;
}
Modified: cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp?rev=216476&r1=216475&r2=216476&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp (original)
+++ cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp Tue Aug 26 14:54:40 2014
@@ -493,9 +493,10 @@ namespace {
bool GlobalModuleIndexBuilder::loadModuleFile(const FileEntry *File) {
// Open the module file.
- std::unique_ptr<llvm::MemoryBuffer> Buffer;
+
std::string ErrorStr;
- Buffer.reset(FileMgr.getBufferForFile(File, &ErrorStr, /*isVolatile=*/true));
+ std::unique_ptr<llvm::MemoryBuffer> Buffer =
+ FileMgr.getBufferForFile(File, &ErrorStr, /*isVolatile=*/true);
if (!Buffer) {
return true;
}
Modified: cfe/trunk/lib/Serialization/ModuleManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ModuleManager.cpp?rev=216476&r1=216475&r2=216476&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ModuleManager.cpp (original)
+++ cfe/trunk/lib/Serialization/ModuleManager.cpp Tue Aug 26 14:54:40 2014
@@ -118,9 +118,9 @@ ModuleManager::addModule(StringRef FileN
// ModuleManager it must be the same underlying file.
// FIXME: Because FileManager::getFile() doesn't guarantee that it will
// give us an open file, this may not be 100% reliable.
- New->Buffer.reset(FileMgr.getBufferForFile(New->File, &ErrorStr,
- /*IsVolatile*/false,
- /*ShouldClose*/false));
+ New->Buffer = FileMgr.getBufferForFile(New->File, &ErrorStr,
+ /*IsVolatile*/ false,
+ /*ShouldClose*/ false);
}
if (!New->Buffer)
Modified: cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp?rev=216476&r1=216475&r2=216476&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp Tue Aug 26 14:54:40 2014
@@ -260,9 +260,7 @@ CXDiagnosticSet DiagLoader::load(const c
FileSystemOptions FO;
FileManager FileMgr(FO);
- std::unique_ptr<llvm::MemoryBuffer> Buffer;
- Buffer.reset(FileMgr.getBufferForFile(file));
-
+ std::unique_ptr<llvm::MemoryBuffer> Buffer = FileMgr.getBufferForFile(file);
if (!Buffer) {
reportBad(CXLoadDiag_CannotLoad, ErrStr);
return nullptr;
More information about the cfe-commits
mailing list