From: Rafael Espindola Date: Thu, 30 Oct 2014 20:50:23 +0000 (+0000) Subject: Fix the merging of the constantness of declarations. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=3d41cbb3f4bfd0482689a84c07e3fd8e24f5d9b5 Fix the merging of the constantness of declarations. The langref says: LLVM explicitly allows declarations of global variables to be marked constant, even if the final definition of the global is not. This capability can be used to enable slightly better optimization of the program, but requires the language definition to guarantee that optimizations based on the ‘constantness’ are valid for the translation units that do not include the definition. Given that definition, when merging two declarations, we have to drop constantness if of of them is not marked contant, since the Module without the constant marker might not have the necessary guarantees. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220927 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 403a1ff90c5..2692ec97b78 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -1052,9 +1052,8 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) { if (GlobalVariable *DGVar = dyn_cast(DGV)) { DGVar->setAlignment(Alignment); - if (DGVar->isDeclaration() && SGV->isConstant() && - !DGVar->isConstant()) - DGVar->setConstant(true); + if (DGVar->isDeclaration() && !SGV->isConstant()) + DGVar->setConstant(false); } // Set calculated linkage, visibility and unnamed_addr. diff --git a/test/Linker/ConstantGlobals3.ll b/test/Linker/ConstantGlobals3.ll index 5867ea50088..0b70ddd646f 100644 --- a/test/Linker/ConstantGlobals3.ll +++ b/test/Linker/ConstantGlobals3.ll @@ -1,6 +1,6 @@ ; RUN: llvm-link %s %S/Inputs/ConstantGlobals3.ll -S | FileCheck %s ; RUN: llvm-link %S/Inputs/ConstantGlobals3.ll %s -S | FileCheck %s -; CHECK: @X = external constant [1 x i32] +; CHECK: @X = external global [1 x i32] @X = external global [1 x i32]