diff options
author | Florian Hahn <flo@fhahn.com> | 2019-10-02 19:38:24 +0000 |
---|---|---|
committer | Florian Hahn <flo@fhahn.com> | 2019-10-02 19:38:24 +0000 |
commit | a80b6c15425f82521c624ff24c5c0a34cd534d54 (patch) | |
tree | 5f75a320b55c57aa95d69c6f652f76a3579cf2f8 /llvm/lib/Transforms | |
parent | c78c0e08be2192b3bc33f449f26480a58e89032b (diff) | |
download | bcm5719-llvm-a80b6c15425f82521c624ff24c5c0a34cd534d54.tar.gz bcm5719-llvm-a80b6c15425f82521c624ff24c5c0a34cd534d54.zip |
[Local] Handle terminators with users in removeUnreachableBlocks.
Terminators like invoke can have users outside the current basic block.
We have to replace those users with undef, before replacing the
terminator.
This fixes a crash exposed by rL373430.
Reviewers: brzycki, asbirlea, davide, spatel
Reviewed By: asbirlea
Differential Revision: https://reviews.llvm.org/D68327
llvm-svn: 373513
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 3a6b7a6a655..94339c2ba00 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -2246,9 +2246,13 @@ bool llvm::removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU, } BB->dropAllReferences(); if (DTU) { - // Remove the terminator of BB to clear the successor list of BB. - if (BB->getTerminator()) - BB->getInstList().pop_back(); + Instruction *TI = BB->getTerminator(); + assert(TI && "Basic block should have a terminator"); + // Terminators like invoke can have users. We have to replace their users, + // before removing them. + if (!TI->use_empty()) + TI->replaceAllUsesWith(UndefValue::get(TI->getType())); + TI->eraseFromParent(); new UnreachableInst(BB->getContext(), BB); assert(succ_empty(BB) && "The successor list of BB isn't empty before " "applying corresponding DTU updates."); |