diff --git a/lib/Transforms/IPO/PartialInlining.cpp b/lib/Transforms/IPO/PartialInlining.cpp index 5550376279f..739b0dae314 100644 --- a/lib/Transforms/IPO/PartialInlining.cpp +++ b/lib/Transforms/IPO/PartialInlining.cpp @@ -715,9 +715,15 @@ Function *PartialInlinerImpl::unswitchFunction(Function *F) { // users (function pointers, etc.) back to the original function. DuplicateFunction->replaceAllUsesWith(F); DuplicateFunction->eraseFromParent(); - if (!AnyInline && OutlinedFunction) + + if (AnyInline) + return OutlinedFunction; + + // Remove the function that is speculatively created: + if (OutlinedFunction) OutlinedFunction->eraseFromParent(); - return OutlinedFunction; + + return nullptr; } bool PartialInlinerImpl::tryPartialInline(Function *DuplicateFunction,