From d1e64b1e93ccf8836dc76f36adda880bbeab196f Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 30 Oct 2014 20:50:23 +0000 Subject: Fix the merging of the constantness of declarations. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. llvm-svn: 220927 --- llvm/lib/Linker/LinkModules.cpp | 5 ++--- llvm/test/Linker/ConstantGlobals3.ll | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'llvm') diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp index 403a1ff90c5..2692ec97b78 100644 --- a/llvm/lib/Linker/LinkModules.cpp +++ b/llvm/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/llvm/test/Linker/ConstantGlobals3.ll b/llvm/test/Linker/ConstantGlobals3.ll index 5867ea50088..0b70ddd646f 100644 --- a/llvm/test/Linker/ConstantGlobals3.ll +++ b/llvm/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] -- cgit v1.2.3