[llvm] r321567 - IR: Fix BasicBlock::phis for empty blocks
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 29 11:25:53 PST 2017
Author: arsenm
Date: Fri Dec 29 11:25:53 2017
New Revision: 321567
URL: http://llvm.org/viewvc/llvm-project?rev=321567&view=rev
Log:
IR: Fix BasicBlock::phis for empty blocks
Modified:
llvm/trunk/lib/IR/BasicBlock.cpp
llvm/trunk/unittests/IR/BasicBlockTest.cpp
Modified: llvm/trunk/lib/IR/BasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/BasicBlock.cpp?rev=321567&r1=321566&r2=321567&view=diff
==============================================================================
--- llvm/trunk/lib/IR/BasicBlock.cpp (original)
+++ llvm/trunk/lib/IR/BasicBlock.cpp Fri Dec 29 11:25:53 2017
@@ -264,7 +264,8 @@ const BasicBlock *BasicBlock::getUniqueS
}
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
Modified: llvm/trunk/unittests/IR/BasicBlockTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/BasicBlockTest.cpp?rev=321567&r1=321566&r2=321567&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/BasicBlockTest.cpp (original)
+++ llvm/trunk/unittests/IR/BasicBlockTest.cpp Fri Dec 29 11:25:53 2017
@@ -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());
More information about the llvm-commits
mailing list