[llvm] r235786 - Linker: Copy over function metadata attachments

Duncan P. N. Exon Smith dexonsmith at apple.com
Fri Apr 24 15:07:31 PDT 2015


Author: dexonsmith
Date: Fri Apr 24 17:07:31 2015
New Revision: 235786

URL: http://llvm.org/viewvc/llvm-project?rev=235786&view=rev
Log:
Linker: Copy over function metadata attachments

Update `lib/Linker` to handle `Function` metadata attachments.  The
attachments stick with the function body.

Added:
    llvm/trunk/test/Linker/Inputs/metadata-function.ll
    llvm/trunk/test/Linker/metadata-function.ll
Modified:
    llvm/trunk/lib/Linker/LinkModules.cpp

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=235786&r1=235785&r2=235786&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Fri Apr 24 17:07:31 2015
@@ -1205,6 +1205,13 @@ bool ModuleLinker::linkFunctionBody(Func
     ++DI;
   }
 
+  // Copy over the metadata attachments.
+  SmallVector<std::pair<unsigned, MDNode *>, 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());
 

Added: llvm/trunk/test/Linker/Inputs/metadata-function.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/metadata-function.ll?rev=235786&view=auto
==============================================================================
--- llvm/trunk/test/Linker/Inputs/metadata-function.ll (added)
+++ llvm/trunk/test/Linker/Inputs/metadata-function.ll Fri Apr 24 17:07:31 2015
@@ -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"}

Added: llvm/trunk/test/Linker/metadata-function.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/metadata-function.ll?rev=235786&view=auto
==============================================================================
--- llvm/trunk/test/Linker/metadata-function.ll (added)
+++ llvm/trunk/test/Linker/metadata-function.ll Fri Apr 24 17:07:31 2015
@@ -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"}





More information about the llvm-commits mailing list