Skip to content

Commit 3d4f3a0

Browse files
committed
IRLinker: fix double scheduling of mapping a global value because of an alias
This test was hitting an assertion in the value mapper because the IRLinker was trying to map two times @A while materializing the initializer for @C. Fix http://llvm.org/PR27850 Differential Revision: http://reviews.llvm.org/D20586 llvm-svn: 270757
1 parent 971abe8 commit 3d4f3a0

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

llvm/lib/Linker/IRMover.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,17 @@ void IRLinker::materializeInitFor(GlobalValue *New, GlobalValue *Old,
557557
return;
558558
}
559559

560+
// When linking a global for an alias, it will always be linked. However we
561+
// need to check if it was not already scheduled to satify a reference from a
562+
// regular global value initializer. We know if it has been schedule if the
563+
// "New" GlobalValue that is mapped here for the alias is the same as the one
564+
// already mapped. If there is an entry in the ValueMap but the value is
565+
// different, it means that the value already had a definition in the
566+
// destination module (linkonce for instance), but we need a new definition
567+
// for the alias ("New" will be different.
568+
if (ForAlias && ValueMap.lookup(Old) == New)
569+
return;
570+
560571
if (ForAlias || shouldLink(New, *Old))
561572
linkGlobalValueBody(*New, *Old);
562573
}

llvm/test/Linker/alias-3.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; RUN: llvm-link %s -S -o - | FileCheck %s
2+
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
3+
target triple = "x86_64-apple-macosx10.9"
4+
5+
; CHECK-DAG: @A = internal constant i8 1
6+
; CHECK-DAG: @B = alias i8, i8* @A
7+
; CHECK-DAG: @C = global [2 x i8*] [i8* @A, i8* @B]
8+
9+
@A = internal constant i8 1
10+
@B = alias i8, i8* @A
11+
@C = global [2 x i8*] [i8* @A, i8* @B]
12+
13+

0 commit comments

Comments
 (0)