Index: lib/LTO/LTOBackend.cpp =================================================================== --- lib/LTO/LTOBackend.cpp +++ lib/LTO/LTOBackend.cpp @@ -342,8 +342,7 @@ if (Conf.PostPromoteModuleHook && !Conf.PostPromoteModuleHook(Task, Mod)) return Error(); - if (!DefinedGlobals.empty()) - thinLTOInternalizeModule(Mod, DefinedGlobals); + thinLTOInternalizeModule(Mod, DefinedGlobals); if (Conf.PostInternalizeModuleHook && !Conf.PostInternalizeModuleHook(Task, Mod)) Index: lib/Transforms/IPO/FunctionImport.cpp =================================================================== --- lib/Transforms/IPO/FunctionImport.cpp +++ lib/Transforms/IPO/FunctionImport.cpp @@ -547,6 +547,14 @@ /// Run internalization on \p TheModule based on symmary analysis. void llvm::thinLTOInternalizeModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals) { + // Skip this if there are no GV summaries. Either there are no + // defined GVs to internalize, or we had an empty summary (e.g. + // due to inline or module-level assembly that prevents us from + // being able to rename local references). If we don't bail out here + // then we would get an assert below in the MustPreserveGV callback. + if (DefinedGlobals.empty()) + return; + // Parse inline ASM and collect the list of symbols that are not defined in // the current module. StringSet<> AsmUndefinedRefs; Index: test/Transforms/FunctionImport/Inputs/inlineasm.ll =================================================================== --- test/Transforms/FunctionImport/Inputs/inlineasm.ll +++ test/Transforms/FunctionImport/Inputs/inlineasm.ll @@ -1,3 +1,6 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + @myvar = internal constant i8 1, align 1 @llvm.used = appending global [1 x i8*] [i8* @myvar], section "llvm.metadata" Index: test/Transforms/FunctionImport/inlineasm.ll =================================================================== --- test/Transforms/FunctionImport/inlineasm.ll +++ test/Transforms/FunctionImport/inlineasm.ll @@ -3,11 +3,21 @@ ; RUN: opt -module-summary %p/Inputs/inlineasm.ll -o %t2.bc ; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc +; RUN: llvm-lto -thinlto-action=internalize -thinlto-index %t3.thinlto.bc %t2.bc -o - --exported-symbol=main | llvm-dis -o - | FileCheck %s --check-prefix=INTERNALIZE +; INTERNALIZE: define void @foo(i64* %v) + +; RUN: llvm-lto2 -o %t3 %t.bc %t2.bc -r=%t.bc,main,plx -r=%t.bc,foo,l -r=%t2.bc,foo,pl +; RUN: llvm-nm %t3.1 | FileCheck %s --check-prefix=NM +; NM: T foo + ; Attempt the import now, ensure below that file containing inline assembly ; is not imported from. Otherwise we would need to promote its local variable ; used in the inline assembly, which would not see the rename. ; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s --check-prefix=CHECK +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + define i32 @main() #0 { entry: %f = alloca i64, align 8