From 9cabb129a0216bab9fd4e56b0b79fa3342ddda05 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Fri, 24 Apr 2015 22:07:31 +0000 Subject: [PATCH] Linker: Copy over function metadata attachments Update `lib/Linker` to handle `Function` metadata attachments. The attachments stick with the function body. llvm-svn: 235786 --- lib/Linker/LinkModules.cpp | 7 +++++++ test/Linker/Inputs/metadata-function.ll | 13 +++++++++++++ test/Linker/metadata-function.ll | 26 +++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 test/Linker/Inputs/metadata-function.ll create mode 100644 test/Linker/metadata-function.ll diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 65a02a71c70..34a353a6c82 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -1205,6 +1205,13 @@ bool ModuleLinker::linkFunctionBody(Function &Dst, Function &Src) { ++DI; } + // Copy over the metadata attachments. + SmallVector, 8> MDs; + Src.getAllMetadata(MDs); + for (const auto &I : MDs) + Dst.setMetadata(I.first, MapMetadata(I.second, ValueMap, RF_None, &TypeMap, + &ValMaterializer)); + // Splice the body of the source function into the dest function. Dst.getBasicBlockList().splice(Dst.end(), Src.getBasicBlockList()); diff --git a/test/Linker/Inputs/metadata-function.ll b/test/Linker/Inputs/metadata-function.ll new file mode 100644 index 00000000000..8572ff11983 --- /dev/null +++ b/test/Linker/Inputs/metadata-function.ll @@ -0,0 +1,13 @@ +define weak void @foo() !weak !0 { + unreachable +} + +define void @baz() !baz !0 { + unreachable +} + +define void @b() !b !0 { + unreachable +} + +!0 = !{!"b"} diff --git a/test/Linker/metadata-function.ll b/test/Linker/metadata-function.ll new file mode 100644 index 00000000000..0b17e0c5858 --- /dev/null +++ b/test/Linker/metadata-function.ll @@ -0,0 +1,26 @@ +; RUN: llvm-link %s %S/Inputs/metadata-function.ll -S | FileCheck %s +; RUN: llvm-link %S/Inputs/metadata-function.ll %s -S | FileCheck %s + +; CHECK-DAG: define weak void @foo() !weak ![[B:[0-9]+]] { +define linkonce void @foo() !linkonce !0 { + unreachable +} + +; CHECK-DAG: define void @bar() !bar ![[A:[0-9]+]] { +define void @bar() !bar !0 { + call void @baz() + unreachable +} + +; CHECK-DAG: define void @baz() !baz ![[B]] { +declare void @baz() + +; CHECK-DAG: define void @a() !a ![[A]] { +; CHECK-DAG: define void @b() !b ![[B]] { +define void @a() !a !0 { + unreachable +} + +; CHECK-DAG: ![[A]] = !{!"a"} +; CHECK-DAG: ![[B]] = !{!"b"} +!0 = !{!"a"}