r220657 - Make VFS and FileManager match the current MemoryBuffer API.
Benjamin Kramer
benny.kra at googlemail.com
Sun Oct 26 15:44:14 PDT 2014
Author: d0k
Date: Sun Oct 26 17:44:13 2014
New Revision: 220657
URL: http://llvm.org/viewvc/llvm-project?rev=220657&view=rev
Log:
Make VFS and FileManager match the current MemoryBuffer API.
This eliminates converting back and forth between the 3 formats and
gives us a more homogeneous interface.
Modified:
cfe/trunk/include/clang/Basic/FileManager.h
cfe/trunk/include/clang/Basic/VirtualFileSystem.h
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/lib/Basic/FileSystemStatCache.cpp
cfe/trunk/lib/Basic/SourceManager.cpp
cfe/trunk/lib/Basic/VirtualFileSystem.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/Frontend/SerializedDiagnosticReader.cpp
cfe/trunk/lib/Lex/HeaderMap.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp
cfe/trunk/lib/Serialization/ModuleManager.cpp
cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp
cfe/trunk/unittests/Tooling/RefactoringTest.cpp
cfe/trunk/unittests/Tooling/RewriterTestContext.h
Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Sun Oct 26 17:44:13 2014
@@ -241,11 +241,11 @@ public:
/// \brief Open the specified file as a MemoryBuffer, returning a new
/// MemoryBuffer if successful, otherwise returning null.
- 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);
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+ getBufferForFile(const FileEntry *Entry, bool isVolatile = false,
+ bool ShouldCloseOpenFile = true);
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+ getBufferForFile(StringRef Filename);
/// \brief Get the 'stat' information for the given \p Path.
///
Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original)
+++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Sun Oct 26 17:44:13 2014
@@ -89,11 +89,9 @@ public:
/// \brief Get the status of the file.
virtual llvm::ErrorOr<Status> status() = 0;
/// \brief Get the contents of the file as a \p MemoryBuffer.
- virtual std::error_code getBuffer(const Twine &Name,
- std::unique_ptr<llvm::MemoryBuffer> &Result,
- int64_t FileSize = -1,
- bool RequiresNullTerminator = true,
- bool IsVolatile = false) = 0;
+ virtual llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+ getBuffer(const Twine &Name, int64_t FileSize = -1,
+ bool RequiresNullTerminator = true, bool IsVolatile = false) = 0;
/// \brief Closes the file.
virtual std::error_code close() = 0;
/// \brief Sets the name to use for this file.
@@ -188,16 +186,14 @@ public:
/// \brief Get the status of the entry at \p Path, if one exists.
virtual llvm::ErrorOr<Status> status(const Twine &Path) = 0;
/// \brief Get a \p File object for the file at \p Path, if one exists.
- virtual std::error_code openFileForRead(const Twine &Path,
- std::unique_ptr<File> &Result) = 0;
+ virtual llvm::ErrorOr<std::unique_ptr<File>>
+ openFileForRead(const Twine &Path) = 0;
/// This is a convenience method that opens a file, gets its content and then
/// closes the file.
- std::error_code getBufferForFile(const Twine &Name,
- std::unique_ptr<llvm::MemoryBuffer> &Result,
- int64_t FileSize = -1,
- bool RequiresNullTerminator = true,
- bool IsVolatile = false);
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+ getBufferForFile(const Twine &Name, int64_t FileSize = -1,
+ bool RequiresNullTerminator = true, bool IsVolatile = false);
/// \brief Get a directory_iterator for \p Dir.
/// \note The 'end' iterator is directory_iterator().
@@ -231,8 +227,8 @@ public:
void pushOverlay(IntrusiveRefCntPtr<FileSystem> FS);
llvm::ErrorOr<Status> status(const Twine &Path) override;
- std::error_code openFileForRead(const Twine &Path,
- std::unique_ptr<File> &Result) override;
+ llvm::ErrorOr<std::unique_ptr<File>>
+ openFileForRead(const Twine &Path) override;
directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override;
typedef FileSystemList::reverse_iterator iterator;
Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Sun Oct 26 17:44:13 2014
@@ -399,12 +399,9 @@ void FileManager::FixupRelativePath(Smal
path = NewPath;
}
-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;
-
+llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile,
+ bool ShouldCloseOpenFile) {
uint64_t FileSize = Entry->getSize();
// If there's a high enough chance that the file have changed since we
// got its size, force a stat before opening it.
@@ -414,10 +411,9 @@ FileManager::getBufferForFile(const File
const char *Filename = Entry->getName();
// If the file is already open, use the open file descriptor.
if (Entry->File) {
- ec = Entry->File->getBuffer(Filename, Result, FileSize,
- /*RequiresNullTerminator=*/true, isVolatile);
- if (ErrorStr)
- *ErrorStr = ec.message();
+ auto Result =
+ Entry->File->getBuffer(Filename, FileSize,
+ /*RequiresNullTerminator=*/true, isVolatile);
// FIXME: we need a set of APIs that can make guarantees about whether a
// FileEntry is open or not.
if (ShouldCloseOpenFile)
@@ -427,40 +423,24 @@ FileManager::getBufferForFile(const File
// Otherwise, open the file.
- if (FileSystemOpts.WorkingDir.empty()) {
- ec = FS->getBufferForFile(Filename, Result, FileSize,
- /*RequiresNullTerminator=*/true, isVolatile);
- if (ec && ErrorStr)
- *ErrorStr = ec.message();
- return Result;
- }
+ if (FileSystemOpts.WorkingDir.empty())
+ return FS->getBufferForFile(Filename, FileSize,
+ /*RequiresNullTerminator=*/true, isVolatile);
SmallString<128> FilePath(Entry->getName());
FixupRelativePath(FilePath);
- ec = FS->getBufferForFile(FilePath.str(), Result, FileSize,
- /*RequiresNullTerminator=*/true, isVolatile);
- if (ec && ErrorStr)
- *ErrorStr = ec.message();
- return Result;
+ return FS->getBufferForFile(FilePath.str(), FileSize,
+ /*RequiresNullTerminator=*/true, isVolatile);
}
-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;
- }
+llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
+FileManager::getBufferForFile(StringRef Filename) {
+ if (FileSystemOpts.WorkingDir.empty())
+ return FS->getBufferForFile(Filename);
SmallString<128> FilePath(Filename);
FixupRelativePath(FilePath);
- ec = FS->getBufferForFile(FilePath.c_str(), Result);
- if (ec && ErrorStr)
- *ErrorStr = ec.message();
- return Result;
+ return FS->getBufferForFile(FilePath.c_str());
}
/// getStatValue - Get the 'stat' information for the specified path,
Modified: cfe/trunk/lib/Basic/FileSystemStatCache.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileSystemStatCache.cpp?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileSystemStatCache.cpp (original)
+++ cfe/trunk/lib/Basic/FileSystemStatCache.cpp Sun Oct 26 17:44:13 2014
@@ -78,21 +78,20 @@ bool FileSystemStatCache::get(const char
//
// Because of this, check to see if the file exists with 'open'. If the
// open succeeds, use fstat to get the stat info.
- std::unique_ptr<vfs::File> OwnedFile;
- std::error_code EC = FS.openFileForRead(Path, OwnedFile);
+ auto OwnedFile = FS.openFileForRead(Path);
- if (EC) {
+ if (!OwnedFile) {
// If the open fails, our "stat" fails.
R = CacheMissing;
} else {
// Otherwise, the open succeeded. Do an fstat to get the information
// about the file. We'll end up returning the open file descriptor to the
// client to do what they please with it.
- llvm::ErrorOr<vfs::Status> Status = OwnedFile->status();
+ llvm::ErrorOr<vfs::Status> Status = (*OwnedFile)->status();
if (Status) {
R = CacheExists;
copyStatusToFileData(*Status, Data);
- *F = std::move(OwnedFile);
+ *F = std::move(*OwnedFile);
} else {
// fstat rarely fails. If it does, claim the initial open didn't
// succeed.
Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Sun Oct 26 17:44:13 2014
@@ -94,11 +94,9 @@ llvm::MemoryBuffer *ContentCache::getBuf
return Buffer.getPointer();
}
- std::string ErrorStr;
bool isVolatile = SM.userFilesAreVolatile() && !IsSystemFile;
- Buffer.setPointer(SM.getFileManager()
- .getBufferForFile(ContentsEntry, &ErrorStr, isVolatile)
- .release());
+ auto BufferOrError =
+ SM.getFileManager().getBufferForFile(ContentsEntry, isVolatile);
// 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
@@ -110,7 +108,7 @@ llvm::MemoryBuffer *ContentCache::getBuf
// currently handle returning a null entry here. Ideally we should detect
// that we are in an inconsistent situation and error out as quickly as
// possible.
- if (!Buffer.getPointer()) {
+ if (!BufferOrError) {
StringRef FillStr("<<<MISSING SOURCE FILE>>>\n");
Buffer.setPointer(MemoryBuffer::getNewMemBuffer(ContentsEntry->getSize(),
"<invalid>").release());
@@ -119,18 +117,21 @@ llvm::MemoryBuffer *ContentCache::getBuf
Ptr[i] = FillStr[i % FillStr.size()];
if (Diag.isDiagnosticInFlight())
- Diag.SetDelayedDiagnostic(diag::err_cannot_open_file,
- ContentsEntry->getName(), ErrorStr);
- else
+ Diag.SetDelayedDiagnostic(diag::err_cannot_open_file,
+ ContentsEntry->getName(),
+ BufferOrError.getError().message());
+ else
Diag.Report(Loc, diag::err_cannot_open_file)
- << ContentsEntry->getName() << ErrorStr;
+ << ContentsEntry->getName() << BufferOrError.getError().message();
Buffer.setInt(Buffer.getInt() | InvalidFlag);
if (Invalid) *Invalid = true;
return Buffer.getPointer();
}
-
+
+ Buffer.setPointer(BufferOrError->release());
+
// Check that the file's size is the same as in the file entry (which may
// have come from a stat cache).
if (getRawBuffer()->getBufferSize() != (size_t)ContentsEntry->getSize()) {
Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Sun Oct 26 17:44:13 2014
@@ -67,16 +67,14 @@ File::~File() {}
FileSystem::~FileSystem() {}
-std::error_code FileSystem::getBufferForFile(
- const llvm::Twine &Name, std::unique_ptr<MemoryBuffer> &Result,
- int64_t FileSize, bool RequiresNullTerminator, bool IsVolatile) {
- std::unique_ptr<File> F;
- if (std::error_code EC = openFileForRead(Name, F))
- return EC;
+ErrorOr<std::unique_ptr<MemoryBuffer>>
+FileSystem::getBufferForFile(const llvm::Twine &Name, int64_t FileSize,
+ bool RequiresNullTerminator, bool IsVolatile) {
+ auto F = openFileForRead(Name);
+ if (!F)
+ return F.getError();
- std::error_code EC =
- F->getBuffer(Name, Result, FileSize, RequiresNullTerminator, IsVolatile);
- return EC;
+ return (*F)->getBuffer(Name, FileSize, RequiresNullTerminator, IsVolatile);
}
//===-----------------------------------------------------------------------===/
@@ -96,11 +94,10 @@ class RealFile : public File {
public:
~RealFile();
ErrorOr<Status> status() override;
- std::error_code getBuffer(const Twine &Name,
- std::unique_ptr<MemoryBuffer> &Result,
- int64_t FileSize = -1,
- bool RequiresNullTerminator = true,
- bool IsVolatile = false) override;
+ ErrorOr<std::unique_ptr<MemoryBuffer>>
+ getBuffer(const Twine &Name, int64_t FileSize = -1,
+ bool RequiresNullTerminator = true,
+ bool IsVolatile = false) override;
std::error_code close() override;
void setName(StringRef Name) override;
};
@@ -120,19 +117,12 @@ ErrorOr<Status> RealFile::status() {
return S;
}
-std::error_code RealFile::getBuffer(const Twine &Name,
- std::unique_ptr<MemoryBuffer> &Result,
- int64_t FileSize,
- bool RequiresNullTerminator,
- bool IsVolatile) {
+ErrorOr<std::unique_ptr<MemoryBuffer>>
+RealFile::getBuffer(const Twine &Name, int64_t FileSize,
+ bool RequiresNullTerminator, bool IsVolatile) {
assert(FD != -1 && "cannot get buffer for closed file");
- ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
- MemoryBuffer::getOpenFile(FD, Name.str().c_str(), FileSize,
- RequiresNullTerminator, IsVolatile);
- if (std::error_code EC = BufferOrErr.getError())
- return EC;
- Result = std::move(BufferOrErr.get());
- return std::error_code();
+ return MemoryBuffer::getOpenFile(FD, Name, FileSize, RequiresNullTerminator,
+ IsVolatile);
}
// FIXME: This is terrible, we need this for ::close.
@@ -161,8 +151,7 @@ namespace {
class RealFileSystem : public FileSystem {
public:
ErrorOr<Status> status(const Twine &Path) override;
- std::error_code openFileForRead(const Twine &Path,
- std::unique_ptr<File> &Result) override;
+ ErrorOr<std::unique_ptr<File>> openFileForRead(const Twine &Path) override;
directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override;
};
} // end anonymous namespace
@@ -176,14 +165,14 @@ ErrorOr<Status> RealFileSystem::status(c
return Result;
}
-std::error_code RealFileSystem::openFileForRead(const Twine &Name,
- std::unique_ptr<File> &Result) {
+ErrorOr<std::unique_ptr<File>>
+RealFileSystem::openFileForRead(const Twine &Name) {
int FD;
if (std::error_code EC = sys::fs::openFileForRead(Name, FD))
return EC;
- Result.reset(new RealFile(FD));
+ std::unique_ptr<File> Result(new RealFile(FD));
Result->setName(Name.str());
- return std::error_code();
+ return std::move(Result);
}
IntrusiveRefCntPtr<FileSystem> vfs::getRealFileSystem() {
@@ -252,14 +241,13 @@ ErrorOr<Status> OverlayFileSystem::statu
return make_error_code(llvm::errc::no_such_file_or_directory);
}
-std::error_code
-OverlayFileSystem::openFileForRead(const llvm::Twine &Path,
- std::unique_ptr<File> &Result) {
+ErrorOr<std::unique_ptr<File>>
+OverlayFileSystem::openFileForRead(const llvm::Twine &Path) {
// FIXME: handle symlinks that cross file systems
for (iterator I = overlays_begin(), E = overlays_end(); I != E; ++I) {
- std::error_code EC = (*I)->openFileForRead(Path, Result);
- if (!EC || EC != llvm::errc::no_such_file_or_directory)
- return EC;
+ auto Result = (*I)->openFileForRead(Path);
+ if (Result || Result.getError() != llvm::errc::no_such_file_or_directory)
+ return Result;
}
return make_error_code(llvm::errc::no_such_file_or_directory);
}
@@ -520,8 +508,7 @@ public:
IntrusiveRefCntPtr<FileSystem> ExternalFS);
ErrorOr<Status> status(const Twine &Path) override;
- std::error_code openFileForRead(const Twine &Path,
- std::unique_ptr<File> &Result) override;
+ ErrorOr<std::unique_ptr<File>> openFileForRead(const Twine &Path) override;
directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override{
ErrorOr<Entry *> E = lookupPath(Dir);
@@ -969,9 +956,7 @@ ErrorOr<Status> VFSFromYAML::status(cons
return status(Path, *Result);
}
-std::error_code
-VFSFromYAML::openFileForRead(const Twine &Path,
- std::unique_ptr<vfs::File> &Result) {
+ErrorOr<std::unique_ptr<File>> VFSFromYAML::openFileForRead(const Twine &Path) {
ErrorOr<Entry *> E = lookupPath(Path);
if (!E)
return E.getError();
@@ -980,14 +965,14 @@ VFSFromYAML::openFileForRead(const Twine
if (!F) // FIXME: errc::not_a_file?
return make_error_code(llvm::errc::invalid_argument);
- if (std::error_code EC =
- ExternalFS->openFileForRead(F->getExternalContentsPath(), Result))
- return EC;
+ auto Result = ExternalFS->openFileForRead(F->getExternalContentsPath());
+ if (!Result)
+ return Result;
if (!F->useExternalName(UseExternalNames))
- Result->setName(Path.str());
+ (*Result)->setName(Path.str());
- return std::error_code();
+ return Result;
}
IntrusiveRefCntPtr<FileSystem>
Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Sun Oct 26 17:44:13 2014
@@ -647,18 +647,15 @@ CodeGenAction::CreateASTConsumer(Compile
// loaded from bitcode, do so now.
const std::string &LinkBCFile = CI.getCodeGenOpts().LinkBitcodeFile;
if (!LinkModuleToUse && !LinkBCFile.empty()) {
- std::string ErrorStr;
-
- std::unique_ptr<llvm::MemoryBuffer> BCBuf =
- CI.getFileManager().getBufferForFile(LinkBCFile, &ErrorStr);
+ auto BCBuf = CI.getFileManager().getBufferForFile(LinkBCFile);
if (!BCBuf) {
CI.getDiagnostics().Report(diag::err_cannot_open_file)
- << LinkBCFile << ErrorStr;
+ << LinkBCFile << BCBuf.getError().message();
return nullptr;
}
ErrorOr<llvm::Module *> ModuleOrErr =
- getLazyBitcodeModule(std::move(BCBuf), *VMContext);
+ getLazyBitcodeModule(std::move(*BCBuf), *VMContext);
if (std::error_code EC = ModuleOrErr.getError()) {
CI.getDiagnostics().Report(diag::err_cannot_open_file)
<< LinkBCFile << EC.message();
Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Sun Oct 26 17:44:13 2014
@@ -638,7 +638,12 @@ ASTDeserializationListener *ASTUnit::get
std::unique_ptr<llvm::MemoryBuffer>
ASTUnit::getBufferForFile(StringRef Filename, std::string *ErrorStr) {
assert(FileMgr);
- return FileMgr->getBufferForFile(Filename, ErrorStr);
+ auto Buffer = FileMgr->getBufferForFile(Filename);
+ if (Buffer)
+ return std::move(*Buffer);
+ if (ErrorStr)
+ *ErrorStr = Buffer.getError().message();
+ return nullptr;
}
/// \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=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Sun Oct 26 17:44:13 2014
@@ -717,14 +717,14 @@ bool CompilerInstance::InitializeSourceM
// pick up the correct size, and simply override their contents as we do for
// STDIN.
if (File->isNamedPipe()) {
- std::string ErrorStr;
- if (std::unique_ptr<llvm::MemoryBuffer> MB =
- FileMgr.getBufferForFile(File, &ErrorStr, /*isVolatile=*/true)) {
+ auto MB = FileMgr.getBufferForFile(File, /*isVolatile=*/true);
+ if (MB) {
// Create a new virtual file that will have the correct size.
- File = FileMgr.getVirtualFile(InputFile, MB->getBufferSize(), 0);
- SourceMgr.overrideFileContents(File, std::move(MB));
+ File = FileMgr.getVirtualFile(InputFile, (*MB)->getBufferSize(), 0);
+ SourceMgr.overrideFileContents(File, std::move(*MB));
} else {
- Diags.Report(diag::err_cannot_open_file) << InputFile << ErrorStr;
+ Diags.Report(diag::err_cannot_open_file) << InputFile
+ << MB.getError().message();
return false;
}
}
Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Sun Oct 26 17:44:13 2014
@@ -683,10 +683,10 @@ void PrintPreambleAction::ExecuteAction(
}
CompilerInstance &CI = getCompilerInstance();
- if (std::unique_ptr<llvm::MemoryBuffer> Buffer =
- CI.getFileManager().getBufferForFile(getCurrentFile())) {
+ auto Buffer = CI.getFileManager().getBufferForFile(getCurrentFile());
+ if (Buffer) {
unsigned Preamble =
- Lexer::ComputePreamble(Buffer->getBuffer(), CI.getLangOpts()).first;
- llvm::outs().write(Buffer->getBufferStart(), Preamble);
+ Lexer::ComputePreamble((*Buffer)->getBuffer(), CI.getLangOpts()).first;
+ llvm::outs().write((*Buffer)->getBufferStart(), Preamble);
}
}
Modified: cfe/trunk/lib/Frontend/SerializedDiagnosticReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/SerializedDiagnosticReader.cpp?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/SerializedDiagnosticReader.cpp (original)
+++ cfe/trunk/lib/Frontend/SerializedDiagnosticReader.cpp Sun Oct 26 17:44:13 2014
@@ -21,13 +21,13 @@ std::error_code SerializedDiagnosticRead
FileSystemOptions FO;
FileManager FileMgr(FO);
- std::unique_ptr<llvm::MemoryBuffer> Buffer = FileMgr.getBufferForFile(File);
+ auto Buffer = FileMgr.getBufferForFile(File);
if (!Buffer)
return SDError::CouldNotLoad;
llvm::BitstreamReader StreamFile;
- StreamFile.init((const unsigned char *)Buffer->getBufferStart(),
- (const unsigned char *)Buffer->getBufferEnd());
+ StreamFile.init((const unsigned char *)(*Buffer)->getBufferStart(),
+ (const unsigned char *)(*Buffer)->getBufferEnd());
llvm::BitstreamCursor Stream;
Stream.init(StreamFile);
Modified: cfe/trunk/lib/Lex/HeaderMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderMap.cpp?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderMap.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderMap.cpp Sun Oct 26 17:44:13 2014
@@ -81,10 +81,9 @@ const HeaderMap *HeaderMap::Create(const
unsigned FileSize = FE->getSize();
if (FileSize <= sizeof(HMapHeader)) return nullptr;
- std::unique_ptr<const llvm::MemoryBuffer> FileBuffer =
- FM.getBufferForFile(FE);
+ auto FileBuffer = FM.getBufferForFile(FE);
if (!FileBuffer) return nullptr; // Unreadable file?
- const char *FileStart = FileBuffer->getBufferStart();
+ const char *FileStart = (*FileBuffer)->getBufferStart();
// We know the file is at least as big as the header, check it now.
const HMapHeader *Header = reinterpret_cast<const HMapHeader*>(FileStart);
@@ -104,7 +103,7 @@ const HeaderMap *HeaderMap::Create(const
if (Header->Reserved != 0) return nullptr;
// Okay, everything looks good, create the header map.
- return new HeaderMap(std::move(FileBuffer), NeedsByteSwap);
+ return new HeaderMap(std::move(*FileBuffer), NeedsByteSwap);
}
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Sun Oct 26 17:44:13 2014
@@ -4074,19 +4074,18 @@ std::string ASTReader::getOriginalSource
FileManager &FileMgr,
DiagnosticsEngine &Diags) {
// Open the AST file.
- std::string ErrStr;
- std::unique_ptr<llvm::MemoryBuffer> Buffer =
- FileMgr.getBufferForFile(ASTFileName, &ErrStr);
+ auto Buffer = FileMgr.getBufferForFile(ASTFileName);
if (!Buffer) {
- Diags.Report(diag::err_fe_unable_to_read_pch_file) << ASTFileName << ErrStr;
+ Diags.Report(diag::err_fe_unable_to_read_pch_file)
+ << ASTFileName << Buffer.getError().message();
return std::string();
}
// Initialize the stream
llvm::BitstreamReader StreamFile;
BitstreamCursor Stream;
- StreamFile.init((const unsigned char *)Buffer->getBufferStart(),
- (const unsigned char *)Buffer->getBufferEnd());
+ StreamFile.init((const unsigned char *)(*Buffer)->getBufferStart(),
+ (const unsigned char *)(*Buffer)->getBufferEnd());
Stream.init(StreamFile);
// Sniff for the signature.
@@ -4163,9 +4162,7 @@ bool ASTReader::readASTFileControlBlock(
FileManager &FileMgr,
ASTReaderListener &Listener) {
// Open the AST file.
- std::string ErrStr;
- std::unique_ptr<llvm::MemoryBuffer> Buffer =
- FileMgr.getBufferForFile(Filename, &ErrStr);
+ auto Buffer = FileMgr.getBufferForFile(Filename);
if (!Buffer) {
return true;
}
@@ -4173,8 +4170,8 @@ bool ASTReader::readASTFileControlBlock(
// Initialize the stream
llvm::BitstreamReader StreamFile;
BitstreamCursor Stream;
- StreamFile.init((const unsigned char *)Buffer->getBufferStart(),
- (const unsigned char *)Buffer->getBufferEnd());
+ StreamFile.init((const unsigned char *)(*Buffer)->getBufferStart(),
+ (const unsigned char *)(*Buffer)->getBufferEnd());
Stream.init(StreamFile);
// Sniff for the signature.
Modified: cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp (original)
+++ cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp Sun Oct 26 17:44:13 2014
@@ -494,9 +494,7 @@ namespace {
bool GlobalModuleIndexBuilder::loadModuleFile(const FileEntry *File) {
// Open the module file.
- std::string ErrorStr;
- std::unique_ptr<llvm::MemoryBuffer> Buffer =
- FileMgr.getBufferForFile(File, &ErrorStr, /*isVolatile=*/true);
+ auto Buffer = FileMgr.getBufferForFile(File, /*isVolatile=*/true);
if (!Buffer) {
return true;
}
@@ -504,8 +502,8 @@ bool GlobalModuleIndexBuilder::loadModul
// Initialize the input stream
llvm::BitstreamReader InStreamFile;
llvm::BitstreamCursor InStream;
- InStreamFile.init((const unsigned char *)Buffer->getBufferStart(),
- (const unsigned char *)Buffer->getBufferEnd());
+ InStreamFile.init((const unsigned char *)(*Buffer)->getBufferStart(),
+ (const unsigned char *)(*Buffer)->getBufferEnd());
InStream.init(InStreamFile);
// Sniff for the signature.
Modified: cfe/trunk/lib/Serialization/ModuleManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ModuleManager.cpp?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ModuleManager.cpp (original)
+++ cfe/trunk/lib/Serialization/ModuleManager.cpp Sun Oct 26 17:44:13 2014
@@ -107,27 +107,26 @@ ModuleManager::addModule(StringRef FileN
New->Buffer = std::move(Buffer);
} else {
// Open the AST file.
- std::error_code ec;
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buf(
+ (std::error_code()));
if (FileName == "-") {
- llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buf =
- llvm::MemoryBuffer::getSTDIN();
- ec = Buf.getError();
- if (ec)
- ErrorStr = ec.message();
- else
- New->Buffer = std::move(Buf.get());
+ Buf = llvm::MemoryBuffer::getSTDIN();
} else {
// Leave the FileEntry open so if it gets read again by another
// 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 = FileMgr.getBufferForFile(New->File, &ErrorStr,
- /*IsVolatile*/ false,
- /*ShouldClose*/ false);
+ Buf = FileMgr.getBufferForFile(New->File,
+ /*IsVolatile=*/false,
+ /*ShouldClose=*/false);
}
-
- if (!New->Buffer)
+
+ if (!Buf) {
+ ErrorStr = Buf.getError().message();
return Missing;
+ }
+
+ New->Buffer = std::move(*Buf);
}
// Initialize the stream
Modified: cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp (original)
+++ cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Sun Oct 26 17:44:13 2014
@@ -39,14 +39,8 @@ public:
return make_error_code(llvm::errc::no_such_file_or_directory);
return I->second;
}
- std::error_code openFileForRead(const Twine &Path,
- std::unique_ptr<vfs::File> &Result) override {
- llvm_unreachable("unimplemented");
- }
- std::error_code getBufferForFile(const Twine &Name,
- std::unique_ptr<MemoryBuffer> &Result,
- int64_t FileSize = -1,
- bool RequiresNullTerminator = true) {
+ ErrorOr<std::unique_ptr<vfs::File>>
+ openFileForRead(const Twine &Path) override {
llvm_unreachable("unimplemented");
}
Modified: cfe/trunk/unittests/Tooling/RefactoringTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RefactoringTest.cpp?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/RefactoringTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/RefactoringTest.cpp Sun Oct 26 17:44:13 2014
@@ -251,9 +251,8 @@ public:
// descriptor, which might not see the changes made.
// FIXME: Figure out whether there is a way to get the SourceManger to
// reopen the file.
- std::unique_ptr<const llvm::MemoryBuffer> FileBuffer(
- Context.Files.getBufferForFile(Path, nullptr));
- return FileBuffer->getBuffer();
+ auto FileBuffer = Context.Files.getBufferForFile(Path);
+ return (*FileBuffer)->getBuffer();
}
llvm::StringMap<std::string> TemporaryFiles;
Modified: cfe/trunk/unittests/Tooling/RewriterTestContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RewriterTestContext.h?rev=220657&r1=220656&r2=220657&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/RewriterTestContext.h (original)
+++ cfe/trunk/unittests/Tooling/RewriterTestContext.h Sun Oct 26 17:44:13 2014
@@ -101,9 +101,8 @@ class RewriterTestContext {
// descriptor, which might not see the changes made.
// FIXME: Figure out whether there is a way to get the SourceManger to
// reopen the file.
- std::unique_ptr<const llvm::MemoryBuffer> FileBuffer(
- Files.getBufferForFile(Path, nullptr));
- return FileBuffer->getBuffer();
+ auto FileBuffer = Files.getBufferForFile(Path);
+ return (*FileBuffer)->getBuffer();
}
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
More information about the cfe-commits
mailing list