From f5d1712189a2c4858425cf35f8ed597645af48cc Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Thu, 26 Jan 2017 21:09:48 +0000 Subject: IRGen: When loading the main module in the distributed ThinLTO backend, look for the module containing the summary. Differential Revision: https://reviews.llvm.org/D29067 llvm-svn: 293209 --- clang/lib/CodeGen/CodeGenAction.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenAction.cpp') diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 27b0d0b673f..3828c5e1701 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -860,10 +860,31 @@ std::unique_ptr CodeGenAction::loadModule(MemoryBufferRef MBRef) { SourceManager &SM = CI.getSourceManager(); // For ThinLTO backend invocations, ensure that the context - // merges types based on ODR identifiers. - if (!CI.getCodeGenOpts().ThinLTOIndexFile.empty()) + // merges types based on ODR identifiers. We also need to read + // the correct module out of a multi-module bitcode file. + if (!CI.getCodeGenOpts().ThinLTOIndexFile.empty()) { VMContext->enableDebugTypeODRUniquing(); + auto DiagErrors = [&](Error E) -> std::unique_ptr { + unsigned DiagID = + CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0"); + handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) { + CI.getDiagnostics().Report(DiagID) << EIB.message(); + }); + return {}; + }; + + Expected BMOrErr = FindThinLTOModule(MBRef); + if (!BMOrErr) + return DiagErrors(BMOrErr.takeError()); + + Expected> MOrErr = + BMOrErr->parseModule(*VMContext); + if (!MOrErr) + return DiagErrors(MOrErr.takeError()); + return std::move(*MOrErr); + } + llvm::SMDiagnostic Err; if (std::unique_ptr M = parseIR(MBRef, Err, *VMContext)) return M; -- cgit v1.2.3