From: Rafael Espindola Date: Tue, 9 Sep 2014 17:48:18 +0000 (+0000) Subject: Merge alignment of common GlobalValue. X-Git-Tag: android-x86-7.1-r4~57705 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=12af22e8cc217827cf4f118b0f5e4ebbda9925ae;p=android-x86%2Fexternal-llvm.git Merge alignment of common GlobalValue. Fixes pr20882. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217455 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 65fe30c94f7..0313e2b8a7e 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -1001,6 +1001,7 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) { GlobalValue *DGV = getLinkedToGlobal(SGV); llvm::Optional 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(DGV)) + if (GlobalVariable *DGVar = dyn_cast(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); diff --git a/test/Linker/Inputs/linkage2.ll b/test/Linker/Inputs/linkage2.ll index 6f320e40e0a..ce01c9d90d4 100644 --- a/test/Linker/Inputs/linkage2.ll +++ b/test/Linker/Inputs/linkage2.ll @@ -3,3 +3,5 @@ @test2_a = external dllimport global i8 @test3_a = common global i16 0 + +@test4_a = common global i16 0, align 4 diff --git a/test/Linker/linkage2.ll b/test/Linker/linkage2.ll index 283a3b941df..dbae7caee54 100644 --- a/test/Linker/linkage2.ll +++ b/test/Linker/linkage2.ll @@ -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