[PATCH] D36438: Linker: Create a function declaration when moving a non-prevailing alias of function type.
Peter Collingbourne via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 7 19:02:59 PDT 2017
pcc created this revision.
Herald added subscribers: hiraditya, mehdi_amini.
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.
https://reviews.llvm.org/D36438
Files:
llvm/lib/Linker/IRMover.cpp
llvm/test/LTO/Resolution/X86/function-alias-non-prevailing.ll
Index: llvm/test/LTO/Resolution/X86/function-alias-non-prevailing.ll
===================================================================
--- /dev/null
+++ llvm/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()
+ at foo = weak alias void(), void()* @bar
+
+define internal void @bar() {
+ ret void
+}
+
+define void()* @baz() {
+ ret void()* @foo
+}
Index: llvm/lib/Linker/IRMover.cpp
===================================================================
--- llvm/lib/Linker/IRMover.cpp
+++ llvm/lib/Linker/IRMover.cpp
@@ -640,6 +640,10 @@
} else {
if (ForDefinition)
NewGV = copyGlobalAliasProto(cast<GlobalAlias>(SGV));
+ else if (SGV->getValueType()->isFunctionTy())
+ NewGV =
+ Function::Create(cast<FunctionType>(TypeMap.get(SGV->getValueType())),
+ GlobalValue::ExternalLinkage, SGV->getName(), &DstM);
else
NewGV = new GlobalVariable(
DstM, TypeMap.get(SGV->getValueType()),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36438.110123.patch
Type: text/x-patch
Size: 1260 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170808/7133cb25/attachment.bin>
More information about the llvm-commits
mailing list