- // Otherwise, replace the visibility of DF if DF is a prototype.
- if (DF->isDeclaration())
- DF->setVisibility(SF->getVisibility());
- }
-
- if (DF->getType() != SF->getType()) {
- if (DF->isDeclaration() && !SF->isDeclaration()) {
- // We have a definition of the same name but different type in the
- // source module. Copy the prototype to the destination and replace
- // uses of the destination's prototype with the new prototype.
- Function *NewDF = Function::Create(SF->getFunctionType(),
- SF->getLinkage(),
- SF->getName(), Dest);
- CopyGVAttributes(NewDF, SF);
-
- // Any uses of DF need to change to NewDF, with cast
- DF->replaceAllUsesWith(ConstantExpr::getBitCast(NewDF, DF->getType()));
-
- // DF will conflict with NewDF because they both had the same. We must
- // erase this now so ForceRenaming doesn't assert because DF might
- // not have internal linkage.
- DF->eraseFromParent();
-
- // If the symbol table renamed the function, but it is an externally
- // visible symbol, DF must be an existing function with internal
- // linkage. Rename it.
- if (NewDF->getName() != SF->getName() && !NewDF->hasInternalLinkage())
- ForceRenaming(NewDF, SF->getName());
-
- // Remember this mapping so uses in the source module get remapped
- // later by RemapOperand.
- ValueMap[SF] = NewDF;
- } else if (SF->isDeclaration()) {
- // We have two functions of the same name but different type and the
- // source is a declaration while the destination is not. Any use of
- // the source must be mapped to the destination, with a cast.
- ValueMap[SF] = ConstantExpr::getBitCast(DF, SF->getType());
- } else {
- // We have two functions of the same name but different types and they
- // are both definitions. This is an error.
- return Error(Err, "Function '" + DF->getName() + "' defined as both '" +
- ToStr(SF->getFunctionType(), Src) + "' and '" +
- ToStr(DF->getFunctionType(), Dest) + "'");
- }
- continue;
- }
-
- if (SF->isDeclaration()) {
- // If SF is a declaration or if both SF & DF are declarations, just link
- // the declarations, we aren't adding anything.
- if (SF->hasDLLImportLinkage()) {
- if (DF->isDeclaration()) {
- ValueMap[SF] = DF;
- DF->setLinkage(SF->getLinkage());
- }
- } else {
- ValueMap[SF] = DF;
- }
- continue;
- }
-
- // If DF is external but SF is not, link the external functions, update
- // linkage qualifiers.
- if (DF->isDeclaration() && !DF->hasDLLImportLinkage()) {
- ValueMap.insert(std::make_pair(SF, DF));
- DF->setLinkage(SF->getLinkage());
+ // We have a definition of the same name but different type in the
+ // source module. Copy the prototype to the destination and replace
+ // uses of the destination's prototype with the new prototype.
+ Function *NewDF = Function::Create(SF->getFunctionType(), NewLinkage,
+ SF->getName(), Dest);
+ CopyGVAttributes(NewDF, SF);
+
+ // Any uses of DF need to change to NewDF, with cast
+ DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDF, DGV->getType()));
+
+ // DF will conflict with NewDF because they both had the same. We must
+ // erase this now so ForceRenaming doesn't assert because DF might
+ // not have internal linkage.
+ if (GlobalVariable *Var = dyn_cast<GlobalVariable>(DGV))
+ Var->eraseFromParent();
+ else
+ cast<Function>(DGV)->eraseFromParent();
+
+ // If the symbol table renamed the function, but it is an externally
+ // visible symbol, DF must be an existing function with internal
+ // linkage. Rename it.
+ if (NewDF->getName() != SF->getName() && !NewDF->hasLocalLinkage())
+ ForceRenaming(NewDF, SF->getName());
+
+ // Remember this mapping so uses in the source module get remapped
+ // later by RemapOperand.
+ ValueMap[SF] = NewDF;