Index: lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp =================================================================== --- lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp +++ lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp @@ -182,25 +182,6 @@ void filterModule( Module *M, function_ref ShouldKeepDefinition) { - for (Function &F : *M) { - if (ShouldKeepDefinition(&F)) - continue; - - F.deleteBody(); - F.setComdat(nullptr); - F.clearMetadata(); - } - - for (GlobalVariable &GV : M->globals()) { - if (ShouldKeepDefinition(&GV)) - continue; - - GV.setInitializer(nullptr); - GV.setLinkage(GlobalValue::ExternalLinkage); - GV.setComdat(nullptr); - GV.clearMetadata(); - } - for (Module::alias_iterator I = M->alias_begin(), E = M->alias_end(); I != E;) { GlobalAlias *GA = &*I++; @@ -208,7 +189,7 @@ continue; GlobalObject *GO; - if (I->getValueType()->isFunctionTy()) + if (GA->getValueType()->isFunctionTy()) GO = Function::Create(cast(GA->getValueType()), GlobalValue::ExternalLinkage, "", M); else @@ -220,6 +201,25 @@ GA->replaceAllUsesWith(GO); GA->eraseFromParent(); } + + for (Function &F : *M) { + if (ShouldKeepDefinition(&F)) + continue; + + F.deleteBody(); + F.setComdat(nullptr); + F.clearMetadata(); + } + + for (GlobalVariable &GV : M->globals()) { + if (ShouldKeepDefinition(&GV)) + continue; + + GV.setInitializer(nullptr); + GV.setLinkage(GlobalValue::ExternalLinkage); + GV.setComdat(nullptr); + GV.clearMetadata(); + } } void forEachVirtualFunction(Constant *C, function_ref Fn) { Index: test/ThinLTO/X86/promote-internals.ll =================================================================== --- /dev/null +++ test/ThinLTO/X86/promote-internals.ll @@ -0,0 +1,23 @@ +; RUN: opt -thinlto-bc -o - %s | FileCheck %s +; CHECK: {{^BC}} + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc19.0.24215" + +$al = comdat any + +@anon = private unnamed_addr constant { [1 x i8*] } { [1 x i8*] [i8* null] }, comdat($al), !type !0 + +@al = internal unnamed_addr alias i8*, getelementptr inbounds ({ [1 x i8*] }, { [1 x i8*] }* @anon, i32 0, i32 0, i32 1) + +define i32 @bar() { + %call = call i32 @foo() + ret i32 %call +} + +define internal i32 @foo() unnamed_addr align 2 { + store i8** @al, i8*** null, align 8 + ret i32 0 +} + +!0 = !{i64 8, !"?AVA@@"}