Index: lib/IR/Globals.cpp =================================================================== --- lib/IR/Globals.cpp +++ lib/IR/Globals.cpp @@ -96,6 +96,7 @@ if (const auto *GV = dyn_cast(Src)) { setAlignment(GV->getAlignment()); setSection(GV->getSection()); + setComdat(const_cast(GV)->getComdat()); } } Index: lib/Linker/IRMover.cpp =================================================================== --- lib/Linker/IRMover.cpp +++ lib/Linker/IRMover.cpp @@ -622,6 +622,11 @@ NewGV->copyAttributesFrom(SGV); + // Don't copy the comdat, it's from the original module. We'll handle it + // later. + if (auto *NewGO = dyn_cast(NewGV)) + NewGO->setComdat(nullptr); + // Remove these copied constants in case this stays a declaration, since // they point to the source module. If the def is linked the values will // be mapped in during linkFunctionBody. Index: test/Transforms/DeadArgElim/comdat.ll =================================================================== --- /dev/null +++ test/Transforms/DeadArgElim/comdat.ll @@ -0,0 +1,14 @@ +; RUN: opt -S < %s -deadargelim | FileCheck %s + +$f = comdat any + +define void @f() comdat { + call void @g(i32 0) + ret void +} + +define internal void @g(i32 %dead) comdat($f) { + ret void +} + +; CHECK: define internal void @g() comdat($f) {