[llvm] r220927 - Fix the merging of the constantness of declarations.

Rafael Espindola rafael.espindola at gmail.com
Thu Oct 30 13:50:23 PDT 2014


Author: rafael
Date: Thu Oct 30 15:50:23 2014
New Revision: 220927

URL: http://llvm.org/viewvc/llvm-project?rev=220927&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Linker/LinkModules.cpp
    llvm/trunk/test/Linker/ConstantGlobals3.ll

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=220927&r1=220926&r2=220927&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Thu Oct 30 15:50:23 2014
@@ -1052,9 +1052,8 @@ bool ModuleLinker::linkGlobalProto(Globa
         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.

Modified: llvm/trunk/test/Linker/ConstantGlobals3.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/ConstantGlobals3.ll?rev=220927&r1=220926&r2=220927&view=diff
==============================================================================
--- llvm/trunk/test/Linker/ConstantGlobals3.ll (original)
+++ llvm/trunk/test/Linker/ConstantGlobals3.ll Thu Oct 30 15:50:23 2014
@@ -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]





More information about the llvm-commits mailing list