From 6c4fc98afa17d80e4dec6fd1ad116a67fa60d272 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Wed, 20 Jan 2016 22:05:50 +0000 Subject: [PATCH] Fix PR26152. Fix the condition for when the new global takes over the name of the existing one to be the negation of the condition for the new global to get internal linkage. llvm-svn: 258355 --- lib/Linker/IRMover.cpp | 2 +- test/Linker/Inputs/alias-2.ll | 7 +++++++ test/Linker/alias-2.ll | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/Linker/Inputs/alias-2.ll create mode 100644 test/Linker/alias-2.ll diff --git a/lib/Linker/IRMover.cpp b/lib/Linker/IRMover.cpp index de368498ef2..9fdf8ca6b24 100644 --- a/lib/Linker/IRMover.cpp +++ b/lib/Linker/IRMover.cpp @@ -1087,7 +1087,7 @@ Constant *IRLinker::linkGlobalValueProto(GlobalValue *SGV, bool ForAlias) { return nullptr; NewGV = copyGlobalValueProto(SGV, ShouldLink); - if (!ForAlias) + if (ShouldLink || !ForAlias) forceRenaming(NewGV, SGV->getName()); } if (ShouldLink || ForAlias) { diff --git a/test/Linker/Inputs/alias-2.ll b/test/Linker/Inputs/alias-2.ll new file mode 100644 index 00000000000..03c1d91fe6b --- /dev/null +++ b/test/Linker/Inputs/alias-2.ll @@ -0,0 +1,7 @@ +define void @B() { + call void @A() + ret void +} + +declare void @A() + diff --git a/test/Linker/alias-2.ll b/test/Linker/alias-2.ll new file mode 100644 index 00000000000..8875aa76455 --- /dev/null +++ b/test/Linker/alias-2.ll @@ -0,0 +1,24 @@ +; RUN: llvm-link %s %S/Inputs/alias-2.ll -S -o - | FileCheck %s +; RUN: llvm-link %S/Inputs/alias-2.ll %s -S -o - | FileCheck %s + +; Test the fix for PR26152, where A from the second module is +; erroneously renamed to A.1 and not linked to the declaration from +; the first module + +@C = alias void (), void ()* @A + +define void @D() { + call void @C() + ret void +} + +define void @A() { + ret void +} + +; CHECK-DAG: @C = alias void (), void ()* @A +; CHECK-DAG: define void @B() +; CHECK-DAG: call void @A() +; CHECK-DAG: define void @D() +; CHECK-DAG: call void @C() +; CHECK-DAG: define void @A()