mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
Merge alignment of common GlobalValue.
Fixes pr20882. llvm-svn: 217455
This commit is contained in:
parent
97aff9f17f
commit
d7ebc28eec
@ -1001,6 +1001,7 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) {
|
|||||||
GlobalValue *DGV = getLinkedToGlobal(SGV);
|
GlobalValue *DGV = getLinkedToGlobal(SGV);
|
||||||
llvm::Optional<GlobalValue::VisibilityTypes> NewVisibility;
|
llvm::Optional<GlobalValue::VisibilityTypes> NewVisibility;
|
||||||
bool HasUnnamedAddr = SGV->hasUnnamedAddr();
|
bool HasUnnamedAddr = SGV->hasUnnamedAddr();
|
||||||
|
unsigned Alignment = SGV->getAlignment();
|
||||||
|
|
||||||
bool LinkFromSrc = false;
|
bool LinkFromSrc = false;
|
||||||
Comdat *DC = nullptr;
|
Comdat *DC = nullptr;
|
||||||
@ -1025,15 +1026,22 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) {
|
|||||||
return true;
|
return true;
|
||||||
NewVisibility = NV;
|
NewVisibility = NV;
|
||||||
HasUnnamedAddr = HasUnnamedAddr && DGV->hasUnnamedAddr();
|
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
|
// If we're not linking from the source, then keep the definition that we
|
||||||
// have.
|
// have.
|
||||||
if (!LinkFromSrc) {
|
if (!LinkFromSrc) {
|
||||||
// Special case for const propagation.
|
// 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() &&
|
if (DGVar->isDeclaration() && SGV->isConstant() &&
|
||||||
!DGVar->isConstant())
|
!DGVar->isConstant())
|
||||||
DGVar->setConstant(true);
|
DGVar->setConstant(true);
|
||||||
|
}
|
||||||
|
|
||||||
// Set calculated linkage, visibility and unnamed_addr.
|
// Set calculated linkage, visibility and unnamed_addr.
|
||||||
DGV->setLinkage(NewLinkage);
|
DGV->setLinkage(NewLinkage);
|
||||||
@ -1071,6 +1079,7 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) {
|
|||||||
SGV->getType()->getAddressSpace());
|
SGV->getType()->getAddressSpace());
|
||||||
// Propagate alignment, visibility and section info.
|
// Propagate alignment, visibility and section info.
|
||||||
copyGVAttributes(NewDGV, SGV);
|
copyGVAttributes(NewDGV, SGV);
|
||||||
|
NewDGV->setAlignment(Alignment);
|
||||||
if (NewVisibility)
|
if (NewVisibility)
|
||||||
NewDGV->setVisibility(*NewVisibility);
|
NewDGV->setVisibility(*NewVisibility);
|
||||||
NewDGV->setUnnamedAddr(HasUnnamedAddr);
|
NewDGV->setUnnamedAddr(HasUnnamedAddr);
|
||||||
|
@ -3,3 +3,5 @@
|
|||||||
@test2_a = external dllimport global i8
|
@test2_a = external dllimport global i8
|
||||||
|
|
||||||
@test3_a = common global i16 0
|
@test3_a = common global i16 0
|
||||||
|
|
||||||
|
@test4_a = common global i16 0, align 4
|
||||||
|
@ -9,3 +9,6 @@
|
|||||||
|
|
||||||
@test3_a = common global i8 0
|
@test3_a = common global i8 0
|
||||||
; CHECK-DAG: @test3_a = common global i16 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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user