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

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 9 17:26:37 PDT 2017


LGTM

Peter Collingbourne via Phabricator via llvm-commits
<llvm-commits at lists.llvm.org> writes:

> 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()),
>
>
> 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()),
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list