[llvm] r215765 - Set comdats when lazily linking functions.

Rafael Espindola rafael.espindola at gmail.com
Fri Aug 15 13:17:08 PDT 2014


Author: rafael
Date: Fri Aug 15 15:17:08 2014
New Revision: 215765

URL: http://llvm.org/viewvc/llvm-project?rev=215765&view=rev
Log:
Set comdats when lazily linking functions.

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.

Added:
    llvm/trunk/test/Linker/Inputs/comdat9.ll
    llvm/trunk/test/Linker/comdat9.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=215765&r1=215764&r2=215765&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Fri Aug 15 15:17:08 2014
@@ -546,6 +546,11 @@ Value *ValueMaterializerTy::materializeV
                                   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;
 }

Added: llvm/trunk/test/Linker/Inputs/comdat9.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/comdat9.ll?rev=215765&view=auto
==============================================================================
--- llvm/trunk/test/Linker/Inputs/comdat9.ll (added)
+++ llvm/trunk/test/Linker/Inputs/comdat9.ll Fri Aug 15 15:17:08 2014
@@ -0,0 +1,5 @@
+$c = comdat any
+ at a = alias void ()* @f
+define internal void @f() comdat $c {
+  ret void
+}

Added: llvm/trunk/test/Linker/comdat9.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/comdat9.ll?rev=215765&view=auto
==============================================================================
--- llvm/trunk/test/Linker/comdat9.ll (added)
+++ llvm/trunk/test/Linker/comdat9.ll Fri Aug 15 15:17:08 2014
@@ -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: }





More information about the llvm-commits mailing list