diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2017-01-26 21:09:48 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2017-01-26 21:09:48 +0000 |
commit | f5d1712189a2c4858425cf35f8ed597645af48cc (patch) | |
tree | ff87e9d9438847c52bc177735616403d29ca9c1d /clang/lib/CodeGen/CodeGenAction.cpp | |
parent | b0d96d327e09d0ac13b34078e7413709f4815b2d (diff) | |
download | llvm-f5d1712189a2c4858425cf35f8ed597645af48cc.zip llvm-f5d1712189a2c4858425cf35f8ed597645af48cc.tar.gz llvm-f5d1712189a2c4858425cf35f8ed597645af48cc.tar.bz2 |
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
Diffstat (limited to 'clang/lib/CodeGen/CodeGenAction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenAction.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 27b0d0b..3828c5e 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -860,10 +860,31 @@ std::unique_ptr<llvm::Module> 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<llvm::Module> { + unsigned DiagID = + CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0"); + handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) { + CI.getDiagnostics().Report(DiagID) << EIB.message(); + }); + return {}; + }; + + Expected<llvm::BitcodeModule> BMOrErr = FindThinLTOModule(MBRef); + if (!BMOrErr) + return DiagErrors(BMOrErr.takeError()); + + Expected<std::unique_ptr<llvm::Module>> MOrErr = + BMOrErr->parseModule(*VMContext); + if (!MOrErr) + return DiagErrors(MOrErr.takeError()); + return std::move(*MOrErr); + } + llvm::SMDiagnostic Err; if (std::unique_ptr<llvm::Module> M = parseIR(MBRef, Err, *VMContext)) return M; |