[llvm] r310543 - Linker: Create a function declaration when moving a non-prevailing alias of function type.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 9 18:07:44 PDT 2017


Author: pcc
Date: Wed Aug  9 18:07:44 2017
New Revision: 310543

URL: http://llvm.org/viewvc/llvm-project?rev=310543&view=rev
Log:
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

Added:
    llvm/trunk/test/LTO/Resolution/X86/function-alias-non-prevailing.ll
Modified:
    llvm/trunk/lib/Linker/IRMover.cpp

Modified: llvm/trunk/lib/Linker/IRMover.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/IRMover.cpp?rev=310543&r1=310542&r2=310543&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/IRMover.cpp (original)
+++ llvm/trunk/lib/Linker/IRMover.cpp Wed Aug  9 18:07:44 2017
@@ -640,6 +640,10 @@ GlobalValue *IRLinker::copyGlobalValuePr
   } 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()),

Added: llvm/trunk/test/LTO/Resolution/X86/function-alias-non-prevailing.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/function-alias-non-prevailing.ll?rev=310543&view=auto
==============================================================================
--- llvm/trunk/test/LTO/Resolution/X86/function-alias-non-prevailing.ll (added)
+++ llvm/trunk/test/LTO/Resolution/X86/function-alias-non-prevailing.ll Wed Aug  9 18:07:44 2017
@@ -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
+}




More information about the llvm-commits mailing list