@@ -756,12 +756,12 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) {
756756 // Determine whether linkage of these two globals follows the source
757757 // module's definition or the destination module's definition.
758758 GlobalValue::LinkageTypes NewLinkage = GlobalValue::InternalLinkage;
759- HasUnnamedAddr = HasUnnamedAddr && DGV->hasUnnamedAddr ();
760759 GlobalValue::VisibilityTypes NV;
761760 bool LinkFromSrc = false ;
762761 if (getLinkageResult (DGV, SGV, NewLinkage, NV, LinkFromSrc))
763762 return true ;
764763 NewVisibility = NV;
764+ HasUnnamedAddr = HasUnnamedAddr && DGV->hasUnnamedAddr ();
765765
766766 // If we're not linking from the source, then keep the definition that we
767767 // have.
@@ -817,6 +817,7 @@ bool ModuleLinker::linkGlobalProto(GlobalVariable *SGV) {
817817bool ModuleLinker::linkFunctionProto (Function *SF) {
818818 GlobalValue *DGV = getLinkedToGlobal (SF);
819819 llvm::Optional<GlobalValue::VisibilityTypes> NewVisibility;
820+ bool HasUnnamedAddr = SF->hasUnnamedAddr ();
820821
821822 if (DGV) {
822823 GlobalValue::LinkageTypes NewLinkage = GlobalValue::InternalLinkage;
@@ -825,11 +826,13 @@ bool ModuleLinker::linkFunctionProto(Function *SF) {
825826 if (getLinkageResult (DGV, SF, NewLinkage, NV, LinkFromSrc))
826827 return true ;
827828 NewVisibility = NV;
829+ HasUnnamedAddr = HasUnnamedAddr && DGV->hasUnnamedAddr ();
828830
829831 if (!LinkFromSrc) {
830832 // Set calculated linkage
831833 DGV->setLinkage (NewLinkage);
832834 DGV->setVisibility (*NewVisibility);
835+ DGV->setUnnamedAddr (HasUnnamedAddr);
833836
834837 // Make sure to remember this mapping.
835838 ValueMap[SF] = ConstantExpr::getBitCast (DGV, TypeMap.get (SF->getType ()));
@@ -857,6 +860,7 @@ bool ModuleLinker::linkFunctionProto(Function *SF) {
857860 copyGVAttributes (NewDF, SF);
858861 if (NewVisibility)
859862 NewDF->setVisibility (*NewVisibility);
863+ NewDF->setUnnamedAddr (HasUnnamedAddr);
860864
861865 if (DGV) {
862866 // Any uses of DF need to change to NewDF, with cast.
0 commit comments