[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

llvm-svn: 270743
This commit is contained in:
Reid Kleckner 2016-05-25 18:36:22 +00:00
parent 8c7c869714
commit 31bb5b2278
3 changed files with 20 additions and 0 deletions

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());
}
}

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.

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) {