diff options
| -rw-r--r-- | clang/lib/CodeGen/CodeGenAction.cpp | 25 | ||||
| -rw-r--r-- | clang/test/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | clang/test/CodeGen/thinlto-multi-module.ll | 20 |
3 files changed, 44 insertions, 2 deletions
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<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; diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt index 050addcb4fd..0fd8f57f92a 100644 --- a/clang/test/CMakeLists.txt +++ b/clang/test/CMakeLists.txt @@ -86,6 +86,7 @@ if( NOT CLANG_BUILT_STANDALONE ) FileCheck count not llc llvm-bcanalyzer + llvm-cat llvm-dis llvm-nm llvm-objdump diff --git a/clang/test/CodeGen/thinlto-multi-module.ll b/clang/test/CodeGen/thinlto-multi-module.ll new file mode 100644 index 00000000000..072c47379b4 --- /dev/null +++ b/clang/test/CodeGen/thinlto-multi-module.ll @@ -0,0 +1,20 @@ +; RUN: opt -module-summary -o %t1.o %s +; RUN: llvm-lto -thinlto -o %t %t1.o + +; RUN: opt -o %t2.o %S/Inputs/thinlto_backend.ll +; RUN: llvm-cat -b -o %t1cat.o %t1.o %t2.o +; RUN: cp %t1cat.o %t1.o +; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc +; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s +; CHECK-OBJ: T f1 +; CHECK-OBJ: U f2 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare void @f2() + +define void @f1() { + call void @f2() + ret void +} |

