Index: llvm/lib/Transforms/IPO/FunctionSpecialization.cpp =================================================================== --- llvm/lib/Transforms/IPO/FunctionSpecialization.cpp +++ llvm/lib/Transforms/IPO/FunctionSpecialization.cpp @@ -216,6 +216,10 @@ ValueToValueMapTy EmptyMap; Function *Clone = CloneFunction(F, EmptyMap); Argument *ClonedArg = Clone->arg_begin() + A.getArgNo(); + // Functions with AvailableExternallyLinkage would be deleted + // in the end. + if (Clone->hasAvailableExternallyLinkage()) + Clone->setLinkage(GlobalValue::InternalLinkage); // Rewrite calls to the function so that they call the clone instead. rewriteCallSites(F, Clone, *ClonedArg, C); @@ -463,7 +467,8 @@ // Determine if we can track the function's arguments. If so, add the // function to the solver's set of argument-tracked functions. - if (canTrackArgumentsInterprocedurally(&F)) { + if (canTrackArgumentsInterprocedurally(&F) || + F.hasAvailableExternallyLinkage()) { LLVM_DEBUG(dbgs() << "FnSpecialization: Can track arguments\n"); Solver.addArgumentTrackedFunction(&F); continue;