diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Basic/FileManager.cpp | 52 | ||||
-rw-r--r-- | clang/lib/Basic/FileSystemStatCache.cpp | 9 | ||||
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 21 | ||||
-rw-r--r-- | clang/lib/Basic/VirtualFileSystem.cpp | 83 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenAction.cpp | 9 | ||||
-rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 7 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 12 | ||||
-rw-r--r-- | clang/lib/Frontend/FrontendActions.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Frontend/SerializedDiagnosticReader.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Lex/HeaderMap.cpp | 7 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 19 | ||||
-rw-r--r-- | clang/lib/Serialization/GlobalModuleIndex.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Serialization/ModuleManager.cpp | 25 |
13 files changed, 113 insertions, 153 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 87844864a85..91681edcc51 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -399,12 +399,9 @@ void FileManager::FixupRelativePath(SmallVectorImpl<char> &path) const { 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 FileEntry *Entry, std::string *ErrorStr, 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 FileEntry *Entry, std::string *ErrorStr, // 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, diff --git a/clang/lib/Basic/FileSystemStatCache.cpp b/clang/lib/Basic/FileSystemStatCache.cpp index 7515cfb440a..83e42bdb848 100644 --- a/clang/lib/Basic/FileSystemStatCache.cpp +++ b/clang/lib/Basic/FileSystemStatCache.cpp @@ -78,21 +78,20 @@ bool FileSystemStatCache::get(const char *Path, FileData &Data, bool isFile, // // 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. diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 64504064535..69917830562 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -94,11 +94,9 @@ llvm::MemoryBuffer *ContentCache::getBuffer(DiagnosticsEngine &Diag, 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::getBuffer(DiagnosticsEngine &Diag, // 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::getBuffer(DiagnosticsEngine &Diag, 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()) { diff --git a/clang/lib/Basic/VirtualFileSystem.cpp b/clang/lib/Basic/VirtualFileSystem.cpp index df446bbcd51..8dc7006f2de 100644 --- a/clang/lib/Basic/VirtualFileSystem.cpp +++ b/clang/lib/Basic/VirtualFileSystem.cpp @@ -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; - - std::error_code EC = - F->getBuffer(Name, Result, FileSize, RequiresNullTerminator, IsVolatile); - 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(); + + 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(const Twine &Path) { 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::status(const Twine &Path) { 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(const Twine &Path) { 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 &Path, 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> diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 146c550c678..044eec643bb 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -647,18 +647,15 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { // 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(); diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 19fafa3370a..1d8c6a15586 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -638,7 +638,12 @@ ASTDeserializationListener *ASTUnit::getDeserializationListener() { 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. diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 1f336b48e29..03ab20b083e 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -717,14 +717,14 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input, // 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; } } diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 99cd4a2e6d6..6634e19fc2c 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -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); } } diff --git a/clang/lib/Frontend/SerializedDiagnosticReader.cpp b/clang/lib/Frontend/SerializedDiagnosticReader.cpp index 6d692e4059e..197132d6162 100644 --- a/clang/lib/Frontend/SerializedDiagnosticReader.cpp +++ b/clang/lib/Frontend/SerializedDiagnosticReader.cpp @@ -21,13 +21,13 @@ std::error_code SerializedDiagnosticReader::readDiagnostics(StringRef File) { 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); diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp index c86569f74a6..09d53846d4c 100644 --- a/clang/lib/Lex/HeaderMap.cpp +++ b/clang/lib/Lex/HeaderMap.cpp @@ -81,10 +81,9 @@ const HeaderMap *HeaderMap::Create(const FileEntry *FE, FileManager &FM) { 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 FileEntry *FE, FileManager &FM) { 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); } //===----------------------------------------------------------------------===// diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 1d7efb81827..29fa263bda8 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -4074,19 +4074,18 @@ std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, 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(StringRef Filename, 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(StringRef Filename, // 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. diff --git a/clang/lib/Serialization/GlobalModuleIndex.cpp b/clang/lib/Serialization/GlobalModuleIndex.cpp index 121478ce052..a67f9f36dbb 100644 --- a/clang/lib/Serialization/GlobalModuleIndex.cpp +++ b/clang/lib/Serialization/GlobalModuleIndex.cpp @@ -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::loadModuleFile(const FileEntry *File) { // 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. diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp index c76a318805e..3baaa0a4b28 100644 --- a/clang/lib/Serialization/ModuleManager.cpp +++ b/clang/lib/Serialization/ModuleManager.cpp @@ -107,27 +107,26 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type, 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 |