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