diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp --- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -1748,24 +1748,26 @@ End->eraseFromParent(); } - switch (Shape.ABI) { - case coro::ABI::Switch: - // Each clone in the Switch lowering is independent of the other clones. Let - // the LazyCallGraph know about each one separately. - for (Function *Clone : Clones) - CG.addSplitFunction(N.getFunction(), *Clone); - break; - case coro::ABI::Async: - case coro::ABI::Retcon: - case coro::ABI::RetconOnce: - // Each clone in the Async/Retcon lowering references of the other clones. - // Let the LazyCallGraph know about all of them at once. - CG.addSplitRefRecursiveFunctions(N.getFunction(), Clones); - break; - } + if (!Clones.empty()) { + switch (Shape.ABI) { + case coro::ABI::Switch: + // Each clone in the Switch lowering is independent of the other clones. + // Let the LazyCallGraph know about each one separately. + for (Function *Clone : Clones) + CG.addSplitFunction(N.getFunction(), *Clone); + break; + case coro::ABI::Async: + case coro::ABI::Retcon: + case coro::ABI::RetconOnce: + // Each clone in the Async/Retcon lowering references of the other clones. + // Let the LazyCallGraph know about all of them at once. + CG.addSplitRefRecursiveFunctions(N.getFunction(), Clones); + break; + } - // Let the CGSCC infra handle the changes to the original function. - updateCGAndAnalysisManagerForCGSCCPass(CG, C, N, AM, UR, FAM); + // Let the CGSCC infra handle the changes to the original function. + updateCGAndAnalysisManagerForCGSCCPass(CG, C, N, AM, UR, FAM); + } // Do some cleanup and let the CGSCC infra see if we've cleaned up any edges // to the split functions. diff --git a/llvm/test/Transforms/Coroutines/coro-retcon-unreachable.ll b/llvm/test/Transforms/Coroutines/coro-retcon-unreachable.ll --- a/llvm/test/Transforms/Coroutines/coro-retcon-unreachable.ll +++ b/llvm/test/Transforms/Coroutines/coro-retcon-unreachable.ll @@ -1,4 +1,5 @@ ; RUN: opt < %s -coro-early -coro-split -S | FileCheck %s +; RUN: opt < %s -passes='function(coro-early),cgscc(coro-split)' -S | FileCheck %s target datalayout = "E-p:64:64" %swift.type = type { i64 }