diff --git a/llvm/include/llvm/Transforms/IPO/FunctionImport.h b/llvm/include/llvm/Transforms/IPO/FunctionImport.h --- a/llvm/include/llvm/Transforms/IPO/FunctionImport.h +++ b/llvm/include/llvm/Transforms/IPO/FunctionImport.h @@ -111,7 +111,8 @@ ClearDSOLocalOnDeclarations(ClearDSOLocalOnDeclarations) {} /// Import functions in Module \p M based on the supplied import list. - Expected importFunctions(Module &M, const ImportMapTy &ImportList); + Expected importFunctions(Module &M, const ImportMapTy &ImportList, + bool AssumeValidDebugInfo); private: /// The summaries index used to trigger importing. diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -648,7 +648,10 @@ FunctionImporter Importer(CombinedIndex, ModuleLoader, ClearDSOLocalOnDeclarations); - if (Error Err = Importer.importFunctions(Mod, ImportList).takeError()) + if (Error Err = + Importer + .importFunctions(Mod, ImportList, /*AssumeValidDebugInfo=*/true) + .takeError()) return Err; if (Conf.PostImportModuleHook && !Conf.PostImportModuleHook(Task, Mod)) diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -221,7 +221,8 @@ }; FunctionImporter Importer(Index, Loader, ClearDSOLocalOnDeclarations); - Expected Result = Importer.importFunctions(TheModule, ImportList); + Expected Result = Importer.importFunctions( + TheModule, ImportList, /*AssumeValidDebugInfo=*/true); if (!Result) { handleAllErrors(Result.takeError(), [&](ErrorInfoBase &EIB) { SMDiagnostic Err = SMDiagnostic(TheModule.getModuleIdentifier(), diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -1252,7 +1252,8 @@ // Automatically import functions in Module \p DestModule based on the summaries // index. Expected FunctionImporter::importFunctions( - Module &DestModule, const FunctionImporter::ImportMapTy &ImportList) { + Module &DestModule, const FunctionImporter::ImportMapTy &ImportList, + bool AssumeValidDebugInfo) { LLVM_DEBUG(dbgs() << "Starting import for Module " << DestModule.getModuleIdentifier() << "\n"); unsigned ImportedCount = 0, ImportedGVCount = 0; @@ -1351,7 +1352,8 @@ // Upgrade debug info after we're done materializing all the globals and we // have loaded all the required metadata! - UpgradeDebugInfo(*SrcModule); + if (!AssumeValidDebugInfo) + UpgradeDebugInfo(*SrcModule); // Set the partial sample profile ratio in the profile summary module flag // of the imported source module, if applicable, so that the profile summary @@ -1443,7 +1445,8 @@ }; FunctionImporter Importer(*Index, ModuleLoader, /*ClearDSOLocalOnDeclarations=*/false); - Expected Result = Importer.importFunctions(M, ImportList); + Expected Result = + Importer.importFunctions(M, ImportList, /*AssumeValidDebugInfo=*/false); // FIXME: Probably need to propagate Errors through the pass manager. if (!Result) { diff --git a/llvm/test/LTO/X86/strip-debug-info.ll b/llvm/test/LTO/X86/strip-debug-info.ll --- a/llvm/test/LTO/X86/strip-debug-info.ll +++ b/llvm/test/LTO/X86/strip-debug-info.ll @@ -5,25 +5,6 @@ ; RUN: -o %t.o %t.bc 2>&1 | \ ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-WARN ; RUN: llvm-nm %t.o | FileCheck %s -; ---- Thin LTO (codegen only) ------------------------------ -; RUN: llvm-lto -thinlto -thinlto-action=codegen \ -; RUN: %t.bc -disable-verify 2>&1 | \ -; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-WARN -; ---- Thin LTO (optimize, strip main file) ----------------- -; RUN: opt -disable-verify -disable-upgrade-debug-info -module-summary %s -o %t.bc -; RUN: opt -disable-verify -disable-upgrade-debug-info -module-summary %S/Inputs/strip-debug-info-bar.ll \ -; RUN: -o %t2.bc -; RUN: llvm-lto -thinlto -thinlto-action=run \ -; RUN: %t.bc -disable-verify 2>&1 | \ -; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-WARN -; ---- Thin LTO (optimize, strip imported file) ------------- -; RUN: opt -module-summary %t.bc -o %t-stripped.bc -; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t-stripped.bc %t2.bc -; RUN: llvm-lto -thinlto -thinlto-action=import \ -; RUN: -thinlto-index=%t.index.bc \ -; RUN: -exported-symbol foo -exported-symbol _foo \ -; RUN: %t-stripped.bc -disable-verify 2>&1 | \ -; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-WARN ; CHECK-WARN: warning{{.*}} ignoring invalid debug info ; CHECK-WARN-NOT: Broken module found diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp --- a/llvm/tools/llvm-link/llvm-link.cpp +++ b/llvm/tools/llvm-link/llvm-link.cpp @@ -368,7 +368,8 @@ }; FunctionImporter Importer(*Index, CachedModuleLoader, /*ClearDSOLocalOnDeclarations=*/false); - ExitOnErr(Importer.importFunctions(DestModule, ImportList)); + ExitOnErr(Importer.importFunctions(DestModule, ImportList, + /*AssumeValidDebugInfo=*/false)); return true; }