diff --git a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp --- a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp +++ b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp @@ -129,6 +129,13 @@ /// Check whether it's safe to outline \p BB. static bool mayExtractBlock(const BasicBlock &BB) { + // Don't extract the indirect destination of a "callbr" instruction as even + // though it's ice cold it's not safe to extract it, for reasons similar to + // extracting an EH block. + for (const auto *pred : predecessors(&BB)) + if (isa(pred->getTerminator())) + return false; + // EH pads are unsafe to outline because doing so breaks EH type tables. It // follows that invoke instructions cannot be extracted, because CodeExtractor // requires unwind destinations to be within the extraction region. @@ -137,7 +144,7 @@ // be unreachable. It’s not safe to split them out either. auto Term = BB.getTerminator(); return !BB.hasAddressTaken() && !BB.isEHPad() && !isa(Term) && - !isa(Term); + !isa(Term) && !isa(Term); } /// Mark \p F cold. Based on this assumption, also optimize it for minimum size.