1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

Merge alignment of common GlobalValue.

Fixes pr20882.

llvm-svn: 217455
This commit is contained in:
Rafael Espindola 2014-09-09 17:48:18 +00:00
parent 97aff9f17f
commit d7ebc28eec
3 changed files with 15 additions and 1 deletions

View File

@ -1001,6 +1001,7 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) {
GlobalValue *DGV = getLinkedToGlobal(SGV);
llvm::Optional<GlobalValue::VisibilityTypes> NewVisibility;
bool HasUnnamedAddr = SGV->hasUnnamedAddr();
unsigned Alignment = SGV->getAlignment();
bool LinkFromSrc = false;
Comdat *DC = nullptr;
@ -1025,15 +1026,22 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) {
return true;
NewVisibility = NV;
HasUnnamedAddr = HasUnnamedAddr && DGV->hasUnnamedAddr();
if (DGV->hasCommonLinkage() && SGV->hasCommonLinkage())
Alignment = std::max(Alignment, DGV->getAlignment());
else if (!LinkFromSrc)
Alignment = DGV->getAlignment();
// If we're not linking from the source, then keep the definition that we
// have.
if (!LinkFromSrc) {
// Special case for const propagation.
if (GlobalVariable *DGVar = dyn_cast<GlobalVariable>(DGV))
if (GlobalVariable *DGVar = dyn_cast<GlobalVariable>(DGV)) {
DGVar->setAlignment(Alignment);
if (DGVar->isDeclaration() && SGV->isConstant() &&
!DGVar->isConstant())
DGVar->setConstant(true);
}
// Set calculated linkage, visibility and unnamed_addr.
DGV->setLinkage(NewLinkage);
@ -1071,6 +1079,7 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) {
SGV->getType()->getAddressSpace());
// Propagate alignment, visibility and section info.
copyGVAttributes(NewDGV, SGV);
NewDGV->setAlignment(Alignment);
if (NewVisibility)
NewDGV->setVisibility(*NewVisibility);
NewDGV->setUnnamedAddr(HasUnnamedAddr);

View File

@ -3,3 +3,5 @@
@test2_a = external dllimport global i8
@test3_a = common global i16 0
@test4_a = common global i16 0, align 4

View File

@ -9,3 +9,6 @@
@test3_a = common global i8 0
; CHECK-DAG: @test3_a = common global i16 0
@test4_a = common global i8 0, align 8
; CHECK-DAG: @test4_a = common global i16 0, align 8