Skip to content

Commit

Permalink
Fix the merging of the constantness of declarations.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
espindola committed Oct 30, 2014
1 parent d33e677 commit 3d41cbb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/Linker/LinkModules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/Linker/ConstantGlobals3.ll
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit 3d41cbb

Please sign in to comment.