Skip to content

Commit 700eb26

Browse files
committed
Merging r310543:
------------------------------------------------------------------------ r310543 | pcc | 2017-08-09 18:07:44 -0700 (Wed, 09 Aug 2017) | 9 lines 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/branches/release_50@318181 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 690ade4 commit 700eb26

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/Linker/IRMover.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,10 @@ GlobalValue *IRLinker::copyGlobalValueProto(const GlobalValue *SGV,
640640
} else {
641641
if (ForDefinition)
642642
NewGV = copyGlobalAliasProto(cast<GlobalAlias>(SGV));
643+
else if (SGV->getValueType()->isFunctionTy())
644+
NewGV =
645+
Function::Create(cast<FunctionType>(TypeMap.get(SGV->getValueType())),
646+
GlobalValue::ExternalLinkage, SGV->getName(), &DstM);
643647
else
644648
NewGV = new GlobalVariable(
645649
DstM, TypeMap.get(SGV->getValueType()),
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; RUN: llvm-as -o %t %s
2+
; RUN: llvm-lto2 run %t -r %t,foo, -r %t,baz,p -o %t2 -save-temps
3+
; RUN: llvm-dis -o - %t2.0.0.preopt.bc | FileCheck %s
4+
5+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6+
target triple = "x86_64--fuchsia"
7+
8+
; CHECK: declare void @foo()
9+
@foo = weak alias void(), void()* @bar
10+
11+
define internal void @bar() {
12+
ret void
13+
}
14+
15+
define void()* @baz() {
16+
ret void()* @foo
17+
}

0 commit comments

Comments
 (0)