diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2016-11-11 19:50:39 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2016-11-11 19:50:39 +0000 |
commit | 6de481a3786b5b0409eddeee4b99a148e3f0f3f3 (patch) | |
tree | e2a11dcd251688636adc5f1a4657c15aef1d0aad /llvm/lib/Transforms/IPO/FunctionImport.cpp | |
parent | cd513a41c17a3591e764b1ff986ae501a28cc5f5 (diff) | |
download | bcm5719-llvm-6de481a3786b5b0409eddeee4b99a148e3f0f3f3.tar.gz bcm5719-llvm-6de481a3786b5b0409eddeee4b99a148e3f0f3f3.zip |
Bitcode: Change getModuleSummaryIndex() to return an llvm::Expected.
Differential Revision: https://reviews.llvm.org/D26539
llvm-svn: 286624
Diffstat (limited to 'llvm/lib/Transforms/IPO/FunctionImport.cpp')
-rw-r--r-- | llvm/lib/Transforms/IPO/FunctionImport.cpp | 41 |
1 files changed, 6 insertions, 35 deletions
diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index 8b252507f0e..2a351b30119 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -739,36 +739,6 @@ static cl::opt<std::string> SummaryFile("summary-file", cl::desc("The summary file to use for function importing.")); -static void diagnosticHandler(const DiagnosticInfo &DI) { - raw_ostream &OS = errs(); - DiagnosticPrinterRawOStream DP(OS); - DI.print(DP); - OS << '\n'; -} - -/// Parse the summary index out of an IR file and return the summary -/// index object if found, or nullptr if not. -static std::unique_ptr<ModuleSummaryIndex> getModuleSummaryIndexForFile( - StringRef Path, std::string &Error, - const DiagnosticHandlerFunction &DiagnosticHandler) { - std::unique_ptr<MemoryBuffer> Buffer; - ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr = - MemoryBuffer::getFile(Path); - if (std::error_code EC = BufferOrErr.getError()) { - Error = EC.message(); - return nullptr; - } - Buffer = std::move(BufferOrErr.get()); - ErrorOr<std::unique_ptr<object::ModuleSummaryIndexObjectFile>> ObjOrErr = - object::ModuleSummaryIndexObjectFile::create(Buffer->getMemBufferRef(), - DiagnosticHandler); - if (std::error_code EC = ObjOrErr.getError()) { - Error = EC.message(); - return nullptr; - } - return (*ObjOrErr)->takeIndex(); -} - static bool doImportingForModule(Module &M, const ModuleSummaryIndex *Index) { if (SummaryFile.empty() && !Index) report_fatal_error("error: -function-import requires -summary-file or " @@ -777,13 +747,14 @@ static bool doImportingForModule(Module &M, const ModuleSummaryIndex *Index) { if (!SummaryFile.empty()) { if (Index) report_fatal_error("error: -summary-file and index from frontend\n"); - std::string Error; - IndexPtr = - getModuleSummaryIndexForFile(SummaryFile, Error, diagnosticHandler); - if (!IndexPtr) { - errs() << "Error loading file '" << SummaryFile << "': " << Error << "\n"; + Expected<std::unique_ptr<ModuleSummaryIndex>> IndexPtrOrErr = + getModuleSummaryIndexForFile(SummaryFile); + if (!IndexPtrOrErr) { + logAllUnhandledErrors(IndexPtrOrErr.takeError(), errs(), + "Error loading file '" + SummaryFile + "': "); return false; } + IndexPtr = std::move(*IndexPtrOrErr); Index = IndexPtr.get(); } |