- } else if (GlobalAlias *DGA = dyn_cast<GlobalAlias>(DGV)) {
- // SF is function, but DF is alias.
- // The only valid mappings are:
- // - SF is external declaration, which is effectively a no-op.
- // - SF is weak, when we just need to throw SF out.
- if (!SF->isDeclaration() && !SF->isWeakForLinker())
- return Error(Err, "Function-Alias Collision on '" + SF->getName() +
- "': symbol multiple defined");
-
- // Make sure to remember this mapping...
- ValueMap[SF] = ConstantExpr::getBitCast(DGA, SF->getType());
- continue;
- }
-
- Function* DF = cast<Function>(DGV);
- // If types don't agree because of opaque, try to resolve them.
- if (SF->getType() != DF->getType())
- RecursiveResolveTypes(SF->getType(), DF->getType());
-
- // Check visibility, merging if a definition overrides a prototype.
- if (SF->getVisibility() != DF->getVisibility()) {
- // If one is a prototype, ignore its visibility. Prototypes are always
- // overridden by the definition.
- if (!SF->isDeclaration() && !DF->isDeclaration())
- return Error(Err, "Linking functions named '" + SF->getName() +
- "': symbols have different visibilities!");
-
- // 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;
- continue;
- } else {
- // We have two functions of the same name but different type. Any use
- // of the source must be mapped to the destination, with a cast.
- MappedDF = ConstantExpr::getBitCast(DF, SF->getType());
- }
- } else {
- MappedDF = DF;