diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/BackendUtil.cpp | 16 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenAction.cpp | 19 |
2 files changed, 25 insertions, 10 deletions
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index fc8b5523520..384800e9510 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1025,16 +1025,22 @@ Expected<BitcodeModule> clang::FindThinLTOModule(MemoryBufferRef MBRef) { // The bitcode file may contain multiple modules, we want the one that is // marked as being the ThinLTO module. - for (BitcodeModule &BM : *BMsOrErr) { - Expected<BitcodeLTOInfo> LTOInfo = BM.getLTOInfo(); - if (LTOInfo && LTOInfo->IsThinLTO) - return BM; - } + if (const BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr)) + return *Bm; return make_error<StringError>("Could not find module summary", inconvertibleErrorCode()); } +BitcodeModule *clang::FindThinLTOModule(MutableArrayRef<BitcodeModule> BMs) { + for (BitcodeModule &BM : BMs) { + Expected<BitcodeLTOInfo> LTOInfo = BM.getLTOInfo(); + if (LTOInfo && LTOInfo->IsThinLTO) + return &BM; + } + return nullptr; +} + static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, Module *M, const HeaderSearchOptions &HeaderOpts, const CodeGenOptions &CGOpts, diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 6ca69d63cdc..13fa4a83308 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -947,12 +947,21 @@ std::unique_ptr<llvm::Module> CodeGenAction::loadModule(MemoryBufferRef MBRef) { return {}; }; - Expected<llvm::BitcodeModule> BMOrErr = FindThinLTOModule(MBRef); - if (!BMOrErr) - return DiagErrors(BMOrErr.takeError()); - + Expected<std::vector<BitcodeModule>> BMsOrErr = getBitcodeModuleList(MBRef); + if (!BMsOrErr) + return DiagErrors(BMsOrErr.takeError()); + BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr); + // We have nothing to do if the file contains no ThinLTO module. This is + // possible if ThinLTO compilation was not able to split module. Content of + // the file was already processed by indexing and will be passed to the + // linker using merged object file. + if (!Bm) { + auto M = llvm::make_unique<llvm::Module>("empty", *VMContext); + M->setTargetTriple(CI.getTargetOpts().Triple); + return M; + } Expected<std::unique_ptr<llvm::Module>> MOrErr = - BMOrErr->parseModule(*VMContext); + Bm->parseModule(*VMContext); if (!MOrErr) return DiagErrors(MOrErr.takeError()); return std::move(*MOrErr); |