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 @@ -82,6 +82,11 @@ "import-cutoff", cl::init(-1), cl::Hidden, cl::value_desc("N"), cl::desc("Only import first N functions if N>=0 (default -1)")); +static cl::opt InputBitcodeBuiltFromSameVersion( + "bitcode-built-from-same-version", cl::init(false), cl::Hidden, + cl::desc("Assume that imported functions are built at the same revision of " + "LLVM as this consumer to avoid upgrading debug info")); + static cl::opt ForceImportAll("force-import-all", cl::init(false), cl::Hidden, cl::desc("Import functions with noinline attribute")); @@ -1351,7 +1356,8 @@ // Upgrade debug info after we're done materializing all the globals and we // have loaded all the required metadata! - UpgradeDebugInfo(*SrcModule); + if (!InputBitcodeBuiltFromSameVersion) + 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 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 @@ -24,10 +24,18 @@ ; RUN: -exported-symbol foo -exported-symbol _foo \ ; RUN: %t-stripped.bc -disable-verify 2>&1 | \ ; RUN: FileCheck %s -allow-empty -check-prefix=CHECK-WARN +; ---- Thin LTO (optimize, don't strip imported file) +; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t-stripped.bc %t2.bc +; RUN: llvm-lto -thinlto -thinlto-action=import -bitcode-built-from-same-version \ +; 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-NO-WARN ; CHECK-WARN: warning{{.*}} ignoring invalid debug info ; CHECK-WARN-NOT: Broken module found ; CHECK: foo +; CHECK-NO-WARN-NOT: ignoring invalid debug info target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.12"