[PATCH] D21255: Fix cloning GlobalValues with comdats across Modules.

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 13 10:38:43 PDT 2016

majnemer added inline comments.

Comment at: lib/IR/Globals.cpp:103-110
@@ -100,1 +102,10 @@
+    // module as Src, so it's safe to share Src's comdat.
+    Comdat *SrcComdat = const_cast<GlobalObject *>(GV)->getComdat();
+    if (SrcComdat == nullptr || getParent() == nullptr)
+      setComdat(SrcComdat);
+    else if (getParent() != nullptr) {
+      Comdat *C = getParent()->getOrInsertComdat(SrcComdat->getName());
+      C->setSelectionKind(SrcComdat->getSelectionKind());
+      setComdat(C);
+    }
I find it a little weird that we are trying to predict how the global will be used.
We are not sure which module it will be in but we sorta assume it will be in the same one as the original function...

I'm starting to think that the right thing to do is move this logic out of copyAttributesFrom and into another method.  Something like copyComdatFrom which asserts that the source and dest are from the same module.

What do you think?


More information about the llvm-commits mailing list