[llvm-branch-commits] [llvm] [llvm][GlobalOpt] Preserve COMDAT during SRA splitting (PR #220721)
Miguel A. Arroyo via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Sep 17 09:04:11 PDT 2026
================
@@ -656,7 +657,22 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const DataLayout &DL) {
++NumSRA;
assert(NewGlobals.size() > 0);
- return NewGlobals.begin()->second;
+
+ auto *FirstNewGV = NewGlobals.begin()->second;
+
+ // For COFF, the comdat must contain a member which has the
+ // same name as the group.
+ if (auto *C = FirstNewGV->getComdat()) {
+ auto *DummyGV = new GlobalVariable(
+ *FirstNewGV->getParent(), Type::getInt1Ty(FirstNewGV->getContext()),
+ false, FirstNewGV->getLinkage(),
+ ConstantInt::getFalse(FirstNewGV->getContext()), C->getName(),
+ FirstNewGV, FirstNewGV->getThreadLocalMode(),
+ FirstNewGV->getAddressSpace());
+ DummyGV->setComdat(C);
----------------
mayanez wrote:
Done.
https://github.com/llvm/llvm-project/pull/220721
More information about the llvm-branch-commits
mailing list