[llvm] r223474 - Small cleanup on how we clear constant variables. NFC.

Rafael Espindola rafael.espindola at gmail.com
Fri Dec 5 08:05:20 PST 2014


Author: rafael
Date: Fri Dec  5 10:05:19 2014
New Revision: 223474

URL: http://llvm.org/viewvc/llvm-project?rev=223474&view=rev
Log:
Small cleanup on how we clear constant variables. NFC.

Modified:
    llvm/trunk/lib/Linker/LinkModules.cpp

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=223474&r1=223473&r2=223474&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Fri Dec  5 10:05:19 2014
@@ -1045,6 +1045,14 @@ bool ModuleLinker::linkGlobalValueProto(
       NewGO->setAlignment(std::max(DGV->getAlignment(), SGV->getAlignment()));
   }
 
+  if (auto *NewGVar = dyn_cast<GlobalVariable>(NewGV)) {
+    auto *DGVar = dyn_cast_or_null<GlobalVariable>(DGV);
+    auto *SGVar = dyn_cast<GlobalVariable>(SGV);
+    if (DGVar && SGVar && DGVar->isDeclaration() && SGVar->isDeclaration() &&
+        (!DGVar->isConstant() || !SGVar->isConstant()))
+      NewGVar->setConstant(false);
+  }
+
   // Make sure to remember this mapping.
   if (NewGV != DGV) {
     if (DGV) {
@@ -1062,21 +1070,8 @@ bool ModuleLinker::linkGlobalValueProto(
 GlobalValue *ModuleLinker::linkGlobalVariableProto(const GlobalVariable *SGVar,
                                                    GlobalValue *DGV,
                                                    bool LinkFromSrc) {
-  bool ClearConstant = false;
-
-  if (DGV) {
-    auto *DGVar = dyn_cast<GlobalVariable>(DGV);
-    if (!SGVar->isConstant() || (DGVar && !DGVar->isConstant()))
-      ClearConstant = true;
-  }
-
-  if (!LinkFromSrc) {
-    if (auto *NewGVar = dyn_cast<GlobalVariable>(DGV)) {
-      if (NewGVar->isDeclaration() && ClearConstant)
-        NewGVar->setConstant(false);
-    }
+  if (!LinkFromSrc)
     return DGV;
-  }
 
   // No linking to be performed or linking from the source: simply create an
   // identical version of the symbol over in the dest module... the





More information about the llvm-commits mailing list