Skip to content

Commit

Permalink
Fix PR8300 by remembering to keep the bitcast in all cases.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116788 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Oct 19, 2010
1 parent 5c0db76 commit 1978599
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/Linker/LinkModules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,13 @@ static bool LinkAlias(Module *Dest, const Module *Src,
GlobalValue* DAliasee = cast<GlobalValue>(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());
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions test/Linker/PR8300.ll
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 1978599

Please sign in to comment.