diff --git a/include/llvm/Linker/Linker.h b/include/llvm/Linker/Linker.h index f09cf1029a4..2b051e6d15c 100644 --- a/include/llvm/Linker/Linker.h +++ b/include/llvm/Linker/Linker.h @@ -69,8 +69,7 @@ public: /// Perform in-place global value handling on the given Module for /// exported local functions renamed and promoted for ThinLTO. -std::unique_ptr renameModuleForThinLTO(std::unique_ptr M, - const FunctionInfoIndex *Index); +bool renameModuleForThinLTO(Module &M, const FunctionInfoIndex *Index); } // End llvm namespace diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 653f639f28e..6ffa71e1477 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -863,13 +863,9 @@ bool Linker::linkModules(Module &Dest, std::unique_ptr Src, return L.linkInModule(std::move(Src), Flags); } -std::unique_ptr -llvm::renameModuleForThinLTO(std::unique_ptr M, - const FunctionInfoIndex *Index) { - ThinLTOGlobalProcessing ThinLTOProcessing(*M, Index); - if (ThinLTOProcessing.run()) - return nullptr; - return M; +bool llvm::renameModuleForThinLTO(Module &M, const FunctionInfoIndex *Index) { + ThinLTOGlobalProcessing ThinLTOProcessing(M, Index); + return ThinLTOProcessing.run(); } //===----------------------------------------------------------------------===// diff --git a/lib/Transforms/IPO/FunctionImport.cpp b/lib/Transforms/IPO/FunctionImport.cpp index d194c5e424d..11418edbf7b 100644 --- a/lib/Transforms/IPO/FunctionImport.cpp +++ b/lib/Transforms/IPO/FunctionImport.cpp @@ -413,14 +413,19 @@ public: Index = IndexPtr.get(); } + // First we need to promote to global scope and rename any local values that + // are potentially exported to other modules. + if (renameModuleForThinLTO(M, Index)) { + errs() << "Error renaming module\n"; + return false; + } + // Perform the import now. auto ModuleLoader = [&M](StringRef Identifier) { return loadFile(Identifier, M.getContext()); }; FunctionImporter Importer(*Index, ModuleLoader); return Importer.importFunctions(M); - - return false; } }; } // anonymous namespace