diff options
-rw-r--r-- | llvm/lib/IR/Globals.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Linker/IRMover.cpp | 5 | ||||
-rw-r--r-- | llvm/test/Transforms/DeadArgElim/comdat.ll | 14 |
3 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp index 7e8ef6526fc..3bf3cc25455 100644 --- a/llvm/lib/IR/Globals.cpp +++ b/llvm/lib/IR/Globals.cpp @@ -96,6 +96,7 @@ void GlobalObject::copyAttributesFrom(const GlobalValue *Src) { if (const auto *GV = dyn_cast<GlobalObject>(Src)) { setAlignment(GV->getAlignment()); setSection(GV->getSection()); + setComdat(const_cast<GlobalObject *>(GV)->getComdat()); } } diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp index 0d37ad1c657..9a2cedfc59e 100644 --- a/llvm/lib/Linker/IRMover.cpp +++ b/llvm/lib/Linker/IRMover.cpp @@ -622,6 +622,11 @@ GlobalValue *IRLinker::copyGlobalValueProto(const GlobalValue *SGV, NewGV->copyAttributesFrom(SGV); + // Don't copy the comdat, it's from the original module. We'll handle it + // later. + if (auto *NewGO = dyn_cast<GlobalObject>(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. diff --git a/llvm/test/Transforms/DeadArgElim/comdat.ll b/llvm/test/Transforms/DeadArgElim/comdat.ll new file mode 100644 index 00000000000..d3752eb4074 --- /dev/null +++ b/llvm/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) { |