From 6947f10ec467eb89d606bc96450c35864e1b4f10 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 4 Sep 2013 14:59:03 +0000 Subject: [PATCH] Fix linking of unnamed_addr in functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189945 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Linker/LinkModules.cpp | 6 +++++- test/Linker/unnamed-addr1-a.ll | 19 +++++++++++++++++++ test/Linker/unnamed-addr1-b.ll | 8 ++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index ab37b8b12fb..16e2851f0bc 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -756,12 +756,12 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) { // Determine whether linkage of these two globals follows the source // module's definition or the destination module's definition. GlobalValue::LinkageTypes NewLinkage = GlobalValue::InternalLinkage; - HasUnnamedAddr = HasUnnamedAddr && DGV->hasUnnamedAddr(); GlobalValue::VisibilityTypes NV; bool LinkFromSrc = false; if (getLinkageResult(DGV, SGV, NewLinkage, NV, LinkFromSrc)) return true; NewVisibility = NV; + HasUnnamedAddr = HasUnnamedAddr && DGV->hasUnnamedAddr(); // If we're not linking from the source, then keep the definition that we // have. @@ -817,6 +817,7 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) { bool ModuleLinker::linkFunctionProto(Function *SF) { GlobalValue *DGV = getLinkedToGlobal(SF); llvm::Optional NewVisibility; + bool HasUnnamedAddr = SF->hasUnnamedAddr(); if (DGV) { GlobalValue::LinkageTypes NewLinkage = GlobalValue::InternalLinkage; @@ -825,11 +826,13 @@ bool ModuleLinker::linkFunctionProto(Function *SF) { if (getLinkageResult(DGV, SF, NewLinkage, NV, LinkFromSrc)) return true; NewVisibility = NV; + HasUnnamedAddr = HasUnnamedAddr && DGV->hasUnnamedAddr(); if (!LinkFromSrc) { // Set calculated linkage DGV->setLinkage(NewLinkage); DGV->setVisibility(*NewVisibility); + DGV->setUnnamedAddr(HasUnnamedAddr); // Make sure to remember this mapping. ValueMap[SF] = ConstantExpr::getBitCast(DGV, TypeMap.get(SF->getType())); @@ -857,6 +860,7 @@ bool ModuleLinker::linkFunctionProto(Function *SF) { copyGVAttributes(NewDF, SF); if (NewVisibility) NewDF->setVisibility(*NewVisibility); + NewDF->setUnnamedAddr(HasUnnamedAddr); if (DGV) { // Any uses of DF need to change to NewDF, with cast. diff --git a/test/Linker/unnamed-addr1-a.ll b/test/Linker/unnamed-addr1-a.ll index 8ab9d09aa3d..adaa40024cf 100644 --- a/test/Linker/unnamed-addr1-a.ll +++ b/test/Linker/unnamed-addr1-a.ll @@ -6,6 +6,11 @@ @global-b = common unnamed_addr global i32 0 ; CHECK-DAG: @global-b = common unnamed_addr global i32 0 +define weak void @func-a() { ret void } +; CHECK-DAG: define weak void @func-a() { +define weak void @func-b() unnamed_addr { ret void } +; CHECK-DAG: define weak void @func-b() unnamed_addr { + ; Other file has unnamed_addr definition @global-c = common unnamed_addr global i32 0 ; CHECK-DAG: @global-c = common unnamed_addr global i32 0 @@ -16,6 +21,13 @@ @global-f = weak global i32 42 ; CHECK-DAG: @global-f = global i32 42 +declare void @func-c() +; CHECK-DAG: define weak void @func-c() { +define weak void @func-d() { ret void } +; CHECK-DAG: define weak void @func-d() { +define weak void @func-e() unnamed_addr { ret void } +; CHECK-DAG: define weak void @func-e() unnamed_addr { + ; Other file has non-unnamed_addr definition @global-g = common unnamed_addr global i32 0 ; CHECK-DAG: @global-g = common global i32 0 @@ -25,3 +37,10 @@ ; CHECK-DAG: @global-i = global i32 42 @global-j = weak global i32 42 ; CHECK-DAG: @global-j = global i32 42 + +declare void @func-g() +; CHECK-DAG: define weak void @func-g() { +define weak void @func-h() { ret void } +; CHECK-DAG: define weak void @func-h() { +define weak void @func-i() unnamed_addr { ret void } +; CHECK-DAG: define weak void @func-i() { diff --git a/test/Linker/unnamed-addr1-b.ll b/test/Linker/unnamed-addr1-b.ll index ef009e87ec2..aa1507b9c6b 100644 --- a/test/Linker/unnamed-addr1-b.ll +++ b/test/Linker/unnamed-addr1-b.ll @@ -6,7 +6,15 @@ @global-e = unnamed_addr global i32 42 @global-f = unnamed_addr global i32 42 +define weak void @func-c() unnamed_addr { ret void } +define weak void @func-d() unnamed_addr { ret void } +define weak void @func-e() unnamed_addr { ret void } + @global-g = common global i32 42 @global-h = global i32 42 @global-i = global i32 42 @global-j = global i32 42 + +define weak void @func-g() { ret void } +define weak void @func-h() { ret void } +define weak void @func-i() { ret void }