[IR] Copy comdats in GlobalObject::copyAttributesFrom

This is probably correct for all uses except cross-module IR linking,
where we need to move the comdat from the source module to the
destination module.

Fixes PR27870.

Reviewers: majnemer

Differential Revision: http://reviews.llvm.org/D20631

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270743 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Kleckner
2016-05-25 18:36:22 +00:00
parent f50e8cdfbd
commit 6dc628ff61
3 changed files with 20 additions and 0 deletions
+1
View File
@@ -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());
}
}
+5
View File
@@ -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.
+14
View File
@@ -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) {