Fix linking of prologue data.

It would crash when the function was lazy linked.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223656 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2014-12-08 13:44:38 +00:00
parent dc8b15c3a1
commit 7779b87b25
2 changed files with 28 additions and 23 deletions

View File

@ -1177,6 +1177,17 @@ bool ModuleLinker::linkFunctionBody(Function *Dst, Function *Src) {
if (std::error_code EC = Src->materialize())
return emitError(EC.message());
// Link in the prefix data.
if (Src->hasPrefixData())
Dst->setPrefixData(MapValue(Src->getPrefixData(), ValueMap, RF_None,
&TypeMap, &ValMaterializer));
// Link in the prologue data.
if (Src->hasPrologueData())
Dst->setPrologueData(MapValue(Src->getPrologueData(), ValueMap, RF_None,
&TypeMap, &ValMaterializer));
// Go through and convert function arguments over, remembering the mapping.
Function::arg_iterator DI = Dst->arg_begin();
for (Function::arg_iterator I = Src->arg_begin(), E = Src->arg_end();
@ -1485,17 +1496,6 @@ bool ModuleLinker::run() {
continue;
Function *DF = cast<Function>(ValueMap[&SF]);
// Link in the prefix data.
if (SF.hasPrefixData())
DF->setPrefixData(MapValue(SF.getPrefixData(), ValueMap, RF_None,
&TypeMap, &ValMaterializer));
// Link in the prologue data.
if (SF.hasPrologueData())
DF->setPrologueData(MapValue(SF.getPrologueData(), ValueMap, RF_None,
&TypeMap, &ValMaterializer));
if (linkFunctionBody(DF, &SF))
return true;
}
@ -1522,13 +1522,6 @@ bool ModuleLinker::run() {
LazilyLinkFunctions.pop_back();
Function *DF = cast<Function>(ValueMap[SF]);
if (SF->hasPrefixData()) {
// Link in the prefix data.
DF->setPrefixData(MapValue(SF->getPrefixData(), ValueMap, RF_None,
&TypeMap, &ValMaterializer));
}
// Link in function body.
if (linkFunctionBody(DF, SF))
return true;
}

View File

@ -1,9 +1,21 @@
; RUN: echo > %t.ll
; RUN: llvm-link %t.ll %s -S -o - | FileCheck %s
; RUN: llvm-link %s -S -o - | FileCheck %s
@i = linkonce_odr global i32 1
@g1 = global void()* @f2
; CHECK: @g1 = global void ()* @f2
; CHECK: define void @f() prologue i32* @i
define void @f() prologue i32* @i {
@p1 = global i8 42
; CHECK: @p1 = global i8 42
@p2 = internal global i8 43
; CHECK: @p2 = internal global i8 43
define void @f1() prologue i8* @p1 {
ret void
}
; CHECK: define void @f1() prologue i8* @p1 {
define internal void @f2() prologue i8* @p2 {
ret void
}
; CHECK: define internal void @f2() prologue i8* @p2 {