From: Peter Collingbourne Date: Thu, 10 Aug 2017 01:07:44 +0000 (+0000) Subject: Linker: Create a function declaration when moving a non-prevailing alias of function... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9e6aa3e0fefb3f5df241ba5175c5e0907199bb01;p=llvm Linker: Create a function declaration when moving a non-prevailing alias of function type. We were previously creating a global variable of function type, which is invalid IR. This issue was exposed by r304690, in which we started asserting that global variables were of a valid type. Fixes PR33462. Differential Revision: https://reviews.llvm.org/D36438 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310543 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Linker/IRMover.cpp b/lib/Linker/IRMover.cpp index f486e525b5e..ee067a912e3 100644 --- a/lib/Linker/IRMover.cpp +++ b/lib/Linker/IRMover.cpp @@ -640,6 +640,10 @@ GlobalValue *IRLinker::copyGlobalValueProto(const GlobalValue *SGV, } else { if (ForDefinition) NewGV = copyGlobalAliasProto(cast(SGV)); + else if (SGV->getValueType()->isFunctionTy()) + NewGV = + Function::Create(cast(TypeMap.get(SGV->getValueType())), + GlobalValue::ExternalLinkage, SGV->getName(), &DstM); else NewGV = new GlobalVariable( DstM, TypeMap.get(SGV->getValueType()), diff --git a/test/LTO/Resolution/X86/function-alias-non-prevailing.ll b/test/LTO/Resolution/X86/function-alias-non-prevailing.ll new file mode 100644 index 00000000000..ab2cefebb42 --- /dev/null +++ b/test/LTO/Resolution/X86/function-alias-non-prevailing.ll @@ -0,0 +1,17 @@ +; RUN: llvm-as -o %t %s +; RUN: llvm-lto2 run %t -r %t,foo, -r %t,baz,p -o %t2 -save-temps +; RUN: llvm-dis -o - %t2.0.0.preopt.bc | FileCheck %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64--fuchsia" + +; CHECK: declare void @foo() +@foo = weak alias void(), void()* @bar + +define internal void @bar() { + ret void +} + +define void()* @baz() { + ret void()* @foo +}