From: Rafael Espindola Date: Fri, 5 Dec 2014 16:05:19 +0000 (+0000) Subject: Small cleanup on how we clear constant variables. NFC. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=dd6794f01dac8a80b2d630eff9e39a081d3515b3;p=oota-llvm.git Small cleanup on how we clear constant variables. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223474 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 561b02136b8..4aa0b88df5b 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -1045,6 +1045,14 @@ bool ModuleLinker::linkGlobalValueProto(GlobalValue *SGV) { NewGO->setAlignment(std::max(DGV->getAlignment(), SGV->getAlignment())); } + if (auto *NewGVar = dyn_cast(NewGV)) { + auto *DGVar = dyn_cast_or_null(DGV); + auto *SGVar = dyn_cast(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 *SGV) { GlobalValue *ModuleLinker::linkGlobalVariableProto(const GlobalVariable *SGVar, GlobalValue *DGV, bool LinkFromSrc) { - bool ClearConstant = false; - - if (DGV) { - auto *DGVar = dyn_cast(DGV); - if (!SGVar->isConstant() || (DGVar && !DGVar->isConstant())) - ClearConstant = true; - } - - if (!LinkFromSrc) { - if (auto *NewGVar = dyn_cast(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