[PATCH] D60898: MergeFunc: preserve COMDAT information when creating a thunk

Saleem Abdulrasool via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 18 18:00:54 PDT 2019


compnerd created this revision.
compnerd added reviewers: vsk, rjmccall, rnk.
compnerd added a project: LLVM.

We would previously drop the COMDAT on the thunk we generated when replacing a function body with the forwarding thunk.  This would result in a function that may have been multiply emitted and multiply merged to be emitted with the same name without the COMDAT.  This is a hard error with PE/COFF where the COMDAT is used for the deduplication of Value Witness functions for Swift.


Repository:
  rL LLVM

https://reviews.llvm.org/D60898

Files:
  lib/Transforms/IPO/MergeFunctions.cpp
  test/Transforms/MergeFunc/comdat.ll


Index: test/Transforms/MergeFunc/comdat.ll
===================================================================
--- /dev/null
+++ test/Transforms/MergeFunc/comdat.ll
@@ -0,0 +1,24 @@
+; RUN: opt -S -mergefunc %s | FileCheck %s
+
+ at symbols = linkonce_odr global <{ i8*, i8* }> <{ i8* bitcast (i32 (i32, i32)* @f to i8*), i8* bitcast (i32 (i32, i32)* @g to i8*) }>
+
+$f = comdat any
+$g = comdat any
+
+define linkonce_odr hidden i32 @f(i32 %x, i32 %y) comdat {
+  %sum = add i32 %x, %y
+  %sum2 = add i32 %x, %sum
+  %sum3 = add i32 %x, %sum
+  ret i32 %sum3
+}
+
+define linkonce_odr hidden i32 @g(i32 %x, i32 %y) comdat {
+  %sum = add i32 %x, %y
+  %sum2 = add i32 %x, %sum
+  %sum3 = add i32 %x, %sum
+  ret i32 %sum3
+}
+
+; CHECK-DAG: define linkonce_odr hidden i32 @f(i32 %x, i32 %y) comdat
+; CHECK-DAG: define linkonce_odr hidden i32 @g(i32 %x, i32 %y) comdat
+
Index: lib/Transforms/IPO/MergeFunctions.cpp
===================================================================
--- lib/Transforms/IPO/MergeFunctions.cpp
+++ lib/Transforms/IPO/MergeFunctions.cpp
@@ -704,6 +704,7 @@
   } else {
     NewG = Function::Create(G->getFunctionType(), G->getLinkage(),
                             G->getAddressSpace(), "", G->getParent());
+    NewG->setComdat(G->getComdat());
     BB = BasicBlock::Create(F->getContext(), "", NewG);
   }



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60898.195848.patch
Type: text/x-patch
Size: 1340 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190419/3b6b9c91/attachment.bin>


More information about the llvm-commits mailing list