1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

IR: Fix BasicBlock::phis for empty blocks

llvm-svn: 321567
This commit is contained in:
Matt Arsenault 2017-12-29 19:25:53 +00:00
parent d8a579c383
commit 93f1de7111
2 changed files with 8 additions and 1 deletions

View File

@ -264,7 +264,8 @@ const BasicBlock *BasicBlock::getUniqueSuccessor() const {
}
iterator_range<BasicBlock::phi_iterator> BasicBlock::phis() {
return make_range<phi_iterator>(dyn_cast<PHINode>(&front()), nullptr);
PHINode *P = empty() ? nullptr : dyn_cast<PHINode>(&*begin());
return make_range<phi_iterator>(P, nullptr);
}
/// This method is used to notify a BasicBlock that the

View File

@ -33,6 +33,12 @@ TEST(BasicBlockTest, PhiRange) {
std::unique_ptr<BasicBlock> BB2(BasicBlock::Create(Context));
BranchInst::Create(BB.get(), BB2.get());
// Make sure this doesn't crash if there are no phis.
for (auto &PN : BB->phis()) {
(void)PN;
EXPECT_TRUE(false) << "empty block should have no phis";
}
// Make it a cycle.
auto *BI = BranchInst::Create(BB.get(), BB.get());