]> granicus.if.org Git - llvm/commitdiff
Set comdats when lazily linking functions.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 15 Aug 2014 20:17:08 +0000 (20:17 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 15 Aug 2014 20:17:08 +0000 (20:17 +0000)
We were setting the comdat when functions were copied in the initial pass, but
not when they were linked only when we found out that they are needed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215765 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Linker/LinkModules.cpp
test/Linker/Inputs/comdat9.ll [new file with mode: 0644]
test/Linker/comdat9.ll [new file with mode: 0644]

index 1970e7fa0697ffe85a8525016942c22599c5d306..5c26b2610b1da78f4554004ecebb6dfeadacb4a6 100644 (file)
@@ -546,6 +546,11 @@ Value *ValueMaterializerTy::materializeValueFor(Value *V) {
                                   SF->getLinkage(), SF->getName(), DstM);
   copyGVAttributes(DF, SF);
 
+  if (Comdat *SC = SF->getComdat()) {
+    Comdat *DC = DstM->getOrInsertComdat(SC->getName());
+    DF->setComdat(DC);
+  }
+
   LazilyLinkFunctions.push_back(SF);
   return DF;
 }
diff --git a/test/Linker/Inputs/comdat9.ll b/test/Linker/Inputs/comdat9.ll
new file mode 100644 (file)
index 0000000..679dbde
--- /dev/null
@@ -0,0 +1,5 @@
+$c = comdat any
+@a = alias void ()* @f
+define internal void @f() comdat $c {
+  ret void
+}
diff --git a/test/Linker/comdat9.ll b/test/Linker/comdat9.ll
new file mode 100644 (file)
index 0000000..eada8c6
--- /dev/null
@@ -0,0 +1,7 @@
+; RUN: llvm-link %s %p/Inputs/comdat9.ll -S -o - | FileCheck %s
+
+; CHECK: $c = comdat any
+; CHECK: @a = alias void ()* @f
+; CHECK: define internal void @f() comdat $c {
+; CHECK:   ret void
+; CHECK: }