From e73bc890932e0ee129696cf23baa850028a184f4 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 19 Oct 2010 02:02:57 +0000 Subject: [PATCH] Fix PR8300 by remembering to keep the bitcast in all cases. llvm-svn: 116788 --- llvm/lib/Linker/LinkModules.cpp | 19 ++++++++++--------- llvm/test/Linker/PR8300.ll | 13 +++++++++++++ 2 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 llvm/test/Linker/PR8300.ll diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp index 7e8245a9e3a6..2903a7e71548 100644 --- a/llvm/lib/Linker/LinkModules.cpp +++ b/llvm/lib/Linker/LinkModules.cpp @@ -668,6 +668,13 @@ static bool LinkAlias(Module *Dest, const Module *Src, GlobalValue* DAliasee = cast(VMI->second); GlobalValue* DGV = NULL; + // Fixup aliases to bitcasts. Note that aliases to GEPs are still broken + // by this, but aliases to GEPs are broken to a lot of other things, so + // it's less important. + Constant *DAliaseeConst = DAliasee; + if (SGA->getType() != DAliasee->getType()) + DAliaseeConst = ConstantExpr::getBitCast(DAliasee, SGA->getType()); + // Try to find something 'similar' to SGA in destination module. if (!DGV && !SGA->hasLocalLinkage()) { DGV = Dest->getNamedAlias(SGA->getName()); @@ -721,7 +728,7 @@ static bool LinkAlias(Module *Dest, const Module *Src, "': aliasee is not global variable"); NewGA = new GlobalAlias(SGA->getType(), SGA->getLinkage(), - SGA->getName(), DAliasee, Dest); + SGA->getName(), DAliaseeConst, Dest); CopyGVAttributes(NewGA, SGA); // Any uses of DGV need to change to NewGA, with cast, if needed. @@ -750,7 +757,7 @@ static bool LinkAlias(Module *Dest, const Module *Src, "': aliasee is not function"); NewGA = new GlobalAlias(SGA->getType(), SGA->getLinkage(), - SGA->getName(), DAliasee, Dest); + SGA->getName(), DAliaseeConst, Dest); CopyGVAttributes(NewGA, SGA); // Any uses of DF need to change to NewGA, with cast, if needed. @@ -772,14 +779,8 @@ static bool LinkAlias(Module *Dest, const Module *Src, } else { // No linking to be performed, simply create an identical version of the // alias over in the dest module... - Constant *Aliasee = DAliasee; - // Fixup aliases to bitcasts. Note that aliases to GEPs are still broken - // by this, but aliases to GEPs are broken to a lot of other things, so - // it's less important. - if (SGA->getType() != DAliasee->getType()) - Aliasee = ConstantExpr::getBitCast(DAliasee, SGA->getType()); NewGA = new GlobalAlias(SGA->getType(), SGA->getLinkage(), - SGA->getName(), Aliasee, Dest); + SGA->getName(), DAliaseeConst, Dest); CopyGVAttributes(NewGA, SGA); // Proceed to 'common' steps diff --git a/llvm/test/Linker/PR8300.ll b/llvm/test/Linker/PR8300.ll new file mode 100644 index 000000000000..f0fc1e7a5cc4 --- /dev/null +++ b/llvm/test/Linker/PR8300.ll @@ -0,0 +1,13 @@ +; RUN: echo {%foo2 = type \{ \[8 x i8\] \} \ +; RUN: declare void @zed(%foo2*) } > %t.ll +; RUN: llvm-link %t.ll %s -o %t.bc + +%foo = type { [8 x i8] } +%bar = type { [9 x i8] } + +@zed = alias bitcast (void (%bar*)* @xyz to void (%foo*)*) + +define void @xyz(%bar* %this) { +entry: + ret void +}