diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-10-30 20:50:23 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-10-30 20:50:23 +0000 |
commit | d1e64b1e93ccf8836dc76f36adda880bbeab196f (patch) | |
tree | 7d2d1adae7224b3bf3eb0749e2e6e0bad44a4df6 /llvm | |
parent | 533e26103e1cdeb4201056ba8ff655d3f2604b9f (diff) | |
download | bcm5719-llvm-d1e64b1e93ccf8836dc76f36adda880bbeab196f.tar.gz bcm5719-llvm-d1e64b1e93ccf8836dc76f36adda880bbeab196f.zip |
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.
llvm-svn: 220927
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Linker/LinkModules.cpp | 5 | ||||
-rw-r--r-- | llvm/test/Linker/ConstantGlobals3.ll | 2 |
2 files changed, 3 insertions, 4 deletions
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<GlobalVariable>(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] |